Go to the documentation of this file.00001 #include "../pch.h"
00002
00003 Body::Body(const float3& position, const float3& rotation)
00004 : IBody(position, rotation)
00005 {
00006 flag = false;
00007 }
00008
00009 Body::~Body()
00010 {
00011 }
00012
00013 void Body::setActor(NxActor* actor)
00014 {
00015 this->actor = actor;
00016 if(this->actor)
00017 this->actor->setMaxAngularVelocity(200.0f);
00018 }
00019
00020 NxActor& Body::getActor(void)
00021 {
00022 return *actor;
00023 }
00024
00025 float3 Body::getPosition()
00026 {
00027 float3 pos;
00028 if(actor) {
00029 NxVec3 vec= actor->getGlobalPosition();
00030 pos(0) = vec[0];
00031 pos(1) = vec[1];
00032 pos(2) = vec[2];
00033 } else {
00034 pos(0) = transformation(0,3);
00035 pos(1) = transformation(1,3);
00036 pos(2) = transformation(2,3);
00037 }
00038
00039 return pos;
00040 }
00041
00042 void Body::setGlobalPosition(float3 position)
00043 {
00044 if(actor) {
00045 NxVec3 vec;
00046 vec[0] = position(0);
00047 vec[1] = position(1);
00048 vec[2] = position(2);
00049 actor->setGlobalPosition(vec);
00050 } else {
00051 transformation(0,3) = position(0);
00052 transformation(1,3) = position(1);
00053 transformation(2,3) = position(2);
00054 }
00055 }
00056
00057 void Body::stopMotion()
00058 {
00059 if(actor) {
00060 actor->setLinearMomentum(NxVec3(0,0,0));
00061 actor->setAngularMomentum(NxVec3(0,0,0));
00062
00063
00064 actor->putToSleep();
00065 actor->raiseBodyFlag(NX_BF_KINEMATIC);
00066 flag = true;
00067 }
00068 }
00069
00070 void Body::setMass(int mass)
00071 {
00072 if(actor)
00073 actor->setMass((NxReal)mass);
00074 }
00075
00076
00077 void Body::applyForce(float3 vec)
00078 {
00079 if(!actor)
00080 return;
00081
00082 NxVec3 vec3;
00083 vec3[0] = vec(0);
00084 vec3[1] = vec(1);
00085 vec3[2] = vec(2);
00086
00087 if(flag == true) {
00088 actor->clearBodyFlag(NX_BF_KINEMATIC);
00089 flag = false;
00090 }
00091 actor->addForce(vec3, NX_IMPULSE ,true);
00092 actor->setLinearDamping(0.08f);
00093 actor->setAngularDamping(0.08f);
00094
00095 }
00096
00097 bool Body::isMoving()
00098 {
00099 NxVec3 vel = actor->getLinearVelocity();
00100
00101
00102 bool xMove, yMove, zMove;
00103 xMove = vel[0] < -0.1f || vel[0] > 0.1f;
00104 yMove = vel[1] < -0.1f || vel[1] > 0.1f;
00105 zMove = vel[2] < -0.1f || vel[2] > 0.1f;
00106 return xMove || yMove || zMove;
00107 }
00108
00109 void Body::slowDown()
00110 {
00111 NxVec3 vel = actor->getLinearVelocity();
00112 NxReal magn = vel.magnitudeSquared();
00113
00114 if(magn < 1.0) {
00115 actor->setLinearDamping(actor->getLinearDamping() * (2.0f - magn));
00116 actor->setAngularDamping(actor->getAngularDamping() * (2.0f - magn));
00117 }
00118 }