I've written a 2d minimap for a space flight game and i am having some problems with it. Im hoping somebody could provide some pointers or assistance. Here is the code
Code: Select all
// draw navigation computer
if (Spaceship::mySpaceship->bNavComputer==true)
{
guiNavComp->setVisible(true);
driver->draw2DPolygon(core::position2d<s32>(102,280),5,video::SColor(100,255,255,255),3);
for (unsigned gbn=0; gbn < GameBody::GameBodys.Size(); gbn++)
{
//
core::vector3df targetShipPosition = GameBody::GameBodys[gbn]->v;
f32 transformedPos[4];
scene::ICameraSceneNode* camera2 = smgr->getActiveCamera();
core::matrix4 trans1 = camera2->getProjectionMatrix();
trans1 *= camera2->getViewMatrix();
transformedPos[0] = targetShipPosition.X;
transformedPos[1] = targetShipPosition.Y;
transformedPos[2] = targetShipPosition.Z;
transformedPos[3] = 1.0f;
trans1.multiplyWith1x4Matrix( transformedPos );
float xpos = transformedPos[1];
float ypos = transformedPos[2];
xpos = xpos / 500;
ypos = ypos / 500;
if (strcmp(GameBody::GameBodys[gbn]->mesh,"billboard")==0)
{
// draw the sun or a missile
driver->draw2DPolygon(core::position2d<s32>(xpos+102,ypos+280),5,video::SColor(100,255,240,0),16);
}
else if (strcmp(GameBody::GameBodys[gbn]->mesh,"sphere")==0)
{
// draw a planet
driver->draw2DPolygon(core::position2d<s32>(xpos+102,ypos+280),5,video::SColor(200,100,100,255),12);
}
else
{
driver->draw2DPolygon(core::position2d<s32>(xpos+102,ypos+280),5,video::SColor(100,255,0,0),12);
}
}
}
else
{
guiNavComp->setVisible(false);
}
Firstly my camera is offset from the spaceship so it gives an inaccurate representation of the gamebody objects. Can i do the camera calculations without creating another camera and then updating it along with the primary camera's position by amending the values before they are calculated by the amount of the offset?
Secondly, my minimap renders using this process as down being forward. Does anybody know of a way to change this to up being forward?
Many thanks in advance.