Page 4 of 7 FirstFirst ... 23456 ... LastLast
Results 31 to 40 of 67

Thread: Pascal and XNA...

  1. #31

    Pascal and XNA...

    One thing that Nitschke wrote was that you shouldn't use foreach contruct when developing in C# as it is really slow due to an error in the XBox 360 Garbage Collector. Instead of the Draw routine that was previously posted, should probably use something like this...

    [pascal]
    method TTutorial3.Draw( gameTime : Gametime );
    var
    transforms : array of Matrix;
    mesh : ModelMesh;
    effect : BasicEffect;
    i, x : integer;
    begin
    graphics.GraphicsDevice.Clear( Color.CornflowerBlue );

    //Copy any parent transforms
    transforms := new Matrix[ myModel.Bones.Count ];
    myModel.CopyAbsoluteBoneTransformsTo( transforms );

    //Draw the model, a model can have multiple meshes, so loop
    // use normal for loop rather than for each as it is faster.
    for i := 0 to myModel.Meshes.Count - 1 do
    begin
    mesh := myModel.Meshes[ i ];
    //This is where the mesh orientation is set, as well as our camera and projection
    for x := 0 to mesh.Effects.Count - 1 do
    begin
    effect := BasicEffect( mesh.Effects[ x ] );
    effect.EnableDefaultLighting;
    effect.World := transforms[ mesh.ParentBone.Index ] * Matrix.CreateRotationY( modelRotation ) * Matrix.CreateTranslation( modelPosition );
    effect.View := Matrix.CreateLookAt( cameraPosition, Vector3.Zero, Vector3.Up );
    effect.Projection := Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians( 45.0 ), aspectRatio, 1.0, 10000.0 );
    end;

    //Draw the mesh, will use the effects set above.
    mesh.Draw( );
    end;

    inherited Draw( gameTime );
    end;
    [/pascal]
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  2. #32

    Pascal and XNA...



    Hi Guys, I've uploaded another example of Chrome with XNA, this time it's a 3D WWI ( I think ) animated tank. It is based on a sample from http://creators.xna.com.

    You can download the current demo from
    http://www.pascalgamedevelopment.com...eAnimation.zip ( about 23MB due to large textures and the crappy content pipeline format ), and if you have XNA runtimes installed it includes an exe for you to see it in action.

    I have taken the aforementioned sample and enhanced it slightly with the following capabilities :
    * Left and Right arrows turn the steering left and right.
    * Up and Down arrows give the tank velocity and move it ( not working correctly ).
    * Moving the mouse Left and Right rotates the turret 360 degrees
    * Moving the mouse Forward and Backwards raises and lowers the Turret.

    It is while working with this sort of 3D stuff that make me feel inadequate. I really need to sort out my lack of knowledge of 3D maths with regard to rotations and transformations.

    For example I would like allow the user to drive the tank around, but I don't know how to work out the correct model rotation and position based on the steering angle and the velocity of the model.

    If anyone can point out how I can do this in simple child like maths terms, that would be great.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

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

    Pascal and XNA...

    Use a physics engine?
    NecroSOFT - End of line -

  4. #34

    Pascal and XNA...

    Could do, but I want to understand it first. I did that sort of thing with ODE, but didn't really understand what was going on in the back ground.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  5. #35

    Pascal and XNA...

    I don't know if I understand everything right...

    But basically in TANX I did those kind of calculations by just having some values for speed, angle, turretangle, position etc. Nearly all calculations are done in 2D in Tanx, because I had a plain terrain there. Only when things exploded, the Z-value came into calculation for position (things flying to camera).

    So, when pressing left/right keys you should alter angle. When moving the mouse left/right you should alter turretangle. Pressing up/down would alter speed (velocity).

    Thats all you need in the first place.

    Calculation of new position would be something like this:

    Pos.x := Pos.x + sin(angle) * speed;
    Pos.y := Pos.y + cos(angle) * speed;

    Thats all to move the tank.

    rotation of you model is given by angle, too.
    rotation of your turret is given by angle+turretangle, because you want the turret to move too when you turn the tank, don't you?

    Then when rendering the model its just something like this:

    ClearWorldMatrix;
    RotateWorldY(tank.angle);
    TranslateWorld(tank.x,tank.y,tank.z);
    DrawTankCorpse;

    ClearWorldMatrix;
    RotateWorldY(tank.angle+tank.turretangle);
    TranslateWorld(tank.x,tank.y,tank.z);
    DrawTankTurret;

    All this is written out of my head in PseudoCode. I did not test anything, but basically this should enable you to turn and move your tank.

    Hope that helps. If there are further questions... you know where to find me
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

  6. #36

    Pascal and XNA...

    Hi Dirk,
    Thanks for the explanation. That makes sense a tank on tracks, but would that work for a tank that steers more like a car? Could I not need something like a turning circle in this case?
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  7. #37

    Pascal and XNA...

    yes, this should work, because you multiply with the speed. so is the tank is not moving, its position will not change. only thing you should multiply with speed too is the angle you add when rotating. so no movement no rotation.
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

  8. #38

    Pascal and XNA...

    Great!!

    Is the "animation" already controlled by your manual input?
    <a href="http://www.greatgamesexperiment.com/game/Valgard/?utm_source=gge&amp;utm_medium=badge_game"><img border="0" alt="GGE" title="GGE" src="http://static.greatgamesexperiment.com/badge/game/valgard/gge400x56.png"></a>

  9. #39
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Pascal and XNA...

    <object width="640" height="480"><param name="movie" value="http://www.youtube.com/v/CG-n0alspek"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/CG-n0alspek" type="application/x-shockwave-flash" wmode="transparent" width="640" height="480"></embed></object>
    Jason McMillen
    Pascal Game Development
    Co-Founder





  10. #40

    Pascal and XNA...

    Thanks WILL! Pity the Pascal code is not very visible. I'm going to post a link on the MSDN forums and see what they say.

    @Huehnerschaender : Turret and Cannon movement is mouse controlled, steering is keyboard controlled. Wheels are rotating arbitrarily.
    I still need to add the steering code you mentioned earlier. This video was taken before you answered by question.
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

Page 4 of 7 FirstFirst ... 23456 ... 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
  •