x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
ControllablePhysObj.cpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\GameFactory\ControllablePhysObj.cpp
旋转
特效
属性
历史版本
#include "ControllablePhysObj.h" #include "GameScene.h" const Real ControllablePhysObj::lowestSpeed = 0.1f/60.0f;//0.1 meters per second const Real ControllablePhysObj::skinWidthRatio = 1.0f/50.0f; // the ratio of skinWidth to the radius NxUserAllocatorDefault* ControllablePhysObj::memAllocator = NULL; NxControllerManager* ControllablePhysObj::controllerManager = NULL; ControllablePhysObj::ControllablePhysObj(Real radius, Real height, VisualObject* visualObject) :mPhysController(NULL), PhysicalObject(visualObject){ if (controllerManager==NULL){ //NxUserAllocator memAllocator = new NxUserAllocatorDefault(); controllerManager = NxCreateControllerManager(memAllocator); myassert(controllerManager!=NULL); } mHeight = height + 2*radius; mDisplacementVector = Vec3(0,0,mHeight/2); NxCapsuleControllerDesc desc; desc.upDirection = NX_Z; //desc.climbingMode = NxCapsuleClimbingMode::CLIMB_EASY; desc.height = height; desc.radius = radius; desc.skinWidth = radius * skinWidthRatio; desc.slopeLimit = 0; desc.stepOffset = 0.1f; desc.interactionFlag = NxCCTInteractionFlag::NXIF_INTERACTION_INCLUDE; desc.callback = this; Vec3 startPosition = mVisualObject->GetPosition(); desc.position = NxExtendedVec3(startPosition.x,startPosition.y,startPosition.z); mPhysController = controllerManager->createController(GameScene::GetSingleton()->GetPhysicsScnene(),desc); myassert(mPhysController!=NULL); mPhysController->reportSceneChanged(); mPhysController->setCollision(true); //mPhysController->getActor()->setGroup(5); mPhysController->getActor()->setContactReportFlags(NxContactPairFlag::NX_NOTIFY_FORCES | NxContactPairFlag::NX_NOTIFY_ON_START_TOUCH ); } ControllablePhysObj::~ControllablePhysObj(){ mPhysController->getActor()->userData = NULL; controllerManager->releaseController(*mPhysController); } void ControllablePhysObj::SetMovement(const Vec3& movingVector){ //if (movingVector.length()>0){ // int aa=0; //} NxU32 collisionFlags; mPhysController->move(movingVector,1,lowestSpeed,collisionFlags); } void ControllablePhysObj::FrameMove(Real elapsedTime){ mVisualObject->SetPosition(GetPosition());//only set position, because it does not have orientation NxU32 collisionFlags; mPhysController->move(Vec3(0,0,GameScene::GravityValue*elapsedTime),1,lowestSpeed,collisionFlags); } inline void ControllablePhysObj::RegisterPhysicalEventHandler(PhysicalEventHandler* physicalEventHandler){ myassert(mPhysController->getActor()->userData == NULL);//register one time only mPhysController->getActor()->userData = physicalEventHandler; } void ControllablePhysObj::SetCollisionEnable(bool enabled){ mPhysController->setCollision(enabled); if (!enabled){ mPhysController->setInteraction(NxCCTInteractionFlag::NXIF_INTERACTION_EXCLUDE); mPhysController->getActor()->putToSleep(); } } NxControllerAction ControllablePhysObj::onShapeHit (const NxControllerShapeHit &hit){ if (hit.shape->getActor().userData!=NULL){ static_cast
(this->mPhysController->getActor()->userData)->IsCollided( static_cast
(hit.shape->getActor().userData),hit.worldPos,hit.worldNormal); } return NxControllerAction::NX_ACTION_NONE; } NxControllerAction ControllablePhysObj::onControllerHit (const NxControllersHit &hit) { return NxControllerAction::NX_ACTION_NONE; }
ControllablePhysObj.cpp
网页地址
文件地址
上一页
11/55
下一页
下载
( 3 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.