x
Yes
No
Do you want to visit DriveHQ English website?
Inicio
Características
Precios
Prueba gratuita
Software cliente
Acerca de nosotros
Servidor de archivos
|
Solución de copias de seguridad
|
Servidor FTP
|
Servidor de correo electrónico
|
Alojamiento web
|
Software cliente
Servidor de archivos
Solución de copia de seguridad
Servidor FTP
Servidor de correo electrónico
Alojamiento web
Software cliente
Tank.cpp - Hosted on DriveHQ Cloud IT Platform
Arriba
Subir
Descargar
Compartir
Publicar
Nueva carpeta
Nuevo archivo
Copiar
Cortar
Eliminar
Pegar
Clasificación
Actualizar
Ruta de la carpeta: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\GameFactory\C2Template\Tank.cpp
Girar
Efecto
Propiedad
Historial
#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
Dirección de la página
Dirección del archivo
Anterior
18/19
Siguiente
Descargar
( 2 KB )
Comments
Total ratings:
0
Average rating:
No clasificado
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.