Sunday, December 4, 2011

Programming, Programming, Programming, and more...

Programming.

It's what makes the game, and as much as I wish that games simply required you to make a bunch of pretty pictures, breathe life into them using your morning breath, and then things suddenly start moving in 3D, sadly it is not the case...

So for the last few days all I could work on was programming. Here's what I did:

High school vector math, seriously... to get a beam (green line at the moment) to shoot from the player character (the ball here) to where you click.


The math used was the simple solve the intersection of a line and a plane:

//the xy plane which the level constrains to
Vector3f planeV1 = Vector3f(0.f,0.f,0.f);
Vector3f planeNormal = Vector3f(0,0,-1.f);

//find the uparam
float uParam = planeNormal.Dot(planeV1-kPos)/planeNormal.Dot(kDir);
Vector3f pointOfIntersection = kPos + uParam*(kDir); //multiply the uparam found to get the point of intersection
pkVBuffer->Position3(1) = Vector3f(pointOfIntersection); //draw the line to this point
pkVBuffer->Color3(0,0) = ColorRGB(255,255,255);
pkVBuffer->Color3(0,1) = ColorRGB(255,0,255);

bool bClosed = false;
bool bContiguous = true;
m_spkPolyline = WM4_NEW Wm4::Polyline(pkVBuffer,bClosed,bContiguous);
m_spkPolyline->AttachEffect(WM4_NEW VertexColor3Effect);
m_stateNodePtr->AttachChild(m_spkPolyline);


The kDir, and kPos, values come from the GetPickRay function from the camera, and fills in the camera position, and a normalized vector towards the point clicked on the viewport. Sadly if you click too many times, the lines really start to add up. Another thing I worked on is the constraint plane, which was evidently scrapped and replaced with one line of code, to constrain the player to the Z axis:


//constrain player to z axis
m_playerRigidBody->getRigidBody()->setPosition(hkVector4(m_playerRigidBody->getRigidBody()->getPosition().getComponent(0), m_playerRigidBody->getRigidBody()->getPosition().getComponent(1),0,0));

You may have noticed the black and white dots in the picture above. It's the particle system that's pretty much a clone of the Particle System example in WildMagic 4. I found it really difficult to make the particles move, since the UpdatePointMotion function was being called in some other function deeply in-bedded in WildMagic4. For some odd reason the moment the game window popped up (not the command console) the UpdatePointMotion would stop being called, so I had to call it manually in the OnIdle function in mainGame.

There's still lots more to do, and the game is due... in less than 24 hours T-T