-
Physics Engine Problem
I'm trying to make my own basic physics engine, featuring gravity, collision detection, and hopefully some ragdoll. This engine is made in directX 9 in case you didn't notice.
My problem is with the gravity function.
The function is called every millesecond from a timer.
Here is what it looks like:
Code:
void Phy_Gravity(LPDIRECT3DRMFRAME frScene, LPDIRECT3DRMFRAME Camera){
LPDIRECT3DRMFRAMEARRAY SceneArray;
FrameStruct frFrame;
D3DVECTOR vectPos;
int ArraySize;
frScene->GetChildren(&SceneArray);
ArraySize = SceneArray->GetSize();
for (int i = 0; i < ArraySize; i++){
SceneArray->GetElement(i, &frFrame.frFrame);
frFrame.frFrame->GetPosition(frScene, &vectPos);
if (frFrame.frFrame != Camera){
frFrame.frFrame->SetVelocity(frScene, 0, -frFrame.Weight, 0, false);
}
}
}
FrameStruct is a struct with three variables:
Code:
LPDIRECT3DRMFRAME frFrame
int Weight
int Bounce
You'll notice that if the frame being pulled is not the camera, then I want the object to go down on the y axis according to its own weight, which I defined when I created the frame.
I set the weight of the cube to 0.1, but I tried debugging and it shows me the weight as being -8.blah blah blah which is way to fast.
I think the problem is that the function does not get the weight variable when I do this:
Code:
SceneArray->GetElement(i, &frFrame.frFrame);
So it guesses the weight and puts it to a huge number, like -8.
How do I get my function to be able to use the weight variable?
-
Could we see the GetElement() function?
Also, try putting frFrame.frFrame inside brackets:
...&(frFrame.frFrame)...
-
use floating point for everything that has to do with the equations of motion, including weight. Also review your basic physics, i.e, the weight doesn't change the acceleration of the object.
-
GetElement is just a function included with the SDK, I have no idea where to find the code.
And as for the basic physics, I don't won't to go thorugh with anything too complicated, I think just using weight is realistic enough.
-
Yes but a weight is actually a force, which is the mass times acceleration of the object. The acceleration of the object does not depend on its weight, it's more appropriate to simply store the mass, but I understand where you are coming from, and in general it's a good idea to keep things simple when starting on a paradigm of programming new to you.