00001 /* 00002 SagaEngine library 00003 Copyright (c) 2002-2006 Skalden Studio AS 00004 00005 This software is provided 'as-is', without any express or implied 00006 warranty. In no event will the authors be held liable for any 00007 damages arising from the use of this software. 00008 00009 Permission is granted to distribute the library under the terms of the 00010 Q Public License version 1.0. Be sure to read and understand the license 00011 before using the library. It should be included here, or you may read it 00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl 00013 00014 The original version of this library can be located at: 00015 http://www.sagaengine.com/ 00016 00017 Rune Myrland 00018 rune@skalden.com 00019 */ 00020 00021 00022 #ifndef Pos_hpp 00023 #define Pos_hpp 00024 00025 #include "Anim.hpp" 00026 #include "util/vecmath/ViewPoint.hpp" 00027 #include "util/bounds/BoundingBox.hpp" 00028 #include "sim_pos.hpp" 00029 #include "../sim.hpp" 00030 #include "comp/comp.hpp" 00031 #include "../area/sim_area.hpp" 00032 #include "../config/sim_config.hpp" 00033 00034 00035 namespace se_core { 00041 class _SeCoreExport Pos { 00042 public: 00043 static const short TS_VOID = 0; 00044 static const long TSM_VOID = (1 << TS_VOID); 00045 00049 enum Direction { 00050 EAST = 0, SOUTH_EAST = 32, 00051 SOUTH = 64, SOUTH_WEST = 96, 00052 WEST = 128, NORTH_WEST = 160, 00053 NORTH = 192, NORTH_EAST = 224 00054 }; 00055 00059 Pos(); 00060 00064 void setPos(const Pos& original); 00065 00071 void setXZ(const Pos& original); 00072 00077 inline void setLocalCoor(Point3& original) { 00078 localCoor().set(original); 00079 } 00080 00085 inline const Point3& worldCoor() const { return world_.coor_; } 00086 00091 inline Point3& worldCoor() { return world_.coor_; } 00092 inline const ViewPoint& worldViewPoint() const { return world_; } 00093 inline ViewPoint& worldViewPoint() { return world_; } 00094 00095 #ifdef SE_QUAT 00096 const Quat4& worldFace() const { return world_.face_; } 00097 Quat4& worldFace() { return world_.face_; } 00098 #else 00099 const Euler3& worldFace() const { return world_.face_; } 00100 Euler3& worldFace() { return world_.face_; } 00101 #endif 00102 00103 00104 inline const Point3& localCoor() const { return local_.coor_; } 00105 inline Point3& localCoor() { return local_.coor_; } 00106 inline const ViewPoint& localViewPoint() const { return local_; } 00107 inline ViewPoint& localViewPoint() { return local_; } 00108 00109 #ifdef SE_QUAT 00110 const Quat4& localFace() const { return local_.face_; } 00111 Quat4& localFace() { return local_.face_; } 00112 #else 00113 const Euler3& localFace() const { return local_.face_; } 00114 Euler3& localFace() { return local_.face_; } 00115 #endif 00116 00117 00118 inline bool localEquals(const ViewPoint& vp) const { 00119 return local_.viewPointEquals(vp); 00120 } 00121 00122 inline bool localEquals(const Pos& p) const { 00123 return local_.viewPointEquals(p.local_); 00124 } 00125 00126 inline bool worldEquals(const ViewPoint& vp) const { 00127 return world_.viewPointEquals(vp); 00128 } 00129 00130 inline bool worldEquals(const Pos& p) const { 00131 return world_.viewPointEquals(p.world_); 00132 } 00133 00134 00141 void setArea(PosComponent& area, bool doKeepWorldCoor = false); 00142 00149 void setArea(PosComponent& area, const ViewPoint& vp, bool isLocalViewPoint = true); 00150 00154 void resetArea(); 00155 00162 void setParent(PosComponent& p, bool doKeepWorldCoor = false); 00163 00169 void resetParent(bool doKeepWorldCoor = true); 00170 00174 bool hasParent() const { return parent_ != 0; } 00175 00182 bool didParentMove() const; 00183 00187 PosComponent* parent() { return parent_; } 00192 const PosComponent* parent() const { return parent_; } 00193 00199 void updateWorldViewPoint(); 00200 void areaCoor(const PosComponent& area, Point3& dest) const; 00201 void areaFace(const PosComponent& area, Euler3& dest) const; 00202 void areaViewPoint(const PosComponent& area, ViewPoint& dest) const; 00203 00208 void updateLocalViewPoint(); 00209 00213 PosComponent* area() { return area_; } 00214 00219 const PosComponent* area() const { return area_; } 00220 00221 00225 bool hasArea() const { return area_ != 0; } 00226 00227 bool hasArea(Composite& area) const; 00228 bool hasArea(Component& area) const; 00229 bool hasArea(PosComponent& area) const { return area_ != 0 && area_ == &area; } 00230 00236 short terrainStyle() const; 00237 00243 long touchedTerrain() const; 00244 00251 bool isKeyFramePath(const Pos& other) const; 00252 00253 00260 short clockwiseFaceDirection(short subdivisions) const; 00261 00262 00271 bool hasInFront(const Point3& coor) const; 00272 00273 00282 bray_t xzFaceAwayAngle(const Point3& towards) const; 00283 00284 00288 inline coor_t radius() const { return bounds_.radius(); } 00289 00290 00296 inline void setRadius(coor_t radius) { 00297 bounds_.setMin(-radius, 0, -radius); 00298 bounds_.setMax(radius, 2 * radius, radius); 00299 } 00300 00301 inline void setBounds(coor_t radius) { 00302 bounds_.setMin(-radius, 0, -radius); 00303 bounds_.setMax(radius, 2 * radius, radius); 00304 } 00305 00306 inline void setBounds(coor_t radius, coor_t height) { 00307 bounds_.setMin(-radius, 0, -radius); 00308 bounds_.setMax(radius, height, radius); 00309 } 00310 00311 inline void setBounds(const BoundingBox& b) { 00312 bounds_ = b; 00313 } 00314 00315 inline bool hasInside(const Point3& p) const { 00316 return bounds_.hasInside(worldCoor(), p); 00317 } 00318 00327 bool isInsideCollisionRange(const Pos& p) const; 00328 00329 00337 bool isInsideCollisionRangeLinf(const Pos& p) const; 00338 00339 00344 inline bool isGrounded() const { return isGrounded_; } 00345 00351 inline void setGrounded(bool state) { 00352 isGrounded_ = state; 00353 if(isGrounded_) 00354 updateY(); 00355 } 00356 00362 inline void setIndex(short i) { index_ = i; } 00363 00370 inline short index() const { return index_; } 00371 00375 inline bool hasIndex() const { return index_ >= 0; } 00376 00380 inline void setNoIndex() { index_ = -1; } 00381 00382 PosComponent* updateArea(); 00383 void updateIndex(); 00384 00388 inline Anim& anim(int index) { 00389 return anim_[index]; 00390 } 00391 00392 00397 inline const Anim& anim(int index) const { 00398 return anim_[index]; 00399 } 00400 00404 void swapAnims(int a, int b); 00405 00406 00415 void updateY(); 00416 00417 // Deprecated as the result of world_ 00418 //coor_world_t pageDistanceSquared(const Pos& p) const; 00419 00420 void reset() { 00421 area_ = 0; 00422 parent_ = 0; 00423 local_.setIdentity(); 00424 world_.setIdentity(); 00425 bounds_.reset(); 00426 index_ = -1; 00427 isGrounded_ = false; 00428 anim_[0].setMovementMode(0, 0); 00429 } 00430 00431 00432 public: 00434 PosComponent* area_; 00435 00437 PosComponent* parent_; 00438 00440 ViewPoint local_; 00441 00443 ViewPoint world_; 00444 00446 enum { MAX_ANIMS = 4 }; 00447 Anim anim_[MAX_ANIMS]; 00448 00450 //coor_t radius_; 00452 BoundingBox bounds_; 00453 00455 short index_; 00456 00457 bool isGrounded_; 00458 }; 00459 00460 } 00461 00462 #endif
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:11 2007 by Doxygen version 1.3.9.1.