Space-Shooter project, three days to go

Published February 24, 2011
Advertisement
Today has been a slow day. I had got to the point where a good night sleep was more productive than hitting an early start for yet another day. The day didn't go quite as planned though, with some Real-Life emergencies occurring, but I did get some minor work in.

I went over my physics calculations once more today and added in a density measure for each rigid body. I also added in a spheric volume calculation based on the radius found for each rigid body, plus I used this info to calculate each rigid body's mass. These calculations are in meters and kilograms, and I'm working through my code, making everything consistent.



volume = (4.0f/3.0f) * M_PI * (radius*radius*radius);
mass = density * volume;



I then went and fixed my angular physics some. I had done it a bit wrong when I was adding in the angular velocity to the new orientation. So, in the end, here's how my physics calculation works (unless I find that I'm doing more things wrong, though I think this should be it):



void PhysicsMgr::addTorque(IEntity *body, const CL_Vec3f &force, const CL_Vec3f &position)
{
for(unsigned int i = 0; i < bodies.size(); i++)
{
if(body->getId() == bodies->entity->getId())
{
const CL_Vec3f &body_pos = body->GetProperty("Position").Get();
CL_Vec3f torque = CL_Vec3f::cross(position - body_pos, force);

bodies->torques.push_back(torque);
return;
}
}
}


void PhysicsMgr::update(float dt)
{
for(unsigned int i = 0; i < bodies.size(); i++)
{
CL_Vec3f P = bodies->position.Get();
CL_Vec3f V = bodies->velocity.Get();
CL_Vec3f L = bodies->angular_momentum.Get();
const CL_Mat3f &R = bodies->rotation_matrix.Get();
const CL_Mat3f &I_inverse = bodies->inertia_tensor;
const float &M = bodies->mass.Get();

CL_Vec3f F = CL_Vec3f(0.0f, 0.0f, 0.0f);
CL_Vec3f A;

CL_Vec3f T = CL_Vec3f(0.0f, 0.0f, 0.0f);
CL_Vec3f W; //Angular velocity

bool updateLinearVel = false;
if(bodies->impulses.size() > 0)
{
F = sumForces(bodies->impulses);
bodies->impulses.clear();
updateLinearVel = true;
}
else
{
F = sumForces(bodies->forces);
updateLinearVel = true;
}

bool updateTorque = false;
if(bodies->torque_impulses.size() > 0)
{
T = sumForces(bodies->torque_impulses);
bodies->torque_impulses.clear();
updateTorque = true;
}
else
{
T = sumForces(bodies->torques);
updateTorque = true;
}


if(updateLinearVel)
{
A = F / M;
V += A * dt;
}
P += V * dt;

if(updateTorque)
L += T * dt;

CL_Mat3f iI = R * I_inverse * CL_Mat3f::transpose(R);
W += iI * L;

bodies->pitch = bodies->pitch.Get() + W.x * dt;
bodies->yaw = bodies->yaw.Get() + W.y * dt;
bodies->roll = bodies->roll.Get() + W.z * dt;

bodies->velocity = V;
bodies->position = P;
bodies->angular_momentum = L;
}
}


void Mesh::updateMatrix(float dt)
{
CL_Mat4f mat;
CL_Quaternionf q;
qPitch = CL_Quaternionf::axis_angle(CL_Angle(pitch.Get(), cl_radians), CL_Vec3f(1.0f, 0.0f, 0.0f));
qHeading = CL_Quaternionf::axis_angle(CL_Angle(yaw.Get(), cl_radians), CL_Vec3f(0.0f, 1.0f, 0.0f));
qRoll = CL_Quaternionf::axis_angle(CL_Angle(roll.Get(), cl_radians), CL_Vec3f(0.0f, 0.0f, 1.0f));

q = qPitch * qHeading * qRoll;
rot = q.to_matrix();

mat = qPitch.to_matrix();
CL_Vec3f fwdDir;
fwdDir.y = mat[9];

q = qHeading * qPitch * qRoll;
mat = q.to_matrix();
fwdDir.x = mat[8];
fwdDir.z = mat[10];
leftDirection = CL_Vec3f::cross(fwdDir, upDirection);
forwardDirection = fwdDir;
}



Right now, I think the mass and velocity at which my spacecraft shots fires at, is too much for the system... either that, or I have to increase the mass of my asteroids, because when I hit them, and add a force impulse and torque impulse, they start spinning like crazy :P

Obviously there's some overhead in how I add forces to bodies, in that the entities themselves doesn't have the functionality for physics internally. Instead, at a collision for example, the two entities involved in the collision will be sent to the physics system through the AddImpulse and AddTorqueImpulse functions, with the force and center-of-mass offset position of the collision. So I have to look up the rigid body in the physics system before I can add the impact to the body's list of forces. This is still fast enough for the scope of my project for the exam though!

Tomorrow I plan on getting up real early and have at it. I'm first going to stabilize my angular physics, so that hitting them won't send them in a mad spinning frenzy by adding correct masses for the bodies. Then, I'll have to look at my collision detection algorithm. We're expected to add simulator level collision detection between spheres. This means that if I detect a collision, I'll have to run the simulation again, and check that this change of events didn't impact any other objects (thus causing more collisions). I'll also have to make sure no collisions happen within the time-frame of delta-time. Simply checking for a collision at dt isn't enough... this doesn't sound like it will hold up in a game... I'm afraid that in a dense asteroid field, this will simply slow down the performance too much, so I'll make sure to add the ability to turn it off completely, and I also only plan on adding this level of collision detection / simulation to the closest body (determined by LOD threshold).

Once this is in, it's all pollish left. Add some UI elements, get in some simple gameplay mechanics, etc :) I really hope that I can finish off the necessities tomorrow, so that on saturday and sunday I can focus on making it somewhat a game and not just a tech demo of shooting at asteroids without purpose!

So, though I don't have any updates to show for today... in respect to what will follow on this project after the exam, here's some simple sketches made by the artist on this project, Bill Lowe!

design0003.jpg

mockup02.jpg
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement