Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: 2d Overhead + Newton

  1. #1

    2d Overhead + Newton

    hi, i've been having alot of problems trying to get Newton to work full stop, not to mension i'd like it to be used for 2d physics....

    i guess i am doing something wrong. hope someone can help.

    on engine load.

    [pascal]
    var
    min,max : Single;
    begin
    NewtonWorld := NewtonCreate(nil, nil);

    min := -25000;
    max := 25000;
    NewtonSetWorldSize(NewtonWorld, @min, @max); //temp until i finish the map loader.
    NewtonSetSolverModel(NewtonWorld, 0);
    [/pascal]


    i then load x amount of `civilians`

    [pascal]
    New(civ);
    civ.Initialise(NewtonWorld, @SpriteEngine);
    [/pascal]

    which is as follows:

    [pascal]
    procedure TAICivilian.Initialise(newtonW: PNewtonWorld; se: PCoSpriteEngine);
    var
    Inertia : TCoVector3;
    Value : TCoVector3;
    Force : TCoVector3;

    Collision: PNewtonCollision;
    begin
    Sprite := se.NewSprite('.\aiciv.PNG', 512, 64);
    Sprite.X := 512;
    Sprite.Y := 360;
    Mass := 1;

    Collision := NewtonCreateBox(newtonW, 64, 64, 64, nil); //temp
    Sprite.NewtonBody := NewtonCreateBody(newtonW, Collision);
    NewtonReleaseCollision(newtonW, Collision);

    //all temp values until i get newton working.
    Inertia.x := Mass * (64 * 64 + 64 * 64) / 12;
    Inertia.y := Mass * (64 * 64 + 64 * 64) / 12;
    Inertia.z := Mass * (64 * 64 + 64 * 64) / 12;
    NewtonBodySetMassMatrix(Sprite.NewtonBody, Mass, Inertia.x, Inertia.y, Inertia.z);

    F_Matrix[3,0] := Sprite.X;
    F_Matrix[3,1] := Sprite.Y;
    F_Matrix[3,2] := 0;
    NewtonBodySetMatrix(Sprite.NewtonBody, @F_Matrix[0,0]);
    NewtonBodySetForceAndTorqueCallback(Sprite.NewtonB ody, ForceAndTorqueCallback);
    end;
    [/pascal]


    on each frame i call to move the civilians

    [pascal]
    procedure TAICivilian.Move(delta: Double);
    var
    matWorld: TCoMatrix;
    begin
    NewtonBodyGetMatrix(Sprite.NewtonBody, @matWorld[0,0]);
    Sprite.X := matWorld[3,0];
    Sprite.Y := matWorld[3,1];
    [/pascal]

    after move is called they are then drawn

    [pascal]
    procedure TCoSprite.Draw(Dev: IDirect3DDevice9);
    var
    rcSource: TRect;
    vPosition: TD3DXVector2;
    begin
    rcSource.Left := (F_CurFrame * F_Width)-64;
    rcSource.Right := F_CurFrame * F_Width;

    rcSource.Top := F_TextureY;
    rcSource.Bottom := F_Height;

    with vPosition do begin
    x := F_X;
    y := F_Y;
    end;

    F_Sprite._Begin(D3DXSPRITE_ALPHABLEND);
    F_Sprite.Draw( F_Texture, @rcSource, nil, @vPosition, $f0f0f0f0 );
    F_Sprite._End;
    end;
    [/pascal]

    and finally, at the end of frame NewtonUpdate is called... and so... nothing happens, sprites do not move at all. and i've been trying alsorts of things to get it to work.


    -Colin
    Download the Ziron Assembler
    Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.

  2. #2

    Re: 2d Overhead + Newton

    What do you expect? I see nothing in your code that should make your civilians move.

    I'm just learning Newton myself, and I see that you have correctly setup the world and added collision and body's. Then, you register a few callbacks and wait for something to happen. Nothing happens by itsself though. You need to apply forces on objects to make them move.

    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  3. #3

    Re: 2d Overhead + Newton

    yes i apply forces via the ForceAndTorque callback, in my case the characters should fall somewhere.... (as a test)

    [pascal]
    procedure ForceAndTorqueCallback(const body : PNewtonBody); cdecl;
    var
    Mass : Single;
    Inertia : TCoVector3;
    Force : TCoVector3;
    begin
    NewtonBodyGetMassMatrix(Body, @Mass, @Inertia.x, @Inertia.y, @Inertia.z);
    with Force do begin
    X := -6;
    Y := -6 * Mass;
    Z := -6;
    end;
    NewtonBodySetForce(Body, @Force.x);
    end;
    [/pascal]
    Download the Ziron Assembler
    Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.

  4. #4
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Re: 2d Overhead + Newton

    try this:
    - NewtonWorldUnfreezeBody
    if that doesn't work try these:
    - NewtonBodySetFreezeTreshold
    - NewtonBodySetAutoFreeze

    (reference: http://www.newtondynamics.com/wiki/i...ctions_in_1.35)
    NecroSOFT - End of line -

  5. #5

    Re: 2d Overhead + Newton

    hi NecroDOME thanks but unfortunatly these neither work.
    Download the Ziron Assembler
    Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.

  6. #6

    Re: 2d Overhead + Newton

    Have you been playing with any newton samples? did they work?

    Try to find the differences between your code and any sample code. That should lead you to the sollution. It might also be a good idea to keep toying around with those numbers. Maybe your masses are too big or your forces too small.

    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  7. #7

    Re: 2d Overhead + Newton

    yes i have been doing that

    i have solved my problem finally... it just happens that the sample i was using as a reference did not work neither lol the world size were as singles, after spending a while looking through the Newton Wiki (good resource)......

    [pascal]
    with min do begin
    x := -500;
    y := -500;
    z := -500;
    end;
    with max do begin
    x := 500;
    y := 500;
    z := 500;
    end;

    NewtonSetWorldSize(NewtonWorld, @min, @max);
    [/pascal]

    my problem was (stupid), thanks for your replies.

    my only problem now is keeping the characters on a 2d plane, i have no idea how todo that with Newton, i've been searching google for the past hour.

    -Colin
    Download the Ziron Assembler
    Get free hosting for Ziron related fan-sites and Ziron projects, contact me in private message.

  8. #8
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Re: 2d Overhead + Newton

    yeah well, since newton is a 3D collision solver you have to do some manual steps.

    I never done it, but here are some suggestions:
    - Make 2 huge invisible wall's (cubes would do the trick) and put them to the side of your game so nothing can fall off.
    - Every move-frame set the Z to zero.
    NecroSOFT - End of line -

  9. #9

    Re: 2d Overhead + Newton

    You just quoted min/max use before, can you set Z to 0 for both min and max there?

  10. #10
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Re: 2d Overhead + Newton

    If a body goes outside of the newton boundary, it just stops. So that's not gonna work.
    NecroSOFT - End of line -

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •