void OrientedBox3F::set( const MatrixF& transform, const Box3F& aabb ) { mCenter = aabb.getCenter(); transform.mulP( mCenter ); mAxes[ RightVector ] = transform.getRightVector(); mAxes[ ForwardVector ] = transform.getForwardVector(); mAxes[ UpVector ] = transform.getUpVector(); mHalfExtents[ 0 ] = aabb.len_x() / 2.f; mHalfExtents[ 1 ] = aabb.len_y() / 2.f; mHalfExtents[ 2 ] = aabb.len_z() / 2.f; _initPoints(); }
//---------------------------------------------------------------------------- void RigidBody::createPhysShape() { //Physics* physics = isServerObject() ? gServerPhysics : gClientPhysics; Physics* physics = Physics::getPhysics(isServerObject()); if (physics) { PhysInfo physDescr; //transform into radian VectorF angleRadians = mDataBlock->mRotation/180.f*float(M_PI); physDescr.transform.set(angleRadians, mDataBlock->mPos); physDescr.owner = this; physDescr.shapeType = (PhysInfo::ShapeType)mDataBlock->mShapeType; physDescr.mass = mDataBlock->mass; if (physDescr.shapeType==PhysInfo::ST_SPHERE) { Box3F scaledObjBox = mObjBox; scaledObjBox.minExtents.convolve(mObjScale); scaledObjBox.maxExtents.convolve(mObjScale); F32 radius = (scaledObjBox.maxExtents - scaledObjBox.getCenter()).len(); physDescr.params = VectorF(radius,0.f,0.f); } else //if (physDescr.shapeType==PhysInfo::ST_BOX) { Box3F rotBox = mObjBox; physDescr.transform.mul(rotBox); VectorF length = VectorF(rotBox.len_x(),rotBox.len_y(),rotBox.len_z()); length.convolve(mObjScale); physDescr.params = length; } //physDescr.params = VectorF(1.f,1.f,1.f); //physDescr.shapeType = PhysInfo::ST_SPHERE; //physDescr.mass = 5.f; //physDescr.params = VectorF(0.5f,0.f,0.f); mPhysShape = physics->createPhysShape(physDescr); mPhysShape->setTransform(mObjToWorld); mPhysShape->setForce(mForce); mPhysShape->setTorque(mTorque); mPhysShape->setLinVelocity(mLinVelocity); mPhysShape->setAngVelocity(mAngVelocity); } }
bool AITurretShape::_testTargetLineOfSight(Point3F& aimPoint, ShapeBase* target, Point3F& sightPoint) { Point3F targetCenter = target->getBoxCenter(); RayInfo ri; bool hit = false; target->disableCollision(); // First check for a clear line of sight to the target's center Point3F testPoint = targetCenter; hit = gServerContainer.castRay(aimPoint, testPoint, sAimTypeMask, &ri); if (hit) { // No clear line of sight to center, so try to the target's right. Players holding // a gun in their right hand will tend to stick their right shoulder out first if // they're peering around some cover to shoot, like a wall. Box3F targetBounds = target->getObjBox(); F32 radius = targetBounds.len_x() > targetBounds.len_y() ? targetBounds.len_x() : targetBounds.len_y(); radius *= 0.5; VectorF toTurret = aimPoint - targetCenter; toTurret.normalizeSafe(); VectorF toTurretRight = mCross(toTurret, Point3F::UnitZ); testPoint = targetCenter + toTurretRight * radius; hit = gServerContainer.castRay(aimPoint, testPoint, sAimTypeMask, &ri); if (hit) { // No clear line of sight to right, so try the target's left VectorF toTurretLeft = toTurretRight * -1.0f; testPoint = targetCenter + toTurretLeft * radius; hit = gServerContainer.castRay(aimPoint, testPoint, sAimTypeMask, &ri); } if (hit) { // No clear line of sight to left, so try the target's top testPoint = targetCenter; testPoint.z += targetBounds.len_z() * 0.5f; hit = gServerContainer.castRay(aimPoint, testPoint, sAimTypeMask, &ri); } if (hit) { // No clear line of sight to top, so try the target's bottom testPoint = targetCenter; testPoint.z -= targetBounds.len_z() * 0.5f; hit = gServerContainer.castRay(aimPoint, testPoint, sAimTypeMask, &ri); } } target->enableCollision(); if (!hit) { // Line of sight point is that last one we tested sightPoint = testPoint; } return !hit; }
void Polytope::buildBox(const MatrixF& transform,const Box3F& box) { // Box is assumed to be axis aligned in the source space. // Transform into geometry space Point3F xvec,yvec,zvec,min; transform.getColumn(0,&xvec); xvec *= box.len_x(); transform.getColumn(1,&yvec); yvec *= box.len_y(); transform.getColumn(2,&zvec); zvec *= box.len_z(); transform.mulP(box.minExtents,&min); // Initial vertices mVertexList.setSize(8); mVertexList[0].point = min; mVertexList[1].point = min + yvec; mVertexList[2].point = min + xvec + yvec; mVertexList[3].point = min + xvec; mVertexList[4].point = mVertexList[0].point + zvec; mVertexList[5].point = mVertexList[1].point + zvec; mVertexList[6].point = mVertexList[2].point + zvec; mVertexList[7].point = mVertexList[3].point + zvec; S32 i; for (i = 0; i < 8; i++) mVertexList[i].side = 0; // Initial faces mFaceList.setSize(6); for (S32 f = 0; f < 6; f++) { Face& face = mFaceList[f]; face.original = true; face.vertex = 0; } mFaceList[0].plane.set(mVertexList[0].point,xvec); mFaceList[0].plane.invert(); mFaceList[1].plane.set(mVertexList[2].point,yvec); mFaceList[2].plane.set(mVertexList[2].point,xvec); mFaceList[3].plane.set(mVertexList[0].point,yvec); mFaceList[3].plane.invert(); mFaceList[4].plane.set(mVertexList[0].point,zvec); mFaceList[4].plane.invert(); mFaceList[5].plane.set(mVertexList[4].point,zvec); // Initial edges mEdgeList.setSize(12); Edge* edge = mEdgeList.begin(); S32 nextEdge = 0; for (i = 0; i < 4; i++) { S32 n = (i == 3)? 0: i + 1; S32 p = (i == 0)? 3: i - 1; edge->vertex[0] = i; edge->vertex[1] = n; edge->face[0] = i; edge->face[1] = 4; edge->next = ++nextEdge; edge++; edge->vertex[0] = 4 + i; edge->vertex[1] = 4 + n; edge->face[0] = i; edge->face[1] = 5; edge->next = ++nextEdge; edge++; edge->vertex[0] = i; edge->vertex[1] = 4 + i; edge->face[0] = i; edge->face[1] = p; edge->next = ++nextEdge; edge++; } edge[-1].next = -1; // Volume mVolumeList.setSize(1); Volume& volume = mVolumeList.last(); volume.edgeList = 0; volume.material = -1; volume.object = 0; sideCount = 0; }
void PolyBSPClip::box(const TMat3F transform,const Box3F& box) { sideCount = 0; // Box is assumed to be axis aligned in the source space. // Transform into geometry space Point3F xvec,yvec,zvec,min; transform.getRow(0,&xvec); xvec *= box.len_x(); transform.getRow(1,&yvec); yvec *= box.len_y(); transform.getRow(2,&zvec); zvec *= box.len_z(); m_mul(box.fMin,transform,&min); // Initial vertices vertexList.setSize(8); vertexList[0].point = min; vertexList[1].point = min + yvec; vertexList[2].point = min + xvec + yvec; vertexList[3].point = min + xvec; vertexList[4].point = vertexList[0].point + zvec; vertexList[5].point = vertexList[1].point + zvec; vertexList[6].point = vertexList[2].point + zvec; vertexList[7].point = vertexList[3].point + zvec; int i; for (i = 0; i < 8; i++) { vertexList[i].side = 0; vertexList[i].step = false; } // Initial faces faceList.setSize(6); for (int f = 0; f < 6; f++) { Face& face = faceList[f]; face.vertex = 0; face.plane = 0; face.planeId = -1; } // Initial edges stack[0].setSize(12); Edge* edge = stack[0].begin(); for (i = 0; i < 4; i++) { int n = (i == 3)? 0: i + 1; int p = (i == 0)? 3: i - 1; edge->vertex[0] = i; edge->vertex[1] = n; edge->face[0] = i; edge->face[1] = 4; edge++; edge->vertex[0] = 4 + i; edge->vertex[1] = 4 + n; edge->face[0] = i; edge->face[1] = 5; edge++; edge->vertex[0] = i; edge->vertex[1] = 4 + i; edge->face[0] = i; edge->face[1] = p; edge++; } // Starting stack stack[1].setSize(0); stack[2].setSize(0); Stack poly; poly.edge = &stack[0]; poly.start = 0; poly.end = stack[0].size(); split(rootNode,poly); }