// NOTE: An overload of this method with a similar signature exists! wxPoint MapTerrainT::TraceRay(const Vector3fT& Source, const Vector3fT& Direction) const { VB_Trace3T<double> TraceResult(1.0); m_Terrain.TraceBoundingBox(BoundingBox3T<double>(Vector3dT(), Vector3dT()), Source.AsVectorOfDouble(), Direction.AsVectorOfDouble(), TraceResult); if (TraceResult.Fraction==1.0) return wxPoint(-1, -1); Vector3fT HitPos(Source+Direction*TraceResult.Fraction); float TerrainXLength=m_TerrainBounds.Max.x-m_TerrainBounds.Min.x; float TerrainYLength=m_TerrainBounds.Max.y-m_TerrainBounds.Min.y; Vector3fT HitPosRelative(HitPos.x-m_TerrainBounds.Min.x, HitPos.y-m_TerrainBounds.Min.y, 0.0f); wxPoint HeightDataPos(Round(HitPosRelative.x/float(TerrainXLength)*float(m_Resolution-1)), Round(HitPosRelative.y/float(TerrainYLength)*float(m_Resolution-1))); // Flip tools y position. HeightDataPos.y=m_Resolution-1-HeightDataPos.y; // If height data position lies outside height data boundaries return undefined position. if (HeightDataPos.x<0 || HeightDataPos.y<0 || (unsigned long)HeightDataPos.x>m_Resolution-1 || (unsigned long)HeightDataPos.y>m_Resolution-1) return wxPoint(-1, -1); return HeightDataPos; }
// NOTE: An overload of this method with a similar signature exists! bool MapTerrainT::TraceRay(const Vector3fT& RayOrigin, const Vector3fT& RayDir, float& Fraction, unsigned long& FaceNr) const { // If possible (RayOrigin is not in cull bounding-box), do a quick bounding-box check first. if (!GetBB().Contains(RayOrigin) && !MapPrimitiveT::TraceRay(RayOrigin, RayDir, Fraction, FaceNr)) return false; const double RayLength=1000000.0; VB_Trace3T<double> Trace(1.0); m_Terrain.TraceBoundingBox(BoundingBox3dT(Vector3dT()), RayOrigin.AsVectorOfDouble(), RayDir.AsVectorOfDouble()*RayLength, Trace); if (Trace.Fraction==1.0) return false; Fraction=Trace.Fraction*RayLength; return true; }
EntFuncLadderT::EntFuncLadderT(const EntityCreateParamsT& Params) : BaseEntityT(Params, EntityStateT(VectorT(), // Origin VectorT(), // Velocity BoundingBox3T<double>(Vector3dT()), 0, // Heading 0, // Pitch 0, // Bank 0, 0, 0, // ModelIndex 0, // ModelSequNr 0.0, // ModelFrameNr 0, // Health 0, // Armor 0, // HaveItems 0, // HaveWeapons 0, // ActiveWeaponSlot 0, // ActiveWeaponSequNr 0.0)) // ActiveWeaponFrameNr // RootNode(Params.RootNode) { assert(CollisionModel!=NULL); // A ladder entity without collision model is useless. // Registering the clip model with the clip world is very important, so that we cannot run "into" ladder brushes. // !!! Note that ladder brushes are currently always at the origin (0, 0, 0). // !!! That is the only reason why we don't need to call e.g. ClipModel.SetOrigin() // !!! AND don't need to provide the Cl_UnserializeFrom() method! ClipModel.Register(); // Corresponding to this entities CollisionModelT, use the related btCollisionShape // for adding a btRigidBody (which "is a" btCollisionObject) to the PhysicsWorld. btCollisionShape* LadderShape=CollisionModel->GetBulletAdapter(); m_RigidBody=new btRigidBody(btRigidBody::btRigidBodyConstructionInfo(0, NULL /*MotionState*/, LadderShape, btVector3(0, 0, 0))); m_RigidBody->setUserPointer(this); // This entity is associated to the m_RigidBody. PhysicsWorld->AddRigidBody(m_RigidBody); }
inline Vector3dT convd(const btVector3& v) { return Vector3dT(v.x(), v.y(), v.z()); }