Open Source Tomb Raider Engine
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Entity.cpp 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*!
  2. * \file src/Entity.cpp
  3. * \brief World Entities
  4. *
  5. * \author xythobuz
  6. */
  7. #ifdef __APPLE__
  8. #include <OpenGL/gl.h>
  9. #include <OpenGL/glu.h>
  10. #elif defined WIN32
  11. #include <gl/glew.h>
  12. #include <gl/wglew.h>
  13. #else
  14. #include <GL/gl.h>
  15. #include <GL/glu.h>
  16. #endif
  17. #include "Entity.h"
  18. #include "main.h"
  19. Entity::Entity(TombRaider &tr, unsigned int index, unsigned int i, unsigned int model) {
  20. tr2_moveable_t *moveable = tr.Moveable();
  21. tr2_item_t *item = tr.Item();
  22. vec_t yaw = ((item[i].angle >> 14) & 0x03);
  23. yaw *= 90;
  24. pos[0] = item[i].x;
  25. pos[1] = item[i].y;
  26. pos[2] = item[i].z;
  27. angles[0] = 0;
  28. angles[1] = yaw;
  29. angles[2] = 0;
  30. objectId = moveable[index].object_id;
  31. moveType = MoveTypeWalk;
  32. room = getWorld().getRoomByLocation(pos[0], pos[1], pos[2]);
  33. skeletalModel = model;
  34. boneFrame = 0;
  35. animationFrame = 0;
  36. idleAnimation = 0;
  37. state = 0;
  38. if (tr.Engine() == TR_VERSION_1) {
  39. switch (objectId) {
  40. case TombRaider1::Wolf:
  41. state = TombRaider1::WolfState_Lying;
  42. animationFrame = 3;
  43. break;
  44. }
  45. }
  46. // Gather more info if this is lara
  47. if (objectId == 0) {
  48. animationFrame = TR_ANIAMTION_RUN;
  49. idleAnimation = TR_ANIAMTION_STAND;
  50. }
  51. }
  52. bool Entity::operator<(Entity &o) {
  53. vec_t distA = getRender().mViewVolume.getDistToSphereFromNear(pos[0], pos[1], pos[2], 1.0f);
  54. vec_t distB = getRender().mViewVolume.getDistToSphereFromNear(o.pos[0], o.pos[1], o.pos[2], 1.0f);
  55. return (distA < distB);
  56. }
  57. void Entity::display() {
  58. /*
  59. glPushMatrix();
  60. glTranslatef(pos[0], pos[1], pos[2]);
  61. glRotatef(angles[1], 0, 1, 0);
  62. getWorld().getSkeletalModel(skeletalModel).display();
  63. glPopMatrix();
  64. */
  65. }
  66. void Entity::setSkeletalModel(unsigned int model) {
  67. skeletalModel = model;
  68. animationFrame = 0;
  69. boneFrame = 0;
  70. idleAnimation = 0;
  71. }
  72. unsigned int Entity::getAnimationFrame() {
  73. return animationFrame;
  74. }
  75. void Entity::setAnimationFrame(unsigned int index) {
  76. animationFrame = index;
  77. boneFrame = 0;
  78. }
  79. unsigned int Entity::getBoneFrame() {
  80. return boneFrame;
  81. }
  82. void Entity::setBoneFrame(unsigned int index) {
  83. boneFrame = index;
  84. }
  85. unsigned int Entity::getIdleAnimation() {
  86. return idleAnimation;
  87. }
  88. void Entity::setIdleAnimation(unsigned int index) {
  89. idleAnimation = index;
  90. }