Here are some changes that I'd suggest ...
Throughout your Ball class, you access your member variables with Ball::variable - this is only necessary if you have an argument variable of the same name. If you don't then 'Ball::handle' can be shortened to 'handle' for example. I usually add a trailing underscore to the argument names to avoid this ... others will add 'm_' to the member variables.
Also, different code paths initialise the object in slightly different ways - you can get all of your constructors to call a common subroutine to complete initialisation.
#include "Ball.h"
#include "DarkSDK.h"
Ball::Ball()
{
}
Ball::Ball(int handle_)
{
Initialize(handle_, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
}
Ball::Ball(int handle_, float x_, float y_, float z_)
{
Initialize(handle_, x, y, z, 0.0, 0.0, 0.0);
}
Ball::Ball(int handle_, float x_, float y_, float z_, float vx_, float vy_, float vz_)
{
Initialize(handle_, x, y, z, vx_, vy_, vz_);
}
Ball::~Ball()
{
dbDeleteObject(handle);
}
void Ball::Update()
{
dbPositionObject(handle, x, y, z);
x += vx;
y += vy;
z += vz;
if((x > 100.0 && vx > 0.0) || (x < -100.0 && vx < 0.0)) vx *= -1.0;
if((y > 100.0 && vy > 0.0) || (y < -100.0 && vy < 0.0)) vy *= -1.0;
if((z > 100.0 && vz > 0.0) || (z < -100.0 && vz < 0.0)) vz *= -1.0;
}
void Ball::Initialize(int handle_, float x_, float y_, float z_, float vx_, float vy_, float vz_)
{
handle = handle_;
name = "hello world";
size = 10;
x = x_;
y = y_;
z = z_;
vx = vx_;
vy = vy_;
vz = vz_;
dbMakeObjectSphere(handle, size);
dbColorObject(handle, dbRGB(dbRnd(254) + 1, dbRnd(254) + 1, dbRnd(254) + 1));
}
In addition, although it makes no difference to the speed of the code, you probably want to make all of your member variables non-public - it's considered bad style to leave them available for people to bypass your object interface and tread all over them.
Very good for your first try at a C++ class