Results 1 to 7 of 7

Thread: XNA 3D Cube

  1. #1

    XNA 3D Cube

    Hi all, I would like to know if there is some kind of brief tutorial online... thats shos you how to create a 3D cube using chrome for XNA...


    any ideas?

  2. #2

    XNA 3D Cube

    look on google on how to do it on C#

    the code is 90% the same

    ps: im saying that, cuz i think not many of us have experience in XNA
    From brazil (:

    Pascal pownz!

  3. #3

    XNA 3D Cube

    The Search tool is your friend..

    savage made a nice post that you can find here:
    http://www.pascalgamedevelopment.com...&highlight=xna
    [size=9px]BEGIN GEEK CODE BLOCK
    <br />d s-- : a24 GB GCS GTW GE C++ P L+ W++ N+ K- w++++ M- PS+ PE+ Y- t+ 5+++ X+ R*
    <br />tv b+ DI++ D+ e++ h+ G-
    <br />END GEEK CODE BLOCK[/size]
    <br />Create your own GeekCode block at: <a href="">...</a>

  4. #4

    XNA 3D Cube

    Quote Originally Posted by arthurprs
    look on google on how to do it on C#

    the code is 90% the same

    ps: im saying that, cuz i think not many of us have experience in XNA
    hmmm.. seems like the c# code is much different to chrome though. can anyone suggest a good link on how to convert c# code into pas?

  5. #5

    XNA 3D Cube

    [quote="thisverymoment"]
    Quote Originally Posted by arthurprs
    look on google on how to do it on C#

    the code is 90% the same

    ps: im saying that, cuz i think not many of us have experience in XNA
    hmmm.. seems like the c# code is much different to chrome though. can anyone suggest a good ]

    library is the same, namespaces are the same, same .(dot) syntax

    only thing diferent is some operators

    ps: im not sure of all the things, correct me if im wrong
    From brazil (:

    Pascal pownz!

  6. #6

    XNA 3D Cube

    [quote="arthurprs"]
    Quote Originally Posted by thisverymoment
    Quote Originally Posted by arthurprs
    look on google on how to do it on C#

    the code is 90% the same

    ps: im saying that, cuz i think not many of us have experience in XNA
    hmmm.. seems like the c# code is much different to chrome though. can anyone suggest a good ]

    library is the same, namespaces are the same, same .(dot) syntax

    only thing diferent is some operators

    ps: im not sure of all the things, correct me if im wrong

    constructor declaration may be different... also an array declaration, i keep getting errors in the debug though... can i post the code in chrome?

  7. #7

    XNA 3D Cube

    -------------------------------------------------Shape Class------------------------------------------------------



    namespace XNAWinGame2;

    interface

    uses
    Microsoft.Xna.Framework,
    Microsoft.Xna.Framework.Content,
    Microsoft.Xna.Framework.Audio,
    Microsoft.Xna.Framework.Graphics,
    Microsoft.Xna.Framework.Input,
    Microsoft.Xna.Framework.Storage;


    type

    TArrayOfVertexPositionNormalTexture = array of VertexPositionNormalTexture;

    BasicShape = class
    private
    shapeVertices: TArrayOfVertexPositionNormalTexture;
    shapeTriangles: Integer;
    shapeBuffer: VertexBuffer;
    procedure BuildShape;

    protected
    public
    shapeSize: Vector3;
    shapePosition: Vector3;
    shapeTexture: Texture2D;
    method RenderShape(device: GraphicsDevice);

    constructor;


    end;

    implementation


    constructor BasicShape;
    begin
    var
    size,position : Vector3;
    Self.shapeSize := size;
    Self.shapePosition := position;
    end;

    procedure BasicShape.BuildShape;

    var

    textureBottomRight: Vector2;
    textureBottomLeft: Vector2;
    textureTopRight: Vector2;
    textureTopLeft: Vector2;
    rightNormal: Vector3;
    leftNormal: Vector3;
    bottomNormal: Vector3;
    topNormal: Vector3;
    backNormal: Vector3;
    frontNormal: Vector3;
    bottomRightBack: Vector3;
    bottomLeftBack: Vector3;
    topRightBack: Vector3;
    topLeftBack: Vector3;
    bottomRightFront: Vector3;
    topRightFront: Vector3;
    bottomLeftFront: Vector3;
    topLeftFront: Vector3;

    begin
    Self.shapeTriangles := 12;
    Self.shapeVertices := (new TArrayOfVertexPositionNormalTexture, 36);
    topLeftFront := (Self.shapePosition + (new Vector3(-1, 1, -1) * Self.shapeSize));
    bottomLeftFront := (Self.shapePosition + (new Vector3(-1, -1, -1) * Self.shapeSize));
    topRightFront := (Self.shapePosition + (new Vector3(1, 1, -1) * Self.shapeSize));
    bottomRightFront := (Self.shapePosition + (new Vector3(1, -1, -1) * Self.shapeSize));
    topLeftBack := (Self.shapePosition + (new Vector3(-1, 1, 1) * Self.shapeSize));
    topRightBack := (Self.shapePosition + (new Vector3(1, 1, 1) * Self.shapeSize));
    bottomLeftBack := (Self.shapePosition + (new Vector3(-1, -1, 1) * Self.shapeSize));
    bottomRightBack := (Self.shapePosition + (new Vector3(1, -1, 1) * Self.shapeSize));
    frontNormal := (new Vector3(0, 0, 1) * Self.shapeSize);
    backNormal := (new Vector3(0, 0, -1) * Self.shapeSize);
    topNormal := (new Vector3(0, 1, 0) * Self.shapeSize);
    bottomNormal := (new Vector3(0, -1, 0) * Self.shapeSize);
    leftNormal := (new Vector3(-1, 0, 0) * Self.shapeSize);
    rightNormal := (new Vector3(1, 0, 0) * Self.shapeSize);
    textureTopLeft := new Vector2((0.5 * Self.shapeSize.X), (0 * Self.shapeSize.Y));
    textureTopRight := new Vector2((0 * Self.shapeSize.X), (0 * Self.shapeSize.Y));
    textureBottomLeft := new Vector2((0.5 * Self.shapeSize.X), (0.5 * Self.shapeSize.Y));
    textureBottomRight := new Vector2((0 * Self.shapeSize.X), (0.5 * Self.shapeSize.Y));
    Self.shapeVertices[0] := new VertexPositionNormalTexture(topLeftFront, frontNormal,
    textureTopLeft);
    Self.shapeVertices[1] := new VertexPositionNormalTexture(bottomLeftFront,
    frontNormal, textureBottomLeft);
    Self.shapeVertices[2] := new VertexPositionNormalTexture(topRightFront,
    frontNormal, textureTopRight);
    Self.shapeVertices[3] := new VertexPositionNormalTexture(bottomLeftFront,
    frontNormal, textureBottomLeft);
    Self.shapeVertices[4] := new VertexPositionNormalTexture(bottomRightFront,
    frontNormal, textureBottomRight);
    Self.shapeVertices[5] := new VertexPositionNormalTexture(topRightFront,
    frontNormal, textureTopRight);
    Self.shapeVertices[6] := new VertexPositionNormalTexture(topLeftBack, backNormal,
    textureTopRight);
    Self.shapeVertices[7] := new VertexPositionNormalTexture(topRightBack, backNormal,
    textureTopLeft);
    Self.shapeVertices[8] := new VertexPositionNormalTexture(bottomLeftBack,
    backNormal, textureBottomRight);
    Self.shapeVertices[9] := new VertexPositionNormalTexture(bottomLeftBack,
    backNormal, textureBottomRight);
    Self.shapeVertices[10] := new VertexPositionNormalTexture(topRightBack,
    backNormal, textureTopLeft);
    Self.shapeVertices[11] := new VertexPositionNormalTexture(bottomRightBack,
    backNormal, textureBottomLeft);
    Self.shapeVertices[12] := new VertexPositionNormalTexture(topLeftFront,
    topNormal, textureBottomLeft);
    Self.shapeVertices[13] := new VertexPositionNormalTexture(topRightBack,
    topNormal, textureTopRight);
    Self.shapeVertices[14] := new VertexPositionNormalTexture(topLeftBack, topNormal,
    textureTopLeft);
    Self.shapeVertices[15] := new VertexPositionNormalTexture(topLeftFront,
    topNormal, textureBottomLeft);
    Self.shapeVertices[16] := new VertexPositionNormalTexture(topRightFront,
    topNormal, textureBottomRight);
    Self.shapeVertices[17] := new VertexPositionNormalTexture(topRightBack,
    topNormal, textureTopRight);
    Self.shapeVertices[18] := new VertexPositionNormalTexture(bottomLeftFront,
    bottomNormal, textureTopLeft);
    Self.shapeVertices[19] := new VertexPositionNormalTexture(bottomLeftBack,
    bottomNormal, textureBottomLeft);
    Self.shapeVertices[20] := new VertexPositionNormalTexture(bottomRightBack,
    bottomNormal, textureBottomRight);
    Self.shapeVertices[21] := new VertexPositionNormalTexture(bottomLeftFront,
    bottomNormal, textureTopLeft);
    Self.shapeVertices[22] := new VertexPositionNormalTexture(bottomRightBack,
    bottomNormal, textureBottomRight);
    Self.shapeVertices[23] := new VertexPositionNormalTexture(bottomRightFront,
    bottomNormal, textureTopRight);
    Self.shapeVertices[24] := new VertexPositionNormalTexture(topLeftFront,
    leftNormal, textureTopRight);
    Self.shapeVertices[25] := new VertexPositionNormalTexture(bottomLeftBack,
    leftNormal, textureBottomLeft);
    Self.shapeVertices[26] := new VertexPositionNormalTexture(bottomLeftFront,
    leftNormal, textureBottomRight);
    Self.shapeVertices[27] := new VertexPositionNormalTexture(topLeftBack, leftNormal,
    textureTopLeft);
    Self.shapeVertices[28] := new VertexPositionNormalTexture(bottomLeftBack,
    leftNormal, textureBottomLeft);
    Self.shapeVertices[29] := new VertexPositionNormalTexture(topLeftFront,
    leftNormal, textureTopRight);
    Self.shapeVertices[30] := new VertexPositionNormalTexture(topRightFront,
    rightNormal, textureTopLeft);
    Self.shapeVertices[31] := new VertexPositionNormalTexture(bottomRightFront,
    rightNormal, textureBottomLeft);
    Self.shapeVertices[32] := new VertexPositionNormalTexture(bottomRightBack,
    rightNormal, textureBottomRight);
    Self.shapeVertices[33] := new VertexPositionNormalTexture(topRightBack,
    rightNormal, textureTopRight);
    Self.shapeVertices[34] := new VertexPositionNormalTexture(topRightFront,
    rightNormal, textureTopLeft);
    Self.shapeVertices[35] := new VertexPositionNormalTexture(bottomRightBack,
    rightNormal, textureBottomRight);
    end;

    method BasicShape.RenderShape(device: GraphicsDevice);
    begin
    BuildShape;
    Self.shapeBuffer := new VertexBuffer(device, (VertexPositionNormalTexture.SizeInBytes * (Self.shapeVertices.Length)), BufferUsage.WriteOnly);
    Self.shapeBuffer.SetData(Self.shapeVertices);
    device.Vertices[0].SetSource(Self.shapeBuffer, 0, VertexPositionNormalTexture.SizeInBytes);
    device.VertexDeclaration := new VertexDeclaration(device, VertexPositionNormalTexture.VertexElements);
    device.DrawPrimitives(PrimitiveType.TriangleList, 0, Self.shapeTriangles);
    end;

    end.


    ------------------------------------------------------------------Game Class-------------------------------------------------------------------------------

    namespace XNAWinGame2;

    interface

    uses
    Microsoft.Xna.Framework,
    Microsoft.Xna.Framework.Content,
    Microsoft.Xna.Framework.Audio,
    Microsoft.Xna.Framework.Graphics,
    Microsoft.Xna.Framework.Input,
    Microsoft.Xna.Framework.Storage;

    type
    TXNAWinGame2 = class( Microsoft.Xna.Framework.Game )
    private
    // these are the size of the output window, ignored on Xbox 360
    preferredWindowWidth : integer;
    preferredWindowHeight : integer;

    graphics : GraphicsDeviceManager;
    spriteBatch priteBatch;
    worldMatrix : Matrix;
    cameraMatrix : Matrix;
    projectionMatrix: Matrix;
    angle : System.Single;
    cubeEffect : BasicEffect;
    content : ContentManager;
    protected
    method Initialize; override;
    method Update( aGameTime : Gametime ); override;
    method Draw( aGameTime : Gametime ); override;
    method LoadGraphicsContent( loadAllContent : boolean ); override;
    method UnloadGraphicsContent( unloadAllContent : boolean ); override;

    method UpdateInput( aGameTime : Gametime );
    public
    method initializeworld;
    constructor;
    end;

    implementation

    constructor TXNAWinGame2;
    begin
    inherited;
    preferredWindowWidth := 853;
    preferredWindowHeight := 480;

    Self.graphics := new Microsoft.Xna.Framework.GraphicsDeviceManager( Self );

    Self.graphics.PreferredBackBufferWidth := preferredWindowWidth;
    Self.graphics.PreferredBackBufferHeight := preferredWindowHeight;

    content := new ContentManager( Services );
    end;

    method TXNAWinGame2.Draw( aGameTime : Gametime );
    begin
    // Clear the device to the colour of your choosing
    graphics.GraphicsDevice.Clear( Color.Black );

    // Your Draw Code here.

    inherited Draw( aGameTime );
    end;

    method TXNAWinGame2.initializeWorld;
    var
    tilt: System.Single;
    begin
    Self.cameraMatrix := Matrix.CreateLookAt(new Vector3(0, 30, 20), new Vector3(0,
    0, 0), new Vector3(0, 1, 0));
    Self.projectionMatrix := Matrix.CreatePerspectiveFieldOfView(MathHelper.PiO ver4,
    (Window.ClientBounds.Width / Window.ClientBounds.Height), 1, 50);
    tilt := MathHelper.ToRadians(22.5);
    Self.worldMatrix := (Matrix.CreateRotationX(tilt) * Matrix.CreateRotationY(tilt));
    Self.cubeEffect := new BasicEffect(GraphicsDevice, nil);
    Self.cubeEffect.World := Self.worldMatrix;
    Self.cubeEffect.View := Self.cameraMatrix;
    Self.cubeEffect.Projection := Self.projectionMatrix;
    Self.cubeEffect.TextureEnabled := True;
    end;

    method TXNAWinGame2.Initialize;
    begin
    // Your Initialize Code here

    inherited;
    end;


    method TXNAWinGame2.LoadGraphicsContent( loadAllContent : boolean );
    begin
    if ( loadAllContent ) then
    begin
    // TODO: Load any ResourceManagementMode.Automatic content

    end;

    // TODO: Load any ResourceManagementMode.Manual content
    end;

    method TXNAWinGame2.UnloadGraphicsContent( unloadAllContent : boolean );
    begin
    if ( unloadAllContent ) then
    begin
    content.Unload;
    end;
    end;

    method TXNAWinGame2.Update( aGameTime : Gametime );
    begin
    //Get some input
    UpdateInput( aGameTime);

    // Your Update Code here

    inherited Update( aGameTime);
    end;

    method TXNAWinGame2.UpdateInput( aGameTime : Gametime );
    var
    currentGamePadState : GamePadState;
    currentKeyboardState : KeyboardState;
    begin
    //get the gamepad state
    currentGamePadState := GamePad.GetState( PlayerIndex.One );

    currentKeyboardState := Keyboard.GetState();

    if ( ( currentGamePadState.IsConnected ) or ( currentKeyboardState <> nil ) ) then
    begin
    // Allows the default game to exit on Xbox 360 and Windows using a Gamepad
    if ( currentGamePadState.Buttons.Back = ButtonState.Pressed ) then
    Self.Exit;

    // Allows the default game to exit on Xbox 360 and Windows using a Keyboard
    if ( ( currentKeyboardState <> nil ) and ( currentKeyboardState.IsKeyDown( Keys.Escape ) ) ) then
    Self.Exit;
    end;
    end;

    end.



    Getting Errors(3):


    Error 2 (PE174) There is no overloaded constructor with these parameters for class "Microsoft.Xna.Framework.Graphics.BasicEffect" C:\Users\Tom\Documents\Visual Studio 2005\Projects\XNAWinGame2\XNAWinGame2\Game.pas 77 37 XNAWinGame2

    Error 4 (PE174) There is no overloaded constructor with 0 parameters for class "array of Microsoft.Xna.Framework.Graphics.VertexPositionNor malTexture" C:\Users\Tom\Documents\Visual Studio 2005\Projects\XNAWinGame2\XNAWinGame2\Shape1.pas 73 65 XNAWinGame2

    Error 5 (CE16) Operator "*" cannot be applied to operands of type "<untyped>" and "System.Int32" C:\Users\Tom\Documents\Visual Studio 2005\Projects\XNAWinGame2\XNAWinGame2\Shape1.pas 169 118 XNAWinGame2

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
  •