int VehicleBase,WheelModel;
class wheel
{
public:
vertex3f Pos;
float Radius,Rotation,DistanceToGround,SpringForce,SpringLength,CurrentPress;
wheel()
{
Radius = Rotation =
DistanceToGround = SpringForce =
SpringLength =CurrentPress = 0;
};
~wheel();
void Update()
{
Pos.y = GetGravity(Pos,Radius);
}
};
class baseobject
{
public:
vertex3f Pos;
int UniqueID;
virtual void Draw()=0;
virtual void Update()=0;
virtual void Init()=0;
baseobject() {};
~baseobject() {};
};
baseobject* Vehicle[MAX_NR_VEHICLES];
class Vehicle_FourWheel : public baseobject
{
public:
wheel *Wheel[4];
Vehicle_FourWheel(float radius,float springforce,float springlength)
{
for (int i=0; i < 4;i++)
{
Wheel = new wheel();
Wheel->Radius = radius;
Wheel->SpringForce = springforce;
Wheel->SpringLength = springlength;
}
};
~Vehicle_FourWheel()
{
for (int i=0; i < 4;i++)
delete Wheel;
};
void Draw()
{
//Draw stuff...
}
void Init()
{
//Set wheel positions...
}
virtual void Update()
{
for (int i=0; i < 4; i++)
{
Wheel->Update();
}
Pos.y = Lerp(Wheel[0]->Pos.y,Wheel[2]->Pos.y,0.5)+Wheel[0]->Radius;
};
};
bool NewVehicle(int NrOfWheels,float WheelRadius,float SpringForce,float SpringLength,vertex3f pos)
{
if (TOTAL_NR_VEHICLES < MAX_NR_VEHICLES)
{
TOTAL_NR_VEHICLES++;
Vehicle[TOTAL_NR_VEHICLES] = new Vehicle_FourWheel(WheelRadius,SpringForce,SpringLength);
Vehicle[TOTAL_NR_VEHICLES]->Pos = pos;
Vehicle[TOTAL_NR_VEHICLES]->UniqueID = UNIQUE_ID4++;
Vehicle[TOTAL_NR_VEHICLES]->Init();
return true;
}
else
return false;
}
void DrawVehicles()
{
glBindTexture(GL_TEXTURE_2D,textures[5].texID);
for (int i=0; i < TOTAL_NR_VEHICLES;i++)
if (Vehicle != NULL)
{
Vehicle->Update();
Vehicle->Draw();
}
}
class issues... [SOLVED]
I'm having rather big and weird problems with classes... they're probably just memory allocation (or something similar) errors...
I'm giving a go at virtual functions, but since I have almost no knowledge of classes (I've only been using structs until just recently) I cant figure out this particular problem...
If I spawn a car using the NewVehicle(..) function, it works fine...
but when I have spawned a greater number of cars, be it 13-14 or a hundred, it says: "Project Main.exe raised exception class EOverflow with message: 'Floating point overflow' "
Could anyone please help me with these whole pointer thing... I guess it's something with the copying of data to the vehicle, because if I manually type-in the coordinates in NewVehicle() instead of supplying them into the function, there seem to be no errors... :/
Or if someone has a good tutorial on classes, maybe that will suffice.... :)
Cheers!
[Edited by - Rasmadrak on August 30, 2005 4:23:51 AM]
Floating point overflow isn't a class related problem, it means one of the floating point operations you're doing produces a value too large to be stored in the result. What compiler/OS are you using (is this C# not C++?). I don't recognise EOverflow and I thought most of the time these errors were silent (and +/-INFINITY was returned). I could be wrong I don't think I've ever overflowed my FP numbers.
Yeah, that's why I'm baffled... :D
Anyway, it seems that it's not a problem with the vehicle class at all, if I fire off an effect or create a unit on the game area, it works as intended...
But why...? :/
These are the only classes I've got in my game, maybe I'm creating them wrong?
UPDATE:
I tried creating them without using virtual functions, and it works fine... better go read up a lot better on polymorphism... :/
Anyway, it seems that it's not a problem with the vehicle class at all, if I fire off an effect or create a unit on the game area, it works as intended...
But why...? :/
These are the only classes I've got in my game, maybe I'm creating them wrong?
UPDATE:
I tried creating them without using virtual functions, and it works fine... better go read up a lot better on polymorphism... :/
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement