Thread: Physics Engine Problem

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    33

    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?

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    Could we see the GetElement() function?

    Also, try putting frFrame.frFrame inside brackets:
    ...&(frFrame.frFrame)...
    Pentium 4 - 2.0GHz, 512MB RAM
    NVIDIA GeForce4 MX 440
    WinXP
    Visual Studio .Net 2003
    DX9 October 2004 Update (R.I.P. VC++ 6.0 Compatability)

  3. #3

    Join Date
    May 2005
    Posts
    1,042
    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.
    I'm not immature, I'm refined in the opposite direction.

  4. #4
    Registered User
    Join Date
    Jul 2005
    Posts
    33
    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.

  5. #5

    Join Date
    May 2005
    Posts
    1,042
    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.
    I'm not immature, I'm refined in the opposite direction.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure to store unlimited dynamic vectors
    By m3rk in forum C++ Programming
    Replies: 8
    Last Post: 04-22-2009, 06:12 AM
  2. Problem with Vectors And Pointers
    By Shamino in forum Game Programming
    Replies: 3
    Last Post: 01-21-2006, 07:23 PM
  3. Weird problem on '02 3.4L V6 auto
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 01-12-2006, 12:05 AM
  4. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  5. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM