Hi, I have a crosshair in my game which will guide the players' aim. At the moment I am able to rotate the object (on the Y axis as it's the only axis I want to rotate it on) but it doesn't do it right. If I move the mouse left/down the object rotates anti-clockwise and the opposite for right/up.
Bascially I'd like to know how'd I go about making the object follow the mouse/crosshair exactly be it in a circle or when quickly moving back and forth from anywhere.
Here's my code.....apologies if you find it hard to read, I don't like having to retype code when I am experimenting.
#include "DarkGDK.h"
#include "DarkAI.h"
#pragma comment ( lib, "DarkAI.lib" )
//#include "DarkPhysics.h"
//#pragma comment (lib, "DarkPhysics.lib")
void DarkGDK ( void )
{
// entry point for the application
// switch on sync rate and set to a maximum of 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetDisplayMode (1280, 768, 32);
//PhyStart ( );
AIStart( );
//Object Settings
dbLoadObject("H-Jet Fighter 2-Move.x", 3);
dbLoadImage("JetFigh2.dds", 4);
dbTextureObject(3,4);
dbPositionObject(3,670,200,300);
dbRotateObject(3,0,180,0);
dbSetObjectSpeed(3,10);
float angy=dbObjectAngleY(3);
float angx=dbObjectAngleX(3);
float angz=dbObjectAngleZ(3);
float posx=dbObjectPositionX(3);
float posz=dbObjectPositionZ(3);
//Terrain
dbSetupTerrain();
dbMakeObjectTerrain(1);
dbSetTerrainHeightMap(1, "sandmap2.bmp");
dbLoadImage ("sandTexture.jpg", 2);
dbSetTerrainScale(1, 5.0f, .50f, 100.0f);
dbSetTerrainLight (1, 1.0f, -0.25f, 0.0f, 1.0f, 1.0f, 0.78f, 0.5f );
dbSetTerrainTexture (1,2,5);
dbBuildTerrain ( 1 );
dbMakeCamera (100);
dbPositionCamera (100,670,400,300);
dbRotateCamera (100,90,0,0);
dbLoadImage("Crosshair.jpg", 5);
int mouseX, mouseY;
dbChangeMouse(5);
// our main loop
while ( LoopGDK ( ) )
{
dbMoveObject(1,-3);
if (dbDownKey()==1) dbMoveObject(3,1);
if (dbUpKey()==1) dbMoveObject(3,-1);
if (dbObjectPositionX (3) <=490)
{
dbMoveObjectLeft(3,1);
}
if (dbObjectPositionX (3) >=850)
{
dbMoveObjectLeft(3,-1);
}
if (dbObjectScreenY (3) <=40)
{
dbMoveObject (3, 1);
}
if (dbObjectScreenY (3) >=730)
{
dbMoveObject (3, -1);
}
if (dbLeftKey()==1) dbMoveObjectLeft(3, -1);
/*{
dbRotateObject (3, angx, angy, angz);
}
else if (dbLeftKey() ==1)
{
dbMoveObjectLeft(3, -1);
dbRollObjectLeft (3, -30);
}*/
if (dbRightKey()==1) dbMoveObjectRight(3, -1);
/*{
dbRotateObject (3, angx, angy, angz);
}
else if (dbRightKey() ==1)
{
dbMoveObjectRight(3, -1);
dbRollObjectRight (3, -30);
}*/
if(dbLeftKey()==1)
{
if(dbRightKey()==1)
{
dbPositionObject(3,posx, 200, posz);
}
}
mouseX = dbMouseX();
mouseY = dbMouseY();
dbSprite(5, mouseX, mouseY, 5);
// update the screen
dbUpdateTerrain ( );
dbSync ( );
}
}