void InitNx() { // Create the physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION); if (!gPhysicsSDK) return; // Set the physics parameters gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01); // Set the debug visualization parameters gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1); // gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LIMITS, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LOCAL_AXES, 1); // Create the scene NxSceneDesc sceneDesc; sceneDesc.gravity = gDefaultGravity; sceneDesc.simType = NX_SIMULATION_HW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene){ sceneDesc.simType = NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) return; } // Create the default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.5); defaultMaterial->setStaticFriction(0.5); defaultMaterial->setDynamicFriction(0.5); // Create the objects in the scene CreateGroundPlane(); capsule1 = CreateCapsule(NxVec3(0,5,0), 1, 0.5, 10); capsule1->raiseBodyFlag(NX_BF_KINEMATIC); capsule2 = CreateCapsule(NxVec3(0,3,0), 1, 0.5, 10); // capsule2->setLinearDamping(0.1); capsule2->raiseBodyFlag(NX_BF_DISABLE_GRAVITY); NxVec3 globalAnchor = NxVec3(0,5,0); NxVec3 globalAxis = NxVec3(0,1,0); d6Joint = CreateD6Joint(capsule1, capsule2, globalAnchor, globalAxis); gSelectedActor = capsule2; gForceStrength = 50000; gCameraSpeed = 10; // Initialize HUD InitializeHUD(); InitializeSpecialHUD(); // Get the current time getElapsedTime(); // Start the first frame of the simulation if (gScene) StartPhysics(); }
//初期化 void GameStage::Create(){ try{ //リソースの作成 CreateResourses(); //ビュー類を作成する CreateViews(); //プレートの作成 CreatePlate(); //追いかけるオブジェクトの作成 CreateSeekObject(); //固定のボックスの作成 CreateFixedBox(); //上下移動しているボックスの作成 CreateMoveBox(); //カプセル作成 CreateCapsule(); //球体作成 CreateSphere(); //衝突するスクエアの作成 CreateHitTestSquare(); //プレーヤーの作成 CreatePlayer(); } catch (...){ throw; } }
void KeyboardUpCallback(unsigned char key, int x, int y) { gKeys[key] = false; switch (key) { case 'p': { bPause = !bPause; if (bPause) hud.SetDisplayString(1, "Paused - Hit \"p\" to Unpause", 0.3f, 0.55f); else hud.SetDisplayString(1, "", 0.0f, 0.0f); getElapsedTime(); break; } case 'f': { bForceMode = !bForceMode; break; } case 'b': { box = CreateBox(NxVec3(2,5-0.75,7), NxVec3(0.75,0.75,0.75), 1); sphere = CreateSphere(NxVec3(0,4-0.4,1), 0.4, 1); capsule = CreateCapsule(NxVec3(3,0-(1+0.5),8), 1, 1, 1); break; } case 27 : { exit(0); break; } default : { break; } } }
//カプセルとモデルのあたり判定 CollisionParameter Actor::CapsuleModel(const Actor& other)const{ Vector3 down = -RCVector3::normalize(RCMatrix4::getUp(parameter.matrix)); Vector3 pos = RCMatrix4::getPosition(parameter.matrix) - down; Vector3 end = down * 2.0f + pos; float len = RCVector3::length(end - pos); return ModelCapsule(other.parameter.matrix, other.parameter.octId, CreateCapsule(pos,end,parameter.radius)); }
void SetupAttachmentScene() { sprintf(gTitleString, "Attachment Demo"); // Create objects in scene groundPlane = CreateGroundPlane(); NxActor* box1 = CreateBox(NxVec3(-7,12.25,0), NxVec3(2.5,1,1), 0); NxActor* box2 = CreateBox(NxVec3(0,12.25,0), NxVec3(2.5,1,1), 0); NxActor* box3 = CreateBox(NxVec3(7,12.25,0), NxVec3(2.5,1,1), 0); NxActor* attachedBox = CreateBox(NxVec3(-7.2,4.5,1.6), NxVec3(1.25,1,1), 1); NxActor* attachedSphere = CreateSphere(NxVec3(-0.25,4.0,2.0), 1.3, 1); NxActor* attachedCapsule = CreateCapsule(NxVec3(9.0,5.5,2.0),2.0, 1, 1); NxReal damping = 0.3; attachedBox->setAngularDamping(damping); attachedBox->setLinearDamping(damping); attachedSphere->setAngularDamping(damping); attachedSphere->setLinearDamping(damping); attachedCapsule->setAngularDamping(damping); attachedCapsule->setLinearDamping(damping); NxQuat q; q.fromAngleAxis(90,NxVec3(0,0,1)); attachedCapsule->setGlobalOrientationQuat(q); // Cloth NxClothDesc clothDesc; clothDesc.globalPose.M.rotX(1.3); clothDesc.thickness = 0.3; clothDesc.attachmentResponseCoefficient = 1; clothDesc.flags |= NX_CLF_BENDING; clothDesc.flags |= NX_CLF_BENDING_ORTHO; clothDesc.flags |= NX_CLF_DAMPING | NX_CLF_VISUALIZATION; if (gHardwareCloth) clothDesc.flags |= NX_CLF_HARDWARE; // Cloth attaching to sphere clothDesc.globalPose.t = NxVec3(0.75,5,2); MyCloth* regularCloth1 = new MyCloth(gScene, clothDesc, 2, 8, 0.4); regularCloth1->getNxCloth()->attachToCollidingShapes(NX_CLOTH_ATTACHMENT_TWOWAY); gCloths.push_back(regularCloth1); // Cloth attaching to box clothDesc.globalPose.t = NxVec3(-6.2,5,2); MyCloth* regularCloth2 = new MyCloth(gScene, clothDesc, 2, 8, 0.4); regularCloth2->getNxCloth()->attachToCollidingShapes(NX_CLOTH_ATTACHMENT_TWOWAY); gCloths.push_back(regularCloth2); // Cloth attaching to capsule clothDesc.globalPose.t = NxVec3(8.0,5,2); clothDesc.attachmentTearFactor = 2.0; MyCloth* regularCloth3 = new MyCloth(gScene, clothDesc, 2, 8, 0.4); regularCloth3->getNxCloth()->attachToShape(box3->getShapes()[0], NX_CLOTH_ATTACHMENT_TEARABLE); regularCloth3->getNxCloth()->attachToShape(attachedCapsule->getShapes()[0], NX_CLOTH_ATTACHMENT_TWOWAY); gCloths.push_back(regularCloth3); }
void InitNx() { // Create a memory allocator gAllocator = new UserAllocator; // Create the physics SDK gPhysicsSDK = CreatePhysics(); // Create the scene NxSceneDesc sceneDesc; sceneDesc.gravity = gDefaultGravity; sceneDesc.simType = NX_SIMULATION_HW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene){ sceneDesc.simType = NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) return; } // Create the default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.5); defaultMaterial->setStaticFriction(0.5); defaultMaterial->setDynamicFriction(0.5); // Set Core Dump directory char buff[512]; FindMediaFile(fnameCD, buff); #ifdef WIN32 SetCurrentDirectory(buff); #elif LINUX chdir(buff); #endif // Create the objects in the scene NxActor* groundPlane = CreateGroundPlane(); NxActor* box = CreateBox(NxVec3(5,0,0), NxVec3(0.5,1,0.5), 20); NxActor* sphere = CreateSphere(NxVec3(0,0,0), 1, 10); NxActor* capsule = CreateCapsule(NxVec3(-5,0,0), 2, 0.5, 10); // pyramid = CreatePyramid(NxVec3(0,0,0), NxVec3(1,0.5,1.5), 10); AddUserDataToActors(gScene); gSelectedActor = capsule; // gSelectedActor = pyramid; // Initialize HUD InitializeHUD(); // Get the current time getElapsedTime(); // Start the first frame of the simulation if (gScene) StartPhysics(); }
void CreateDrainActors() { // Create the drains in the scene box = CreateBox(NxVec3(5,0,0), NxVec3(1.5,1.5,1.5), 1); box->getShapes()[0]->setFlag(NX_SF_FLUID_DRAIN,true); sphere = CreateSphere(NxVec3(0,0.0,0), 1.5, 1); sphere->getShapes()[0]->setFlag(NX_SF_FLUID_DRAIN,true); capsule = CreateCapsule(NxVec3(-5,0,0), 1, 1, 1); capsule->getShapes()[0]->setFlag(NX_SF_FLUID_DRAIN,true); gSelectedActor = sphere; }
dCustomInverseDynamicsEffector* AddLeg(DemoEntityManager* const scene, void* const rootNode, const dMatrix& matrix, dFloat partMass, dFloat limbLenght) { NewtonBody* const parent = NewtonInverseDynamicsGetBody(m_kinematicSolver, rootNode); dFloat inertiaScale = 4.0f; // make limb base dMatrix baseMatrix(dRollMatrix(dPi * 0.5f)); dMatrix cylinderMatrix(baseMatrix * matrix); NewtonBody* const base = CreateCylinder(scene, cylinderMatrix, partMass, inertiaScale, 0.2f, 0.1f); dCustomInverseDynamics* const baseHinge = new dCustomInverseDynamics(cylinderMatrix, base, parent); baseHinge->SetJointTorque(1000.0f); baseHinge->SetTwistAngle(-0.5f * dPi, 0.5f * dPi); void* const baseHingeNode = NewtonInverseDynamicsAddChildNode(m_kinematicSolver, rootNode, baseHinge->GetJoint()); //make limb forward arm dMatrix forwardArmMatrix(dPitchMatrix(-30.0f * dDegreeToRad)); dVector forwardArmSize(limbLenght * 0.25f, limbLenght * 0.25f, limbLenght, 0.0f); forwardArmMatrix.m_posit += forwardArmMatrix.m_right.Scale(forwardArmSize.m_z * 0.5f); NewtonBody* const forwardArm = CreateBox(scene, forwardArmMatrix * matrix, forwardArmSize, partMass, inertiaScale); dMatrix forwardArmPivot(forwardArmMatrix); forwardArmPivot.m_posit -= forwardArmMatrix.m_right.Scale(forwardArmSize.m_z * 0.5f); dCustomInverseDynamics* const forwardArmHinge = new dCustomInverseDynamics(forwardArmPivot * matrix, forwardArm, base); forwardArmHinge->SetJointTorque(1000.0f); forwardArmHinge->SetTwistAngle(-0.5f * dPi, 0.5f * dPi); void* const forwardArmHingeNode = NewtonInverseDynamicsAddChildNode(m_kinematicSolver, baseHingeNode, forwardArmHinge->GetJoint()); //make limb forward arm dMatrix armMatrix(dPitchMatrix(-90.0f * dDegreeToRad)); dFloat armSize = limbLenght * 1.25f; armMatrix.m_posit += forwardArmMatrix.m_right.Scale(limbLenght); armMatrix.m_posit.m_y -= armSize * 0.5f; NewtonBody* const arm = CreateCapsule(scene, armMatrix * matrix, partMass, inertiaScale, armSize * 0.2f, armSize); dMatrix armPivot(armMatrix); armPivot.m_posit.m_y += armSize * 0.5f; dCustomInverseDynamics* const armHinge = new dCustomInverseDynamics(armPivot * matrix, arm, forwardArm); armHinge->SetJointTorque(1000.0f); armHinge->SetTwistAngle(-0.5f * dPi, 0.5f * dPi); void* const armHingeNode = NewtonInverseDynamicsAddChildNode(m_kinematicSolver, forwardArmHingeNode, armHinge->GetJoint()); dMatrix effectorMatrix(dGetIdentityMatrix()); effectorMatrix.m_posit = armPivot.m_posit; effectorMatrix.m_posit.m_y -= armSize; dHexapodEffector* const effector = new dHexapodEffector(m_kinematicSolver, armHingeNode, parent, effectorMatrix * matrix); effector->SetAsThreedof(); effector->SetMaxLinearFriction(partMass * DEMO_GRAVITY * 10.0f); effector->SetMaxAngularFriction(partMass * DEMO_GRAVITY * 10.0f); return effector; }
void InitNx() { // Create a memory allocator gAllocator = new UserAllocator; // Create the physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator); if (!gPhysicsSDK) return; // Set the physics parameters gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01); // Set the debug visualization parameters gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LIMITS, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_JOINT_LOCAL_AXES, 1); // Create the scene NxSceneDesc sceneDesc; sceneDesc.gravity = gDefaultGravity; sceneDesc.simType = NX_SIMULATION_HW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene){ sceneDesc.simType = NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) return; } // Create the default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.5); defaultMaterial->setStaticFriction(0.5); defaultMaterial->setDynamicFriction(0.5); // Create the objects in the scene CreateGroundPlane(); // Slider Joint capsule1 = CreateCapsule(NxVec3(0,5,0), 1, 0.5, 10); capsule1->raiseBodyFlag(NX_BF_KINEMATIC); capsule2 = CreateCapsule(NxVec3(0,3,0), 1, 0.5, 10); capsule2->raiseBodyFlag(NX_BF_DISABLE_GRAVITY); NxVec3 globalAnchor = gJointStartPos; NxVec3 globalAxis = NxVec3(0,1,0); d6Joint = CreateD6Joint(capsule1, capsule2, globalAnchor, globalAxis); ball = CreateFollowBall(gBallStartPos,0.25,1); ball->raiseBodyFlag(NX_BF_KINEMATIC); NxMat33 orient = ball->getGlobalOrientation(); NxMat33 controlOrient; controlOrient.setRow(0, orient.getRow(2)); controlOrient.setRow(1, orient.getRow(0)); controlOrient.setRow(2, orient.getRow(1)); ball->setGlobalOrientation(controlOrient); gSelectedActor = ball; gForceStrength = 1500; gCameraSpeed = 10; box = CreateBox(NxVec3(3,0,0), NxVec3(0.5,1,0.5), 20); sphere = CreateSphere(NxVec3(0,0,3), 1, 10); capsule = CreateCapsule(NxVec3(-3,0,0), 2, 0.5, 10); pyramid = CreatePyramid(NxVec3(0,0,-3), NxVec3(0.75,1.5,0.75), 10); box->setLinearDamping(0.5); sphere->setLinearDamping(0.5); capsule->setLinearDamping(0.5); pyramid->setLinearDamping(0.5); AddUserDataToActors(gScene); // Initialize HUD InitializeHUD(); // Get the current time getElapsedTime(); // Start the first frame of the simulation if (gScene) StartPhysics(); }
void InitNx() { // Create a memory allocator gAllocator = new UserAllocator; // Initialize physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator); if (!gPhysicsSDK) return; gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.05); gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 10); //gPhysicsSDK->setParameter(NX_VISUALIZE_FLUID_POSITION, 1); //gPhysicsSDK->setParameter(NX_VISUALIZE_FLUID_VELOCITY, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_FLUID_PACKETS, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_FLUID_DRAINS, 1); // Create a scene NxSceneDesc sceneDesc; sceneDesc.simType = NX_SIMULATION_SW; sceneDesc.gravity = gDefaultGravity; gScene = gPhysicsSDK->createScene(sceneDesc); // Create the default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.5); defaultMaterial->setStaticFriction(0.5); defaultMaterial->setDynamicFriction(0.5); // Initialize cooking NxInitCooking(NULL, &gErrorStream); // Load ASE files int set = 0; #ifdef WIN32 set = SetCurrentDirectory(&fname[0]); if (!set) set = SetCurrentDirectory(&fname1[0]); if (!set) set = SetCurrentDirectory(&fname2[0]); if (!set) set = SetCurrentDirectory(&fname3[0]); if (!set) { char basePath[256]; GetModuleFileName(NULL, basePath, 256); char* pTmp = strrchr(basePath, '\\'); basePath[pTmp-basePath+1] = 0; SetCurrentDirectory(basePath);//for running from start menu set = SetCurrentDirectory(&fname2[0]); } #elif LINUX set = chdir(&fname[0]); if (set != 0) set = chdir(&fname2[0]); if (set != 0) set = chdir(&fname3[0]); #endif bowl = CookASE("fluidSample.ase", gScene, NxVec3(1,0,0)); flume = CookASE("coolFlow.ase", gScene, NxVec3(1,-4,-0), NxVec3(1,0.2,1)); box = CreateBox(NxVec3(2,5-0.75,7), NxVec3(0.75,0.75,0.75), 1); sphere = CreateSphere(NxVec3(0,4-0.4,1), 0.4, 1); capsule = CreateCapsule(NxVec3(3,0-(1+0.5),8), 1, 1, 1); CreateBox(NxVec3(0,-10-1,0), NxVec3(40,1,40), 0); fluid = CreateFluid(NxVec3(0,1.5,0), 19, 0.1, gScene); AddUserDataToActors(gScene); //((ActorUserData*)(drain->userData))->flags |= UD_IS_DRAIN; // Page in the hardware meshes if(bHardwareScene) PageInHardwareMeshes(gScene); gSelectedActor = box; // Initialize HUD InitializeHUD(); // Get the current time getElapsedTime(); // Start the first frame of the simulation if (gScene) StartPhysics(); }
//ポジションとビューをセット void Camera::SetCamera(Vector3 cameraPos, Vector3 cameraView,float frameTime){ // 射影行列 D3DXMatrixPerspectiveFovLH(&matProj, 3.1415926f / 2.0f, 4.0f / 3.0f/*1.5f*/, 0.1f, 100.0f); mCameraParam.InputAngle = Device::GetInstance().GetInput()->MouseVec(); if (Device::GetInstance().GetInput()->KeyDown(INPUTKEY::KEY_UP)) mCameraParam.InputAngle.y = 1.0f; if (Device::GetInstance().GetInput()->KeyDown(INPUTKEY::KEY_DOWN)) mCameraParam.InputAngle.y = -1.0f; if (Device::GetInstance().GetInput()->KeyDown(INPUTKEY::KEY_RIGHT)) mCameraParam.InputAngle.x = 1.0f; if (Device::GetInstance().GetInput()->KeyDown(INPUTKEY::KEY_LEFT)) mCameraParam.InputAngle.x = -1.0f; //入力値をもとに計算 mCameraParam.AngleH += mCameraParam.InputAngle.x * CAMERA_ANGLE_SPEED * frameTime; mCameraParam.AngleV += mCameraParam.InputAngle.y * CAMERA_ANGLE_SPEED * frameTime; //クランプ if (mCameraParam.AngleH > Math::radian(180))mCameraParam.AngleH = Math::radian(-180); else if (mCameraParam.AngleH < Math::radian(-180))mCameraParam.AngleH = Math::radian(180); if (mCameraParam.AngleV > Math::radian(180))mCameraParam.AngleV = Math::radian(-180); else if (mCameraParam.AngleV < Math::radian(-180))mCameraParam.AngleV = Math::radian(180); //テストフォント Graphic::GetInstance().DrawFont(FONT_ID::TEST_FONT, vector2(0, 485), vector2(0.20f, 0.25f), 0.5f,"AngleH:"+ std::to_string(Math::angle(mCameraParam.AngleH))+"f"); Graphic::GetInstance().DrawFont(FONT_ID::TEST_FONT, vector2(0, 500), vector2(0.20f, 0.25f), 0.5f,"AngleV:"+ std::to_string(Math::angle(mCameraParam.AngleV))+"f"); //ターゲットをプレイヤーより少し上にセット mCameraParam.Target = RCMatrix4::getPosition(mat) + RCVector3::normalize(RCMatrix4::getUp(mat)) * CAMERA_PLAYER_TARGET_HEIGHT;//* Time::DeltaTime; //ターゲットの位置のマトリックス取得 Matrix4 t = RCMatrix4::translate(mCameraParam.Target); //プレイヤーの左を使う Vector3 left = RCVector3::normalize(RCMatrix4::getLeft(mat)); //左を軸に上下の回転を求める Matrix4 pitchMat = RCQuaternion::rotate(left, Math::angle(mCameraParam.AngleV - angleC)); //差分用(Player.h参照) angleC = mCameraParam.AngleV; //今の前にさっきの回転を掛ける Vector3 front = RCVector3::normalize(RCMatrix4::getFront(matrix) * pitchMat); //外積を用いて上を求める Vector3 up = RCVector3::normalize(RCVector3::cross(front, left)); //正しい前を求める front = RCVector3::normalize(RCVector3::cross(left, up)); //後ろに下げる Matrix4 trans = RCMatrix4::translate(front * CAMERA_PLAYER_LENGTH); //Targetの位置から後ろに下げる Matrix4 x = t* trans; //プレイヤーのけつ方向とカメラ方向のなす角 float angle = Math::acos(RCVector3::dot(RCVector3::normalize(RCMatrix4::getFront(mat)), front)); //回転行列をセット Matrix4 rotate = RCMatrix4::Identity(); RCMatrix4::setLeft(rotate, left); RCMatrix4::setUp(rotate, up); RCMatrix4::setFront(rotate, front); matrix = rotate; //プレイヤーのけつ方向とカメラ方向のなす角が70度以上なら while (angle > 70.0f){ //1度ずつ引いて求める if (RCVector3::cross(RCVector3::normalize(RCMatrix4::getFront(mat)), front) == left){ mCameraParam.AngleV -= Math::radian(abs(angle) - 70.0f); } else{ mCameraParam.AngleV += Math::radian(abs(angle) - 70.0f); } pitchMat = RCQuaternion::rotate(left, Math::angle(mCameraParam.AngleV - angleC)); angleC = mCameraParam.AngleV; front = RCVector3::normalize(RCMatrix4::getFront(matrix) * pitchMat); up = RCVector3::normalize(RCVector3::cross(front, left)); front = RCVector3::normalize(RCVector3::cross(left, up)); angle = Math::acos(RCVector3::dot(RCVector3::normalize(RCMatrix4::getFront(mat)), front)); rotate = RCMatrix4::Identity(); RCMatrix4::setLeft(rotate, left); RCMatrix4::setUp(rotate, up); RCMatrix4::setFront(rotate, front); matrix = rotate; if (angle < 70.0f)break; } trans = RCMatrix4::translate(front * CAMERA_PLAYER_LENGTH); x = t* trans; mCameraParam.Eye = RCMatrix4::getPosition(x);//* Time::DeltaTime; //カメラとのあたり判定(2分探索法を用いて距離を短くしていく) bool hitNum = ModelCapsule(*stage->ReturnMat(), OCT_ID::STAGE_OCT, CreateCapsule(mCameraParam.Eye, mCameraParam.Target, CAMERA_COLLISION_SIZE)).colFlag; std::string s = (hitNum == true ? "TRUE" : "FALSE"); Graphic::GetInstance().DrawFont(FONT_ID::TEST_FONT, vector2(0, 470), vector2(0.20f, 0.25f), 0.5f, "MODELCAPSULEFLAG:" +s ); if (hitNum){ float notHitLength = 0.0f; float cameraLen = CAMERA_PLAYER_LENGTH; do{ float testLen = notHitLength + (cameraLen - notHitLength) / 2.0f; trans = RCMatrix4::translate(front * testLen); x = t* trans; mCameraParam.Eye = RCMatrix4::getPosition(x);//* Time::DeltaTime; bool hit = ModelCapsule(*stage->ReturnMat(), OCT_ID::STAGE_OCT, CreateCapsule(mCameraParam.Eye, mCameraParam.Target, CAMERA_COLLISION_SIZE)).colFlag; if (hit){ cameraLen = testLen; } else{ notHitLength = testLen; } } while (cameraLen - notHitLength > 0.01f); } mCameraParam.Up = up;//* Time::DeltaTime; // ビュー行列 D3DXMatrixLookAtLH(&matView, &RConvert(&mCameraParam.Eye), &RConvert(&mCameraParam.Target), &RConvert(&mCameraParam.Up)); }
void InitNx() { // Initialize Camera Parameters gCameraAspectRatio = 1.0f; gCameraPos = NxVec3(0,5,-15); gCameraForward = NxVec3(0,0,1); gCameraRight = NxVec3(-1,0,0); // Create the physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION); if (!gPhysicsSDK) return; // Set the physics parameters gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01); gPhysicsSDK->setParameter(NX_DEFAULT_SLEEP_LIN_VEL_SQUARED, 0.15*0.15); gPhysicsSDK->setParameter(NX_DEFAULT_SLEEP_ANG_VEL_SQUARED, 0.14*0.14); // Set the debug visualization parameters gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_AABBS, 1); // Create the scene NxSceneDesc sceneDesc; sceneDesc.gravity = gDefaultGravity; sceneDesc.simType = NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) { sceneDesc.simType = NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(!gScene) return; } // Create the default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.5); defaultMaterial->setStaticFriction(0.5); defaultMaterial->setDynamicFriction(0.5); // Create the objects in the scene groundPlane = CreateGroundPlane(); // Create dynamic actors CreateSphere(NxVec3(6.0f, 0.0f, 24.0f), 0); CreateBox(NxVec3(6.0f, 0.0f, 16.0f), 0); CreateCapsule(NxVec3(6.0f, 0.0f, 6.0f), 0); gSelectedActor = CreateConvex(NxVec3(6.0f, 0.0f, 0.0f), 0); // Create static actors CreateSphere(NxVec3(0.0f, 0.0f, 24.0f), 0); CreateBox(NxVec3(0.0f, 0.0f, 16.0f), 0); CreateCapsule(NxVec3(0.0f, 0.0f, 6.0f), 0); CreateConvex(NxVec3(0.0f, 0.0f, 0.0f), 0); // Create kinematic actors CreateSphere(NxVec3(-6.0f, 0.0f, 24.0f), 0); CreateBox(NxVec3(-6.0f, 0.0f, 16.0f), 0); CreateCapsule(NxVec3(-6.0f, 0.0f, 6.0f), 0); CreateConvex(NxVec3(-6.0f, 0.0f, 0.0f), 0); bPause = false; gCapsuleSegment.p0 = NxVec3(0, 1.2f, 0.5f); gCapsuleSegment.p1 = NxVec3(0, 3.2f, 0.5f); // Initialize HUD InitializeHUD(); // Get the current time getElapsedTime(); // Start the first frame of the simulation if (gScene) StartPhysics(); }
void KinematicController::Draw() { CreateCapsule(); }
void InitNx() { // Create a memory allocator gAllocator = new UserAllocator; // Create the physics SDK gPhysicsSDK = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, gAllocator, &gErrorStream); if (0 == gPhysicsSDK) return; // Set the physics parameters gPhysicsSDK->setParameter(NX_SKIN_WIDTH, 0.01); // Set the debug visualization parameters gPhysicsSDK->setParameter(NX_VISUALIZATION_SCALE, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_COLLISION_SHAPES, 1); gPhysicsSDK->setParameter(NX_VISUALIZE_ACTOR_AXES, 1); // Create the scene NxSceneDesc sceneDesc; sceneDesc.gravity = gDefaultGravity; sceneDesc.simType = NX_SIMULATION_HW; if (gbThreadScheduler) { sceneDesc.flags |= NX_SF_ENABLE_MULTITHREAD; sceneDesc.customScheduler = &gCustomScheduler; gCustomScheduler.CreateThreads(2); } else if (gbThreadPolling) { sceneDesc.flags |= NX_SF_ENABLE_MULTITHREAD; } else if (gbThreadSDKManage) { sceneDesc.flags |= NX_SF_ENABLE_MULTITHREAD; sceneDesc.internalThreadCount = 2; } else if (gbNoThread) { sceneDesc.flags &= ~NX_SF_SIMULATE_SEPARATE_THREAD; } else assert(0); gScene = gPhysicsSDK->createScene(sceneDesc); if(0 == gScene) { sceneDesc.simType = NX_SIMULATION_SW; gScene = gPhysicsSDK->createScene(sceneDesc); if(0 == gScene) return; } if (gbThreadPolling) { gPollingThreads.CreateThreads(2, gScene); // We must reset the polling threads so they are ready for the next run gPollingThreads.ResetPollForWork(); } // Create the default material NxMaterial* defaultMaterial = gScene->getMaterialFromIndex(0); defaultMaterial->setRestitution(0.5); defaultMaterial->setStaticFriction(0.5); defaultMaterial->setDynamicFriction(0.5); // Create the objects in the scene groundPlane = CreateGroundPlane(); box = CreateBox(NxVec3(5,0,0), NxVec3(0.5,1,0.5), 20); sphere = CreateSphere(NxVec3(0,0,5), 1, 10); capsule = CreateCapsule(NxVec3(-5,0,0), 2, 0.5, 10); pyramid = CreateHalfPyramid(NxVec3(0,0,0), NxVec3(1,0.5,1.5), 10); gSelectedActor = pyramid; AddUserDataToActors(gScene); // Initialize HUD InitializeHUD(); // Start the first frame of the simulation if (gScene) StartPhysics(); }