Just wondering if anybody else has ran into something similar
Here we go.
The stuff I am using EZRotate, DGK and MS VC++ 8.0
I am working on a Turret Model that is attached to a model
here is the "basic code" no Media needed.
// Tank & Turret , Turning
/*
Here is a code snip it that shows a tank and turret that rotate independant of each other.
*/
#include "DarkGDK.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
float fMainBodyAngle;
float fMainBodyLastAngle;
float fTurretAngle;
float fFrontArc;
float fDif;
dbSyncOn ( );
dbSyncRate ( 60 );
// set our random seed to a value from the timer, this will help
// to ensure each time we run our program the random values appear
// more random
dbRandomize ( dbTimer ( ) );
// ******************* Create Main Body *********************************
int nMainBodyID = 1; // The Tank
float fMainBodyXAngle = 0.0;
float fMainBodyYAngle = 0.0;
float fMainBodyZAngle = 0.0;
float fMainBodyPosX = 0.0;
float fMainBodyPosY = 0.0;
float fMainBodyPosZ = 0.0;
dbMakeObjectBox(nMainBodyID,100,25,25);
dbFixObjectPivot(nMainBodyID);
fMainBodyXAngle = dbObjectAngleX(nMainBodyID);
fMainBodyYAngle = dbObjectAngleY(nMainBodyID);
fMainBodyZAngle = dbObjectAngleZ(nMainBodyID);
// give the object a color
dbColorObject ( nMainBodyID, dbRgb ( dbRnd ( 255 ), dbRnd ( 255 ), dbRnd ( 255 ) ) );
// increase specular power
dbSetObjectSpecularPower ( nMainBodyID, 255 );
// turn off ambient lighting for this object
dbSetObjectAmbient ( nMainBodyID, 0 );
fMainBodyLastAngle =fMainBodyYAngle;
// ******************* Create Node *********************************
int nNodeID = 2; // The Tank
dbMakeObjectSphere ( nNodeID, 15 );
dbFixObjectPivot(nNodeID);
dbGlueObjectToLimb ( nNodeID,nMainBodyID, 0 ) ;
dbOffsetLimb ( nNodeID, 0, 0, +25,0 ) ;
// give the object a color
dbColorObject ( nNodeID, dbRgb ( dbRnd ( 255 ), dbRnd ( 255 ), dbRnd ( 255 ) ) );
// increase specular power
dbSetObjectSpecularPower ( nNodeID, 255 );
// turn off ambient lighting for this object
dbSetObjectAmbient ( nNodeID, 0 );
// ******************* Create Turret *********************************
int nTurretID = 3; // The Turret
float fTurretXAngle = 0.0;
float fTurretYAngle = 0.0;
float fTurretZAngle = 0.0;
float fTurretPosX = 0.0;
float fTurretPosY = 0.0;
float fTurretPosZ = 0.0;
dbMakeObjectCone(nTurretID, 25);
dbFixObjectPivot(nTurretID);
fTurretXAngle = dbObjectAngleX(nTurretID);
fTurretYAngle = dbObjectAngleY(nTurretID);
fTurretZAngle = dbObjectAngleZ(nTurretID);
dbXRotateObject ( nTurretID, 90.0 ) ;
// give the object a color
dbColorObject ( nTurretID, dbRgb ( dbRnd ( 255 ), dbRnd ( 255 ), dbRnd ( 255 ) ) );
// increase specular power
dbSetObjectSpecularPower ( nTurretID, 255 );
// turn off ambient lighting for this object
dbSetObjectAmbient ( nTurretID, 0 );
// move our camera back so we can view the objects
dbPositionCamera (1, 500, 5000, 500 );
// now we come to our main loop, we call LoopGDK so some internal
// work can be carried out by the GDK
while ( LoopGDK ( ) )
{
// Get Up to date Varibles on Objects
// 1) Main Body
// * Get Position of Main Mody
fMainBodyPosX = dbObjectPositionX ( nMainBodyID);
fMainBodyPosY = dbObjectPositionY ( nMainBodyID);
fMainBodyPosZ = dbObjectPositionX ( nMainBodyID);
// * Get Angle of Main Body
fMainBodyXAngle = dbObjectAngleX(nMainBodyID);
fMainBodyYAngle = dbObjectAngleY(nMainBodyID);
fMainBodyZAngle = dbObjectAngleZ(nMainBodyID);
// 2) Node (This is a limb attacted to the Main Body
// 3) Turret - Attach Turret to Node Limb
// * Get Postion of Turret
fTurretPosX = dbLimbPositionX (nNodeID,0);
fTurretPosY = dbLimbPositionY (nNodeID,0);
fTurretPosZ = dbLimbPositionZ (nNodeID,0);
// * Get Turret Current Angle
fTurretXAngle = dbObjectAngleX(nTurretID);
fTurretYAngle = dbObjectAngleY(nTurretID);
fTurretZAngle = dbObjectAngleZ(nTurretID);
// 4) Get Front Arc
fMainBodyAngle = fMainBodyYAngle;
fDif = fMainBodyAngle - fMainBodyLastAngle;
// 5) Update Varibles
fMainBodyLastAngle = fMainBodyAngle;
// 6) Update Turret
fTurretYAngle += fDif;
// Text Display
dbText ( 0, 0, "Use [up] & [down] Keys to rotate Main Body, [left] & [right] to rotate Turret");
dbText ( 0, 16,"Main Body");
dbText ( 0, 32,"Angle Z");
dbText ( 0, 48,dbStr(fMainBodyYAngle));
dbText ( 200, 16,"Turret");
dbText ( 200, 32,"Angle Z");
dbText ( 200, 48,dbStr(fTurretYAngle));
// Key Commands
if (dbUpKey()==1) fMainBodyYAngle +=1.0;
if (dbDownKey()==1) fMainBodyYAngle -=1.0;
if (dbLeftKey()==1) fTurretYAngle +=1.0;
if (dbRightKey()==1) fTurretYAngle -=1.0;
// Boundries
// * Main Body
if (fMainBodyYAngle > 360.0) fMainBodyYAngle -=360.0;
if (fMainBodyYAngle < 0.0) fMainBodyYAngle +=360.0;
// * Turret
if (fTurretYAngle > 360.0) fTurretYAngle -=360.0;
if (fTurretYAngle < 0.0) fTurretYAngle +=360.0;
// adjust Main Body Angle
dbRotateObject ( nMainBodyID, fMainBodyXAngle, fMainBodyYAngle, fMainBodyZAngle );
// Place Turret to Node Location & Rotate
dbPositionObject(nTurretID, fTurretPosX,fTurretPosY,fTurretPosZ);
dbRotateObject(nTurretID,fTurretXAngle,fTurretYAngle,fTurretZAngle);
// Camera
dbSetCameraToFollow ( fMainBodyPosX,fMainBodyPosY,fMainBodyPosZ, 270.0, 100,50, 100, 0 ) ;
dbSync ( );
}
// before quitting delete our objects
return;
}
This works great. When I basically transplanted this a larger application, added models something odd happens
The idea is to have multiple turrets on the same object.
when the Ship turns the turret also must turn to match the new angle of the ship and maintain it's angle.
The concept is Main Body, I glued on a object as a marker point (node) and then a new object that follows (positioned on) the Node (which is the turret). This allows me to have the Turret independent of most of the glued on limb object.
Now the issue I got is Turret Model flips around when then ship reach the 90' mark or the -90' mark. This does not happen in the basic demo, but in my game. If the turret is rotating by itself (the ship is not rotating) the model behaves like it should. But when the ship rotates and breaks the 90' or the -90' mark, the Turret Model flips what ever degree it was from the ships front angle. If it was 30' left of the center. It would be 30' right after the ship reached the 90' angle.
The behavior issue happens constantly at that point.
Here are the screen shots.
1) I have my turret rotate to the -90' Mark.
2) I rotate the ship upwards. This rotates the turret and the ship. When the ship hits the 90' mark it begins to count back down and my turret flips 90 (or if it was 45' it would flip 45') .
This is kinda driving me crazy. Has this happened to anybody else?
There are many answers but just one question" ~ Jerilith the Mad