NiPoint3 NiPoint3::operator- () const { return NiPoint3(-x, -y, -z); }
//------------------------------------------------------------------------------------------------- bool sdPhysicsSystem::CreateTerrain(sdTerrain* pkTerrain) { NIASSERT(pkTerrain); NIASSERT(m_pkHeightField == NULL) sdHeightMap* pkHeightMap = pkTerrain->GetHeightMap(); NIASSERT(pkHeightMap); uint uiBlockSize = pkHeightMap->GetSize() + 1; ///< 每边顶点数(??为什么加一??) uint uiNumVert = uiBlockSize * uiBlockSize; ///< 总顶点数 float fMinHeight = pkHeightMap->GetMinHeight(); float fMaxHeight = pkHeightMap->GetMaxHeight(); float fMidHeight = (fMaxHeight + fMinHeight) * 0.5f; float fHalfDeltaHeight = (fMaxHeight - fMinHeight) * 0.5f; float fThirtyTwoKb = 32766.f; fHalfDeltaHeight = fabs(fHalfDeltaHeight) < 0.0001f ? 0.0001f : fHalfDeltaHeight; ///< 防止值过小 NxHeightFieldSample* pnxHeightFieldSample = NiAlloc2(NxHeightFieldSample, uiNumVert, NiMemHint::NONE); NIASSERT(pnxHeightFieldSample); // 创建高度域描述 NxHeightFieldDesc nxHeightFieldDesc; nxHeightFieldDesc.nbColumns = uiBlockSize; nxHeightFieldDesc.nbRows = uiBlockSize; nxHeightFieldDesc.convexEdgeThreshold = 0.f; nxHeightFieldDesc.thickness = -1000.f; nxHeightFieldDesc.samples = pnxHeightFieldSample; nxHeightFieldDesc.sampleStride = sizeof(NxU32); uchar* pucData = (uchar*)pnxHeightFieldSample; for (int i = 0; i < (int)uiBlockSize; ++i) { for (int j = 0; j < (int)uiBlockSize; ++j) { float fHeight = pkHeightMap->GetRawHeight(i, j); NxI16 nxHeight = (NxI16)(fThirtyTwoKb * ((fHeight - fMinHeight) / fHalfDeltaHeight)); NxHeightFieldSample* pkHeightFieldSample = (NxHeightFieldSample*)(pucData); pkHeightFieldSample->height = nxHeight; pkHeightFieldSample->materialIndex0 = 1; pkHeightFieldSample->materialIndex1 = 1; pkHeightFieldSample->tessFlag = 1; pucData += nxHeightFieldDesc.sampleStride; } } // 创建高度域 m_pkHeightField = m_pkPhysicsSDK->createHeightField(nxHeightFieldDesc); NIASSERT(m_pkHeightField); // NiFree(pnxHeightFieldSample); pnxHeightFieldSample = NULL; // 创建对象描述 NiPoint3 kWorldCenter(0, 0, fMidHeight); ///< ??为什么是这个值?? NxVec3 nxWorldCenter; NiPhysXTypes::NiPoint3ToNxVec3(kWorldCenter, nxWorldCenter); NiMatrix3 kWorldRotation(NiPoint3(0.f, 1.f, 0.f), NiPoint3(0.f, 0.f, 1.f), NiPoint3(1.f, 0.f, 0.f)); NxMat33 nxWorldRotation; NiPhysXTypes::NiMatrix3ToNxMat33(kWorldRotation, nxWorldRotation); NxMat34 kPose; kPose.t = nxWorldCenter; kPose.M = nxWorldRotation; NxHeightFieldShapeDesc nxHeightFieldShapeDesc; nxHeightFieldShapeDesc.heightField = m_pkHeightField; nxHeightFieldShapeDesc.heightScale = fHalfDeltaHeight / fThirtyTwoKb; nxHeightFieldShapeDesc.rowScale = 1.f; nxHeightFieldShapeDesc.columnScale = 1.f; nxHeightFieldShapeDesc.materialIndexHighBits = 0; nxHeightFieldShapeDesc.holeMaterial = 100; nxHeightFieldShapeDesc.meshFlags = NX_MESH_SMOOTH_SPHERE_COLLISIONS; nxHeightFieldShapeDesc.shapeFlags |= NX_SF_FEATURE_INDICES; // nxHeightFieldShapeDesc.shapeFlags |= NX_SF_VISUALIZATION; nxHeightFieldShapeDesc.shapeFlags &= ~NX_SF_VISUALIZATION; nxHeightFieldShapeDesc.group = E_COLLISION_GROUP_MASK_TERRAIN; nxHeightFieldShapeDesc.name = "PhysX_Terrain"; NxActorDesc nxActorDesc; nxActorDesc.body = NULL; nxActorDesc.name = NULL; nxActorDesc.shapes.push_back(&nxHeightFieldShapeDesc); nxActorDesc.globalPose = kPose; nxActorDesc.group = E_COLLISION_GROUP_MASK_TERRAIN; // 创建对象 NxActor* pkActor = m_pkScene->createActor(nxActorDesc); NIASSERT(pkActor); return true; }
NiPoint3 NiPoint3::operator/ (float scalar) const { float invScalar = 1.0f / scalar; return NiPoint3(invScalar * x, invScalar * y, invScalar * z); }
// Scalar operations NiPoint3 NiPoint3::operator* (float scalar) const { return NiPoint3(scalar * x, scalar * y, scalar * z); }
NiPoint3 NiPoint3::operator- (const NiPoint3& pt) const { return NiPoint3(x - pt.x, y - pt.y, z - pt.z); }
NiPoint3 NiPoint3::operator+ (const NiPoint3& pt) const { return NiPoint3(x + pt.x, y + pt.y, z + pt.z); }
NiPoint3 CyPlot::getPoint() { return m_pPlot ? m_pPlot->getPoint() : NiPoint3(0,0,0); }