N3xtD - Free 3D engine

Started by Brice Manuel, August 25, 2011, 06:40:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Peter Weis



' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample 050   as   load simples MD2 animation and set
'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN
    ' Dimes
    DIM app AS DWORD
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app = %NULL THEN
        EXIT FUNCTION
    END IF

    ChangeWorkingDirectory("media/animations")

    '---------------------------------------------------
    ' Load an 3D Object
    DIM obj1 AS AnimatedMesh
    obj1 = LoadAnimatedMesh("sydney.md2")

    DIM obj2 AS AnimatedMesh
    obj2 = LoadAnimatedMesh("sydney.md2")

    DIM obj3 AS AnimatedMesh
    obj3 = LoadAnimatedMesh("vieux.md2")



    '---------------------------------------------------
    'sidney standby: method one
    '---------------------------------------------------
    DIM md2 AS AnimatedNode
    md2 = CreateAnimation(obj1, %NULL)

    LoadTextureNode( md2, "sydney.bmp", 0, 0)

    AnimationMD2(md2, %MD2_ANIM_SEQUENCES.EMAT_STAND )
    SpeedAnimation(md2, 36)
    PositionNode(md2, 0,0,0)

    '---------------------------------------------------
    'sidney run: alternate method, same result
    '---------------------------------------------------
    DIM md2_2 AS AnimatedNode
    md2_2 = CreateAnimation(obj2, %NULL)

    LoadTextureNode( md2_2, "sydney.bmp", 0, 0)

    DIM outBegin AS LONG, outEnd AS LONG, outFPS AS LONG

    MD2FrameLoopType(md2_2, %MD2_ANIM_SEQUENCES.EMAT_STAND , BYVAL VARPTR(outBegin), BYVAL VARPTR(outEnd), BYVAL VARPTR(outFPS))
    SpeedAnimation(md2_2, outFPS)
    FrameLoopAnimation(md2_2,  outBegin, outEnd)
    PositionNode(md2_2, -50,0,0)

    '---------------------------------------------------
    ' "vieux": all frames
    '---------------------------------------------------
    DIM md2_3 AS AnimatedNode
    md2_3 = CreateAnimation(obj3, %NULL)

    SpeedAnimation(md2_3, 35)
    FrameLoopAnimation(md2_3,  0, 496)
    LoadTextureNode( md2_3, "vieux.tga", 0, 0)
    PositionNode(md2_3, 50,0,0)
    '---------------------------------------------------



    '---------------------------------------------------
    ' Create a camera
    DIM cam AS CameraNode
    cam = CreateCamera(%NULL)
    PositionNode(cam, 20,0,-80)


    '-----------------------------------
    ' Load font png
    LoadFont("../courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
    DIM font_ AS IGUIFont
    font_ = GetFont()



    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF


        ' ---------------
        '      Render
        ' ---------------
        BeginScene(90, 90, 90, 255, 1, 1)
        DrawScene()
        NX3_DrawText(font_, "FrameNumber of second 'vieux' as  "+ TRIM$(STR$(AnimationFrameNumber(md2_2))),  10,10,0,0, &h0ff00ffff)
        EndScene()

    WEND
    ' end
    FreeEngine()
END FUNCTION
  •  

Peter Weis


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample 052  :  load simples B3D animation and set,
'                  with shadows
'     29/03/09  19:16    TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN

    ' Dimes
    DIM app AS DWORD
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)

    IF app = %NULL THEN
        EXIT FUNCTION
    END IF

    ChangeWorkingDirectory("media/animations")



    '----------------------------------------
    ' Load an 3D Object
    DIM obj1 AS AnimatedMesh
    obj1 = LoadAnimatedMesh("ninja.b3d")

    DIM obj2 AS AnimatedMesh
    obj2 = LoadAnimatedMesh("dwarf.b3d")

    DIM obj3 AS Mesh
    obj3 = LoadMesh("../plane.3ds", %HARDMAPPING.EHM_STATIC)

    DIM obj4 AS AnimatedMesh
    obj4 = LoadAnimatedMesh("../woodcrate.3ds")


    '----------------------------------------
    ' Create traditional light And set position
    DIM light AS LightNode
    light = CreateLight(&h0ffaaaaaa, 500, %ELT_POINT , %NULL)

    PositionNode(light, 20,30,-30)
    '----------------------------------------


    '-----------------------------------------
    ' Create plane
    DIM plane AS EntityNode
    plane =  CreateEntityNode(obj3, 0, 0, 0, %NULL)

    ScaleNode(plane, 1.5,1.5,1.5)
    PositionNode(plane, 0,-1.5,0)
    '----------------------------------------



    '--------------------------------------
    ' Create cube
    DIM cube AS EntityNode
    cube = CreateAnimation(obj4, %NULL)

    ScaleNode(cube, 0.02,0.02,0.02)
    PositionNode(cube,0,-1,0)
    ShadowVolumeEntity(cube, %True, 10000.0)


    '--------------------------------------
    ' Create first animation B3D
    DIM ninja AS AnimatedNode
    ninja = CreateAnimation(obj1, %NULL)
    SpeedAnimation(ninja, 10)
    RotateNode(ninja, 0,180,0)
    FrameLoopAnimation(ninja,  1, 14)
    ShadowVolumeAnimation(ninja, %True, 10000.0)

    ' edit number total of the Joint inside the animation
    'Debug _AnimationJointCount(ninja)
    ' affect on the joint nuber 18 the arrow
    DIM bone AS BoneNode
    bone = AnimationJointNode(ninja, 18)
    AddChildNode(bone, cube)





    '--------------------------------------
    ' Create second animation B3D
    DIM dwarf AS AnimatedNode
    dwarf = CreateAnimation(obj2, %NULL)
    SpeedAnimation(dwarf, 8)
    Scalenode(dwarf, 0.12,0.12,0.12)
    RotateNode(dwarf, 0,180,0)
    PositionNode(dwarf, -10,0,10)
    ShadowVolumeAnimation(dwarf, %True, 10000.0)



    '_ShadowColor( &h96000000)




    '-----------------------------------
    ' Create a camera
    DIM cam AS CameraNode
    cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
    PositionNode(cam, 0,10,-13)



    '-----------------------------------
    ' Load font png
    LoadFont("../font2.bmp", %FONT_TYPE.EGDF_DEFAULT)
    DIM pbfont AS IGUIFont
    pbfont = GetFont()


    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF

        ' Select sequence
        IF GetKeyUp(%KEY_CODE.KEY_F1) THEN
            IF GetKeyDown(%KEY_CODE.KEY_CONTROL) THEN
                FrameLoopAnimation(ninja,  134, 145)
            ELSE
                FrameLoopAnimation(ninja,  1, 14)
            END IF
        END IF

        IF GetKeyUp(%KEY_CODE.KEY_F2) THEN
            IF GetKeyDown(%KEY_CODE.KEY_CONTROL) THEN
                FrameLoopAnimation(ninja,  146, 158)
            ELSE
                FrameLoopAnimation(ninja,  15, 30)
            END IF
        END IF

        IF GetKeyUp(%KEY_CODE.KEY_F3) THEN
            IF GetKeyDown(%KEY_CODE.KEY_CONTROL) THEN
                FrameLoopAnimation(ninja,  159,165)
            ELSE
                FrameLoopAnimation(ninja,  32, 44)
            END IF
        END IF

        IF GetKeyUp(%KEY_CODE.KEY_F4) THEN
            IF GetKeyDown(%KEY_CODE.KEY_CONTROL) THEN
                FrameLoopAnimation(ninja,  166,173)
            ELSE
                FrameLoopAnimation(ninja,  45, 59)
            END IF
        END IF

        IF GetKeyUp(%KEY_CODE.KEY_F5) THEN
            IF GetKeyDown(%KEY_CODE.KEY_CONTROL) THEN
                FrameLoopAnimation(ninja,  174,182)
            ELSE
                FrameLoopAnimation(ninja,  60, 68)
            END IF
        END IF

        IF GetKeyUp(%KEY_CODE.KEY_F6) THEN
            IF GetKeyDown(%KEY_CODE.KEY_CONTROL) THEN
                FrameLoopAnimation(ninja,  184,205)
            ELSE
                FrameLoopAnimation(ninja,  69, 72)
            END IF
        END IF

        IF GetKeyUp(%KEY_CODE.KEY_F7) THEN
            IF GetKeyDown(%KEY_CODE.KEY_CONTROL) THEN
                FrameLoopAnimation(ninja,  206,250)
            ELSE
                FrameLoopAnimation(ninja,  73, 83)
            END IF
        END IF

        IF GetKeyUp(%KEY_CODE.KEY_F8) THEN
            IF GetKeyDown(%KEY_CODE.KEY_CONTROL) THEN
                FrameLoopAnimation(ninja,  251,300)
            ELSE
                FrameLoopAnimation(ninja,  84, 93)
            END IF
        END IF

        IF GetKeyUp(%KEY_CODE.KEY_F9) THEN
            FrameLoopAnimation(ninja,  94, 102)
        END IF

        IF GetKeyUp(%KEY_CODE.KEY_F10) THEN
            FrameLoopAnimation(ninja,  103, 111)
        END IF
        IF GetKeyUp(%KEY_CODE.KEY_F11) THEN
            FrameLoopAnimation(ninja,  112, 125)
        END IF
        IF GetKeyUp(%KEY_CODE.KEY_F12) THEN
            FrameLoopAnimation(ninja,  126, 133)
        END IF




        ' ---------------
        '      Render
        ' ---------------
        BeginScene(150, 150, 150, 255, 1, 1)
        DrawScene()
        NX3_DrawText(pbfont, "Animation Frame Number Ninja: "+ TRIM$(STR$(AnimationFrameNumber(ninja))),  10,10,0,0, &h0ff00ffff)
        NX3_DrawText(pbfont, "Pres F1-F12 and Ctrl+F1>-<Ctrl+F8 to change ninja animation",  10,26,0,0, &h0ffffff00)
        EndScene()


    WEND
    ' end
    FreeEngine()

END FUNCTION
  •  

Peter Weis


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  054   as   single sprite2D test.
'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN

    ' Dimes
    DIM app AS DWORD
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app = %NULL THEN
        EXIT FUNCTION
    END IF


    '----------------------------------------
    '// PARTIE 3D
    '----------------------------------------
    ' Load 3D objects
    DIM obj2 AS Mesh
    obj2 = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)

    '-----------------------------------------
    ' Create earth
    DIM sphere AS EntityNode
    sphere =  CreateEntityNode(obj2, 0, 0, 0, %NULL)
    ScaleNode(sphere, 1.5,1.5,1.5)


    '-----------------------------------------
    ' Create first  camera
    DIM cam AS CameraNode
    cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
    PositionNode(cam,0,0,-10)




    '----------------------------------------
    '// PARTIE 2D
    '----------------------------------------
    '-----------------------------------------
    ' Create sprite 1
    DIM sp1 AS Sprite2D
    sp1 = CreateSprite2D("media/grass.bmp", 0.2, &h0ffffffff, %NULL)
    PositionNode(sp1, 0,0,1)


    '-----------------------------------------
    ' Create sprite 2
    DIM sp2 AS Sprite2D
    sp2 = CreateSprite2D("media/five.bmp", 0.75, &h0ffffffff, %NULL)

    PositionNode(sp2, 200,50,1.5)
    '_CenterSprite3D(sp2,  50,  50)

    DIM texturelist AS NArray
    texturelist = CreateListTexture("media/ball2.png", 64,64)

    DIM anim AS NNodeAnimator
    anim = CreateTextureAnimator( texturelist,  100, %TRUE)
    AddAnimatorTexture(sp2, anim)



    '-----------------------------------
    ' Load font png
    LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)

    DIM pbfont AS IGUIFont
    pbfont = GetFont()


    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit=0


    ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF


        IF GetKeyDown(%KEY_CODE.KEY_KEY_R) THEN
            TurnNode(sp2, 0,0,1, 0)
        END IF

        IF GetKeyDown(%KEY_CODE.KEY_KEY_Y) THEN
            TurnNode(sp2, 0,0,-1, 0)
        END IF

        IF GetKeyDown(%KEY_CODE.KEY_KEY_T) THEN
            MoveNode(sp2,1,0,0, 0)
        END IF

        IF GetKeyDown(%KEY_CODE.KEY_KEY_V) THEN
            MoveNode(sp2,-1,0,0, 0)
        END IF




        DIM xx AS LONG
        xx = ProjectedX(sphere, %NULL)

        DIM yy AS LONG
        yy  = ProjectedY(sphere, %NULL)

        PositionNode(sp1, xx-400+10, 300-yy+10, 1)

        ' ---------------
        '      Render
        ' ---------------
        BeginScene(100,100,100, 255, 1, 1)
        DrawScene()

        Begin2D(800,600)
        RenderSprite2D(sp1)
        RenderSprite2D(sp2)
        End2D()

        NX3_DrawText(pbfont, "Key R/Y/T/V to move sprite2",  10,10,0,0, &h0ff9999ff)
        NX3_DrawText(pbfont, "move earth with mouse and sprite1 follow...",  10,25,0,0, &h0ff9999ff)

        EndScene()

    WEND
    ' end
    FreeEngine()
END FUNCTION

  •  

Patrice Terrier

Peter

I would suggest to put everything within a single ZIP file:
All the DLL(s) required to run the examples, the include file, and all the .bas examples (and perhaps with their .exe).

Then when you update something, just post a notification, that there is a new attachment linked to the first post of this thread.

Note: I am glad to see a new code contributor to this forum, thank you.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com
  •  

Peter Weis

Hi Patrice,
wanted to put it in a zip file but unfortunately the volume is too large. Zip or Rar file for a too large

On the first post I wanted to attach it too, but that is not mine

regards Peter
  •  

Jeff Blakeney

I don't think I've used ISMISSING myself in any code but what I posted was just a thought I had for a work around for the problem of default values.  I still think that it is pretty stupid that the source code I create has to specify that value rather than the routine in a DLL I'm calling just setting the value itself if the parameter isn't specified.

If ISMISSING only works with BYREF then you only need to change the CloneNode parameters to be passed BYREF instead and it should work.  If it doesn't, then hopefully zero isn't a valid value for those parameters and you can just just to see if node = 0 or parent = 0 and set them to the defaults instead.

There may be a better way to do this with a macro instead to avoid the extra overhead of another function call.
  •  

Theo Gottwald

Peter was so kind to sent me a compilation with around 23 MB.
If anybody also want this ZIP File with the 3D stuff, mail me then I'll forward you that mail.

Please make sure hoever, that your mailbox can take 23 MB.

Peter Weis

Hi Jeff,
The idea I had with macro that works well is not!
regards Peter
  •  

Peter Weis


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample 055  :  load a DeepMesh scene
'
'   Thanks to Innesoft for the media used in this sample. (and painting on the wall, called 'Tina' by J.H.Lynch )
'
'                http://deepmesh.innesoft.com
'
'   Historique  :
'     09/06/11  19:16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN
    ' Globales
    DIM app AS DWORD
    DIM Quit AS INTEGER



    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800, 600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)

    IF app = %NULL THEN
        EXIT FUNCTION
    END IF



    ' set the curent folder
    ChangeWorkingDirectory("media/house/")

    '; load an 3D scene
    DIM  scene AS EntityNode
    scene = LoadDpmScene("room5.dpm", "")




    ' create a camera
    DIM cam AS CameraNode
    cam = CreateCameraFPS(70, 0.01, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
    PositionNode(cam, 0,0,-5)




    ' ---------------------------------------
    '           main loop
    ' ---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF


        ' ---------------
        '      Render
        ' ---------------
        BeginScene(150,150,150, 255, 1, 1)
        DrawScene()
        EndScene()


    WEND
    ' end
    FreeEngine()
END FUNCTION
  •  

Peter Weis


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  100   as   first test collision.
'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN
    ' Dimes
    DIM app AS DWORD
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800, 600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app = %NULL THEN
        EXIT FUNCTION
    END IF

    '----------------------------------------
    ' Create traditional light And set position
    DIM light AS LightNode
    light = CreateLight(&h0ffdddddd, 200, %ELT_POINT , %NULL)
    PositionNode(light, 5,15,-3)




    '-----------------------------------------
    ' Create a cube
    DIM cubemesh AS Mesh
    cubemesh = CreateCubeMesh(3.0)

    DIM cube AS EntityNode
    cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)

    PositionNode(cube, -3,1,0)
    LoadTextureNode(cube, "media/wcrate.bmp", 0, 0)
    DIM pbmat AS NMaterial
    pbmat = NodeMaterial(cube, 0)
    ColorMaterial(pbmat,  %ECM_NONE)

    ' Create And  set collide Type
    CreateNodeCollide(cube, %BOX_PRIMITIVE, 1)


    ' Load an 3D Object
    DIM obj AS Mesh
    obj = LoadMesh("media/teapot.b3d", %HARDMAPPING.EHM_STATIC)
    ScaleMesh(obj, 0.4,0.4,0.4)

    ' Create a mesh with one of the 3D Object loaded
    DIM teapot AS EntityNode
    teapot = CreateEntityNode(obj, 0, 0, 0, %NULL)
    PositionNode(teapot, 0.75,0,0)
  ' Create And  set collide Type
    CreateNodeCollide(teapot, %HULL_PRIMITIVE, 1)





    '-----------------------------------------
    ' Create first  camera
    DIM cam AS CameraNode
    cam = CreateCamera(%NULL )
    PositionNode(cam, 0,5,-10)
    RotateNode(cam, 15,-5,0)

    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF

        TurnNode(teapot, 0,1,0, 0)


        IF NodeCollide(teapot, cube) THEN
            DiffuseColorNode(cube, &h0ff000000)
        ELSE
            DiffuseColorNode(cube, &h0ffffffff)
        END IF


        ' ---------------
        '      Render
        ' ---------------
        BeginScene(100, 100, 100, 255, 1, 1)
        DrawScene()
        EndScene()


    WEND
    ' end
    FreeEngine()
END FUNCTION

  •  

Patrice Terrier

#85
Peter,

I just made a quick try of your N3xD examples, using your 004_loadmesh.bas example, using the PB10 compiler.

Here is what i have found so far:

  • The color of the earth texture is wrong.
  • Using the window's close button, doesn't exit from the loop, it just hides the window and rises up the CPU percentage to 25%.

The N3xD runtime DLL is huge, compared to the same code produces with direct call to OpenGL.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com
  •  

Peter Weis

Patrice,

Quote
•The color of the earth texture is wrong.


must look at times why the color is wrong, just as in FreeBasic. In PureBasic example, it is different but you're right!

Quote
•Using the window's close button, doesn't exit from the loop, it just hides the window and rises up the CPU percentage to 25%.

The problem with closing the program are all examples is also at Free Basic must still reach the engine is called FreeEngine

On the size of N3xD.DLL I can not do anything so there are all the controls and buttons

regards Peter
  •  

Peter Weis

Hi Patrice,
The color is wrong because the AmbientLight(&h0ffffff00)   is called. The panel then made ​​the wrong color

regards Peter
  •  

Peter Weis



' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  101   as   Collide test.
'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------

' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN
    ' Dimes
    DIM app AS DWORD
    DIM Quit AS INTEGER
    DIM i AS LONG
    DIM pbres AS EntityNode


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800, 600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app = %NULL THEN
        EXIT FUNCTION
    END IF


    '----------------------------------------
    ' Create traditional light And set position
    DIM light AS LightNode
    light = CreateLight(&h0ffdddddd, 200, %ELT_POINT, %NULL)
    PositionNode(light, 5,25,3)
    AmbientLight(&hff222222)



    '-----------------------------------------
    ' Create a static base
    DIM cubemesh AS Mesh
    cubemesh = CreateCubeMesh(1.0)

    DIM cube AS EntityNode
    cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
    PositionNode(cube, 0,-2,0)
    LoadTextureNode(cube, "media/grille1.bmp", 0, 0)

    DIM pbmat AS NMaterial
    pbmat = NodeMaterial(cube, 0)

    ColorMaterial(pbmat, %ECM_NONE)
    ScaleNode( cube, 20,1,20)


    '-----------------------------------------
    ' Create a cube
    FOR i = 0 TO 15
        cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
        PositionNode(cube, -6+RND()*12,-1,-6+RND()*12)
        LoadTextureNode(cube, "media/body.bmp", 0, 0)
        pbmat = NodeMaterial(cube, 0)
        ColorMaterial(pbmat, %ECM_NONE)
        ' Create collide Type
        CreateNodeCollide(cube, %BOX_PRIMITIVE, 1)
    NEXT

    cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
    PositionNode(cube, 0,-1,-5)
    LoadTextureNode(cube, "media/body.bmp", 0, 0)
    pbmat = NodeMaterial(cube, 0)
    ColorMaterial(pbmat, %ECM_NONE)
    ' Create collide Type
    CreateNodeCollide(cube, %BOX_PRIMITIVE, 1)

    cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
    PositionNode(cube, 0,1,-5)
    LoadTextureNode(cube, "media/body.bmp", 0, 0)
    pbmat = NodeMaterial(cube, 0)
    ColorMaterial(pbmat,  %ECM_NONE)
    ' Create collide Type
    CreateNodeCollide(cube, %BOX_PRIMITIVE, 1)


    '-----------------------------------------
    ' Create sphere
    DIM spheremesh AS Mesh
    spheremesh = CreateSphereMesh(1, 16)

    DIM sphere AS EntityNode
    sphere = CreateEntityNode(spheremesh, 0, 0, 0, %NULL)
    PositionNode(sphere, 0,-0.25,0)
    LoadTextureNode(sphere, "media/body.bmp", 0, 0)
    ' Create collide Type
    CreateNodeCollide(sphere, %SPHERE_PRIMITIVE ,1)





    '-----------------------------------------
    ' Create first  camera
    DIM cam AS CameraNode
    cam = CreateCamera(%NULL )

    PositionNode(cam, 0,7,-12)
    RotateNode(cam, 38,0,0)

    '-----------------------------------------
    LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
    DIM pbfont AS IGUIFont
    pbfont = GetFont()

    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF


        ' move sphere with dir key
        IF GetKeyDown(%KEY_CODE.KEY_ARROW_UP) THEN
            TranslateNode(sphere, 0,0,0.1)
            DIM num AS INTEGER
            num = NodeCollideAll(sphere)
            FOR i = 0 TO num
                pbres = CollideNode(i)
                IF pbres THEN
                    DiffuseColorNode(pbres, &h0ff0000ff)
                END IF
            NEXT
        END IF

        IF GetKeyDown(%KEY_CODE.KEY_ARROW_DOWN) THEN
            TranslateNode(sphere, 0,0,-0.1)
            num = NodeCollideAll(sphere)
            FOR i = 0 TO num
                pbres = CollideNode(i)
                IF pbres THEN
                    DiffuseColorNode(pbres, &h0ff0000ff)
                END IF
            NEXT
        END IF

        IF GetKeyDown(%KEY_CODE.KEY_ARROW_LEFT) THEN
            TranslateNode(sphere, -0.1,0,0)
            num = NodeCollideAll(sphere)
            FOR i = 0 TO num
                pbres = CollideNode(i)
                IF pbres THEN
                    DiffuseColorNode(pbres, &h0ff0000ff)
                END IF
            NEXT
        END IF

        IF GetKeyDown(%KEY_CODE.KEY_ARROW_RIGHT) THEN
            TranslateNode(sphere, 0.1,0,0)
            num = NodeCollideAll(sphere)
            FOR i = 0 TO num
                pbres = CollideNode(i)
                IF pbres THEN
                    DiffuseColorNode(pbres, &h0ff0000ff)
                END IF
            NEXT
        END IF


        ' ---------------
        '      Render
        ' ---------------
        BeginScene(0, 0, 0, 255, 1, 1)
        DrawScene()
        NX3_DrawText(pbfont, "Use Dir Key to move Sphere", 10, 10, 0, 0, &h0ff9999ff)
        EndScene()



    WEND
    ' end
    FreeEngine()
END FUNCTION
  •  

Peter Weis


' ------------------------------------------------------------
'   n3xt-D exemples
'
'   Sample  103   as   first test with physic engine.
'   Historique   as
'     29/03/09  19 as 16    TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"

FUNCTION PBMAIN
    ' Dimes
    DIM app AS DWORD
    DIM Quit AS INTEGER


    '----------------------------------------------------------
    ' open n3xt-D screen
    app = CreateGraphics3D(800, 600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
    IF app = %NULL THEN
        EXIT FUNCTION
    END IF




    '-----------------------------------------
    ' Create a static base
    DIM cubemesh AS Mesh
    cubemesh = CreateCubeMesh(1.0)

    DIM cube AS EntityNode
    cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)

    PositionNode(cube, 0,-2,0)
    LoadTextureNode(cube, "media/grille1.bmp", 0, 0)
    ScaleNode( cube, 20,1,20)
    ' Create body, no dynamique
    CreateBody(cube, %BOX_PRIMITIVE, %FALSE, 1.0, 0, 0, 0)



    '-----------------------------------------
    ' Create a cube
    DIM i AS INTEGER
    FOR i = 0 TO 25
        cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
        PositionNode(cube, -10+RND()*20,10,-10+RND()*20)
        LoadTextureNode(cube, "media/body.bmp", 0, 0)
        ' Create body, dynamique
        CreateBody(cube, %BOX_PRIMITIVE, %True, 1.0, 0, 0, 0)
    NEXT





    '-----------------------------------------
    ' Create a sphere
    DIM spheremesh AS Mesh
    spheremesh = CreateSphereMesh(1.0, 16)

    DIM sphere AS EntityNode
    sphere = CreateEntityNode(spheremesh, 0, 0, 0, %NULL)

    PositionNode(sphere, -2,4,0)
    LoadTextureNode(sphere, "media/stones.jpg", 0, 0)
    ' Create body, no dynamique
    CreateBody(sphere, %SPHERE_PRIMITIVE, %True, 1.0, 0, 0, 0)


    '-----------------------------------------
    ' Create a cylinder
    DIM cylindermesh AS Mesh
    cylindermesh = CreateCylinderMesh(1.0, 5.0, &h0ffffffff, 8, %True, 0)

    DIM cylinder AS EntityNode
    cylinder = CreateEntityNode(cylindermesh, 0, 0, 0, %NULL)

    PositionNode(cylinder, -1,4,5)
    LoadTextureNode(cylinder, "media/water.jpg", 0, 0)
    '_ScaleNode(cylinder, 2,2,2)

    ' Create body, no dynamique
    CreateBody(cylinder, %CYLINDER_PRIMITIVE, %True, 1.0, 0, 0, 0 )
    RotateNode(cylinder, 0,0, 90)



    '-----------------------------------------
    ' Create a capsule
    cylindermesh = CreateCylinderMesh(1.0, 5.0, &h0ffffffff, 8, %True, 0)
    cylinder = CreateEntityNode(cylindermesh, 0, 0, 0, %NULL)
    PositionNode(cylinder, -1,4,-2)
    LoadTextureNode(cylinder, "media/water.jpg", 0, 0)
    ' Create body, no dynamique
    CreateBody(cylinder, %CAPSULE_PRIMITIVE, %True, 1.0, 0, 0, 0)




    '-----------------------------------------
    ' Create a hull Object
    ' Load an 3D Object
    DIM obj AS Mesh
    obj = LoadMesh("media/teapot.b3d", %HARDMAPPING.EHM_STATIC)
    ScaleMesh(obj, 0.4,0.4,0.4)

    ' Create a mesh with one of the 3D Object loaded
    DIM teapot AS EntityNode
    teapot = CreateEntityNode(obj, 0, 0, 0, %NULL)
    PositionNode(teapot, 0,12,0)

    ' Create And  set collide Type
    CreateBody(teapot, %HULL_PRIMITIVE, %True, 1.0, 0, 0, 0)






    '-----------------------------------------
    ' Create first  camera
    DIM cam AS CameraNode
    cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
    PositionNode(cam, 0,7,-20)



    ' ---------------------------------------
    '           Main loop
    ' ---------------------------------------
    WHILE Quit=0


        ' If Escape Key, Exit
        IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
            Quit=1
        END IF

        IF GetKeyUp(%KEY_CODE.KEY_SPACE) THEN
            FOR i  = 0 TO 7
                cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
                PositionNode(cube, -8+RND()*16,10, -8+RND()*16)
                LoadTextureNode(cube, "media/five.bmp", 0, 0)
                ' Create body, no dynamique
                CreateBody(cube, %BOX_PRIMITIVE, %True, 1.0, 0, 0, 0)
            NEXT
        END IF




        ' ---------------
        '      Render
        ' ---------------
        BeginScene(0, 0, 0, 255, 1, 1)
        DrawScene()
        EndScene()


    WEND
    ' end
    FreeEngine()
END FUNCTION

  •