Hey all, after the convention I've been busy with my work at uni, but as I've settled down a bit I've got some free time to write some games. Yesterday I started up a new 3D game, but have managed to somehow fall over at the first hurdle whilst using the dbScaleObject() command.
I'd written a "player" class to also include object pos/rotation/scale variables and the respective functions to get/set them, and to include an "update" function which effectively retrieves all those variables and update the object accordingly. Example:
// Object vector members (Position)
void Player::xPos(float x) { xPosition = x; }
float Player::xPos() const { return xPosition; }
// Update object function
void Player::UpdateObject() const
{
dbPositionObject(ObjectNum,xPosition,yPosition,zPosition);
dbRotateObject(ObjectNum,xRotation,yRotation,zRotation);
dbScaleObject(ObjectNum,xScale,yScale,zScale);
}
When adding the dbScaleObject() to the "update object" function the object would disappear although the xScale,yScale,zScale were set to 100.
Commenting out the command would still make the object disappear, and for some reason the xScale,yScale,zScale variables would have to be commented out too, even thought they are only variables and have no effect on the object (i.e. no functions use them). Even wierder uncommenting the variables afterward would make no difference, the object was still there, leaving me to believe it was a memory leak or something to do with the memory locations.
Combinations of commenting out commands give different results, and I can't pinpoint where I'm going wrong. I'm not a
complete noob with C++ and the GDK but I'm still refering to my C++ books to help me, and I just know it's something trivial that I'm doing wrong, so if anyone can help it would be much appreciated:
Player.h:
class Player {
public:
// Constructor function
Player::Player(int num);
~Player();
// Object's Core3D members
void SetObjectNum(int num);
int GetObjectNum() const;
void UpdateObject() const;
// Object vector members (Position)
void xPos(float x);
float xPos() const;
void yPos(float y);
float yPos() const;
void zPos(float z);
float zPos() const;
// Object vector members (Rotation)
void xRot(float x);
float xRot() const;
void yRot(float y);
float yRot() const;
void zRot(float z);
float zRot() const;
// Object vector members (Scale)
void xSize(float x);
float xSize() const;
void ySize(float y);
float ySize() const;
void zSize(float z);
float zSize() const;
private:
int ObjectNum;
// Object vector variables
float xPosition;
float yPosition;
float zPosition;
float xRotation;
float yRotation;
float zRotation;
float xScale;
float yScale;
float zScale;
};
Player.cpp:
#include "Player.h"
#include "DarkGDK.h"
Player::Player(int num)
{
ObjectNum = num;
// Object vector variables
float xPosition = 0;
float yPosition = 0;
float zPosition = 0;
float xRotation = 0;
float yRotation = 0;
float zRotation = 0;
float xScale = 100;
float yScale = 100;
float zScale = 100;
}
Player::~Player(){}
void Player::SetObjectNum(int num) {ObjectNum = num;}
int Player::GetObjectNum() const {return ObjectNum;}
void Player::UpdateObject() const
{
dbPositionObject(ObjectNum,xPosition,yPosition,zPosition);
dbRotateObject(ObjectNum,xRotation,yRotation,zRotation);
dbScaleObject(ObjectNum,xScale,yScale,zScale);
}
// Object vector members (Position)
void Player::xPos(float x) { xPosition = x; }
float Player::xPos() const { return xPosition; }
void Player::yPos(float y) { yPosition = y; }
float Player::yPos() const { return yPosition; }
void Player::zPos(float z) { zPosition = z; }
float Player::zPos() const { return zPosition; }
// Object vector members (Rotation)
void Player::xRot(float x) { xRotation = x; }
float Player::xRot() const { return xRotation; }
void Player::yRot(float y) { yRotation = y; }
float Player::yRot() const { return yRotation; }
void Player::zRot(float z) { zRotation = z; }
float Player::zRot() const { return zRotation; }
// Object vector members (Scale)
void Player::xSize(float x) { xScale = x; }
float Player::xSize() const { return xScale; }
void Player::ySize(float y) { yScale = y; }
float Player::ySize() const { return yScale; }
void Player::zSize(float z) { zScale = z; }
float Player::zSize() const { return zScale; }
Main.cpp:
#include "DarkGDK.h"
#include "Player.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
dbAutoCamOff();
dbPositionCamera(10,10,10);
dbPointCamera(0,0,0);
Player Human(1);
dbMakeObjectCube(Human.GetObjectNum(),2.0);
// our main loop
while ( LoopGDK ( ) )
{
Human.xRot(Human.xRot()+0.1);
Human.yRot(Human.yRot()+0.1);
Human.zRot(Human.zRot()+0.1);
Human.UpdateObject();
// update the screen
dbSync ( );
}
// return back to windows
return;
}
AMD X2 6400+ (3.2GHz) // K9A2 Platinum 790FX Mobo // 2GB Corsair RAM 1066MHz // Powercolor HD4870 512MB OC'ed