x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
Tank.cpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\GameFactory\C2Template\Tank.cpp
旋转
特效
属性
历史版本
#include "Tank.h" Tank::Tank():RigidEntity("tankbio"),isMoving(false),isRotating(false),mMovingSpeed(7.0f){ } Tank::~Tank(){} void Tank::MoveTo(const Vec3& position){ isMoving = true; movingTarget = position; RotateTo(position); } void Tank::Stop(){ mRigidPhysObj->Stop(); } void Tank::movingTo(Real elapsedTime, const Vec3& position){ Vec3 pos = position; //pos.z=0.0f; //Vec3 movingVector = (pos - this->GetPosition()).normalisedCopy(); //mControllablePhysObj->SetMovement(movingVector*mMovingSpeed*elapsedTime); Real curAngle= this->GetOrientation().getRoll().valueRadians();; //this->GetOrientation().ToAngleAxis(curAngle,Vec3(0,0,1.0f)); Vec3 movingVector = Vec3(-sinf(curAngle),+cosf(curAngle),0.0f)*mMovingSpeed; //movingVector.z = -GameScene::GravityValue;//it will bounce up! SetPosition(GetPosition()+movingVector*elapsedTime); //mRigidPhysObj->ApplyForce(movingVector*5.0f*elapsedTime); if (isAt(position)){ isMoving = false; isRotating = false; Stop(); } } bool Tank::isAt(const Vec3& pos) const{ return (this->GetPosition()-pos).length()<1.5f; } void Tank::FrameMove(Real elapsedTime){ RigidEntity::FrameMove(elapsedTime); if (isMoving) movingTo(elapsedTime,movingTarget); if (isRotating) rotatingTo(elapsedTime,rotatingTarget); } void Tank::RotateTo(Real angleRadian){ isRotating = true; rotatingTarget = angleRadian; } void Tank::RotateTo(const Vec3& position){ Vec3 pos = position; pos.z=0.0f; Vec3 movingVector = (pos - this->GetPosition()).normalisedCopy(); Real angle; if (movingVector.x==0){ if (movingVector.y>0) angle = 3.14159/2; else angle = -3.14159/2; }else{ angle = atanf(movingVector.y/movingVector.x); if (movingVector.x<0) angle+=3.14159; } angle+=3*3.14159/2;//to make this angle identical to character angle if (angle>3.14159*2) angle-=3.14159*2;//make sure it is not greater than 360 degrees RotateTo(angle); } void Tank::rotatingTo(Real elapsedTime, Real angleRadian){ RotateTo(movingTarget); Real curAngle = this->GetOrientation().getRoll().valueRadians(); if (curAngle<0) curAngle+=3.14159*2; Real distPlus,distMinus,dist; if (angleRadian>curAngle){ distPlus = abs(angleRadian-curAngle); distMinus = abs(3.14159*2-angleRadian+curAngle); if (distPlus
3.14159/180*2){ //SetOrientation(Quaternion(Radian(curAngle+dist*elapsedTime*2.0f),Vector3::UNIT_Z)); SetOrientation(GetOrientation()*Quaternion(Radian(dist*elapsedTime*2.0f),Vector3::UNIT_Z)); } //else // isRotating = false; }
Tank.cpp
网页地址
文件地址
上一页
18/19
下一页
下载
( 2 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.