A few topics down is an old thread about 3Impact. Since there was some interest in it, I am posting some info about a 3D engine that I just stumbled on that looks pretty nice. It is called N3xtD. It is free and is being used for a 3D modeling program I am trying out. There are not any PowerB wrappers at this point, but there are wrappers included for several other languages. It should be easy enough for somebody skilled with PowerB to convert the FreeBasic wrappers to PowerB.
http://n3xt-d.org
It could be something fun for somebody to play with.
Hello Manuel,
I've made the effort and adapted to the Includes PowerBASIC! But there are still errors. But for a try, it already reached
regards Peter ;D
Include Attention new today 11.10.2011
Hello,
here is the next example
regards Peter
Hello,
resist a few mistakes in "N3xtD.bi" eliminated
regards Peter
And here is the next example
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 006 as Load a simple 3D Object And set multiple mesh
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
' Dimes
FUNCTION PBMAIN()
DIM app AS DWORD
DIM Quit AS LONG
'----------------------------------------------------------
' open n3xt-D screen
app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app=%NULL THEN
END
END IF
' Load an 3D Object
DIM obj AS Mesh
obj = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)
' Create several mesh
DIM i AS INTEGER
DIM sphere AS EntityNode
FOR i = 0 TO 3
'; Create a mesh with one of the 3D Object loaded
sphere = CreateEntityNode(obj, 0, 0, 0, %NULL)
' set position
PositionNode(sphere, 3*i,0,0)
NEXT
' create a camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, 6,0,-10)
' ---------------------------------------
' Main loop
' ---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' just turn our sphere
TurnNode(sphere, 0,0.5,0, 0)
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Next example
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 007 as just create a single mesh
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
FUNCTION PBMAIN
' Dimes
DIM app AS DWORD 'any Ptr
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
'---------------------------
' define a ManualContruct Mesh
DIM mesh_ AS Mesh
' Create the mesh
mesh_ = CreateEmptyMesh(%VERTEX_TYPE.EVT_STANDART)
' add one buffer For vertices And faces
' define 3 vertices
DIM v1 AS LONG
v1 = AddVertexMesh(mesh_, 0, 0,0,0, 0,0,0, &h0ffff, 0, 0, 0, 0)
DIM v2 AS LONG
v2 = AddVertexMesh(mesh_, 0, 2,2,0, 0,0,0, &h0ffff, 0, 0, 0, 0)
DIM v3 AS LONG
v3 = AddVertexMesh(mesh_, 0, 2,0,0, 0,0,0, &h0ffff, 0, 0, 0, 0)
' add one face
AddFaceMesh(mesh_, 0, v1, v2, v3)
' add second buffer For vertices And faces
AddEmptyMeshBuffer(mesh_, %VERTEX_TYPE.EVT_STANDART)
' define 3 vertices
v1 = AddVertexMesh(mesh_, 1, 0,2,0, 0,0,0, &h0ffff, 0, 0, 0, 0)
v2 = AddVertexMesh(mesh_, 1, 2,2,0, 0,0,0, &h0ffff, 0, 0, 0, 0)
v3 = AddVertexMesh(mesh_, 1, 0,0,0, 0,0,0, &h0ffff, 0, 0, 0, 0)
' add one face
AddFaceMesh(mesh_, 1, v1,v2,v3)
' Create a mesh with one of the 3D Object loaded
DIM element AS EntityNode
element = CreateEntityNode(mesh_, 0, 0, 0, %NULL)
'---------------------------
' Create a camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, 1,0,-10)
' ---------------------------------------
' Main loop
' ---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' just turn our sphere
TurnNode(element, 0,0.5,0, 0)
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Did the declaration of Sendlog N3xtD.bi changed in that is better
DECLARE SUB SendLog CDECL LIB "N3XTD.DLL" ALIAS "_SendLog"(logtext AS ASCIZ)
instead of
DECLARE SUB SendLog CDECL LIB "N3XTD.DLL" ALIAS "_SendLog"(byval logtext AS ASCIZ ptr)
This facilitates the transfer
And a new example
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 009 as modifiy mesh loaded geometry
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
FUNCTION PBMAIN
' Dimes
DIM app AS DWORD 'any Ptr
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
' Load an 3D Object
DIM obj AS Mesh
obj = LoadMesh("media/earth.x", 0)
' dim obj as Mesh = _CreateSphereMesh(1)
' Create several mesh
DIM sphere AS EntityNode
DIM i AS INTEGER
FOR i = 0 TO 3
' Create a mesh with one of the 3D Object loaded
sphere = CreateEntityNode(obj, 0, 0, 0, %NULL)
' set position
PositionNode(sphere, 3*i,0,0)
NEXT
' send inside the console some mesh buffer information
SendLog("Number of MeshBuffer as " + STR$(MeshBufferCount(obj)))
SendLog("Type of Vertex Buffer as " + STR$(MeshTypeVertex(obj, 0)))
'_SendLog("adr of mesh buffer 0 as "+ str$(_MeshBuffer(obj, 0)))
SendLog("number of vertices inside the meshbuffer as "+ STR$(MeshVertexCount(obj,0) ))
'apply the scale transformation For all the vertices
DIM vec(4) AS SINGLE
FOR i = 0 TO MeshVertexCount(obj, 0)-1
' get vertex
MeshVertex(obj, 0, i, BYVAL VARPTR (vec(0)))
' multiply vertices position values
vec(0)=vec(0)*3
vec(1)=vec(1)*3
vec(2)=vec(2)*3
' set vertex
VertexPositionMesh(obj,0, i, vec(0), vec(1), vec(2))
NEXT
' because all spheres mesh is based on the same Object geometrie,
' If you transform this mesh geometrie, all the mesh will be
' affected by this transformation
' Create a camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, 6,0,-10)
' ---------------------------------------
' Main loop
' ---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
TurnNode(sphere, 0,0.5,0, 0)
' ---------------
' Render
' ---------------
BeginScene(128,128,128, 255, 1, 1)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Next example
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 010 as first texturing
' 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 mesh
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(1.0)
DIM spheremesh AS Mesh
spheremesh = CreateSphereMesh(1.0, 16)
DIM cylindermesh AS Mesh
cylindermesh = CreateCylinderMesh(1.0, 3.0, &h0ffffffff, 8, %True, 0)
' Create all entity with mesh
DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(cube, -6,0,0)
' first Method To texturing
DIM material AS NMaterial
material = NodeMaterial(cube, 0)
' Load texture
DIM tex AS NTexture
tex = LoadTexture( "media/wall.jpg")
' set texture in material
TextureMaterial(material, 0, tex)
' Create a sphere And set position
DIM sphere AS EntityNode
sphere = CreateEntityNode(spheremesh, 0, 0, 0, %NULL)
PositionNode(sphere, -2,0,0)
' second Method
LoadTextureNode(sphere, "media/body.bmp", 0, 0)
' Create a cylinder And set position
DIM cylinder AS EntityNode
cylinder = CreateEntityNode(cylindermesh, 0, 0, 0, %NULL)
PositionNode(cylinder, 2,0,0)
' Load texture
LoadTextureNode(cylinder, "media/five.bmp", 0, 0)
' Create a camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, 0,0,-10)
' ---------------------------------------
' Main loop
' ---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' ---------------
' Render
' ---------------
BeginScene(12,12,12, 255, 1, 1)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
N3xtD.bi was also changed again
regards
example 011
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 011 as render on texture.
' 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
' set ambient light
AmbientLight(&h0ffaaaaaa)
' Create mesh
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(1.0)
'-----------------------------------------
' Create a cube And set position
DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(cube, 0,0,0)
' first Method To texturing
DIM material AS NMaterial
material = NodeMaterial(cube, 0)
' Load texture
DIM tex AS NTexture
tex = LoadTexture( "media/glass.bmp")
' set texture in material
TextureMaterial(material, 0, tex)
'-----------------------------------------
' Create cube For receive texturerendered
DIM target AS EntityNode
target = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
ScaleNode(target, 3,3,3)
PositionNode(target, -6,0,0)
MaterialFlagNode(target, %EMF_LIGHTING, %False)
' assign target texture on the *target cube
DIM textureTarget AS NTexture
textureTarget = CreateRenderTargetTexture( 256, 256, %ECF_UNKNOWN)
MaterialTextureNode(target, textureTarget, 0 )
' Create first camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, -5,3,-10)
' Create second camera For render target
DIM cam2 AS CameraNode
cam2 = CreateCamera(%NULL)
PositionNode(cam2, 0,0,-3)
' ---------------------------------------
' Main loop
' ---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
TurnNode(cube, 0,1,0, 0)
' ---------------
' Render
' ---------------
BeginScene(0,0,0, 255, 1, 1)
' render traget texture with camera 2
ActiveCamera(cam2)
RenderTarget(textureTarget , %True, %True, &hff666600)
' this Method
RenderNode(cam2)
RenderNode(cube)
' <<Or>>
'_VisibleNode(*target, #False)
'_DrawScene()
' render with Main camera
ActiveCamera(cam)
RenderTarget(%Null , %True, %True, 0)
VisibleNode(target, %True)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
example 013
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 013 as primitives with a light.
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
FUNCTION PBMAIN
' Dimes
DIM app AS DWORD
DIM Quit AS DWORD
'----------------------------------------------------------
' 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 light And set position
DIM light AS LightNode
light = CreateLight( &h0ffffffff, 12, %ELT_POINT , %NULL )
PositionNode(light, 0,5,5)
' change light diffuse color
DiffuseColorLight( light, &h0ffffff00)
AmbientLight( &h0ff22222)
' Create mesh
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(1.0)
DIM spheremesh AS Mesh
spheremesh = CreateSphereMesh(1.0, 16)
DIM cylindermesh AS Mesh
cylindermesh = CreateCylinderMesh(1.0, 3.0, &H0ffffffff, 8, %True, 0)
' Create all entity with mesh
DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(cube, -6,0,0)
' Create a sphere And set position
DIM sphere AS EntityNode
sphere = CreateEntityNode(spheremesh, 0, 0, 0, %NULL)
PositionNode(sphere, -2,0,0)
' Create a cylinder And set position
DIM cylinder AS EntityNode
cylinder = CreateEntityNode(cylindermesh, 0, 0, 0, %NULL)
PositionNode(cylinder, 2,0,0)
RotateNode(cylinder, 0,0,90)
' Create a camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, 0,0,-10)
DIM lightpos(4) AS SINGLE
DIM angle AS SINGLE
'; ---------------------------------------
'; Main loop
'; ---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
angle = angle + 0.05
lightpos(0) = 10*COS( angle)
lightpos(2) = 10*SIN( angle)
XNode( light, lightpos(0))
ZNode( light, lightpos(2))
'---------------
' Render
' ---------------
BeginScene(128,128,128, 255, 1, 1)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
The last example for today
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 014 as primitives with a light And material.
' 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 light And set position
DIM light AS LightNode
light = CreateLight( &h0ffffffff, 10, %ELT_POINT , %NULL)
PositionNode(light, 0,5,0)
' Create mesh
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(1.0)
DIM spheremesh AS Mesh
spheremesh = CreateSphereMesh(1.0, 16)
DIM cylindermesh AS Mesh
cylindermesh = CreateCylinderMesh(1.0, 3.0, &H0ffffffff, 8, %True, 0)
' Create a cube And set position
DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(cube, -6,0,0)
' first Method set
DIM mat_ AS NMaterial
mat_= NodeMaterial(cube, 0)
ColorMaterial(mat_, %ECM_NONE)
DiffuseColorMaterial(mat_, &h0ffff0000)
' Create a sphere And set position
DIM sphere AS EntityNode
sphere = CreateEntityNode(spheremesh, 0, 0, 0, %NULL)
PositionNode(sphere, -2,0,0)
' second metohd set
MaterialColorNode(sphere, %ECM_NONE)
DiffuseColorNode(sphere, &h0ff00ff00)
' Create a cylinder And set position
DIM cylinder AS EntityNode
cylinder = CreateEntityNode(cylindermesh, 0, 0, 0, %NULL)
PositionNode(cylinder, 2,2,0)
RotateNode(cylinder, 0,0,90)
' second metohd set
MaterialColorNode(cylinder, %ECM_NONE)
DiffuseColorNode(cylinder, &h0ff0000ff)
' Create a camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, 0,0,-10)
DIM lightpos(4) AS SINGLE
DIM angle AS SINGLE
angle = 3.0
' ---------------------------------------
' Main loop
' ---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
angle = angle + 0.02
lightpos(0) = 10*COS( angle)
lightpos(2) = 10*SIN( angle)
XNode( light, lightpos(0))
ZNode( light, lightpos(2))
' ---------------
' Render
' ---------------
BeginScene(128,128,128, 255, 1, 1)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Next example
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 015 : primitives with a spot light and material.
' Historique :
' 29/03/09 19:16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
FUNCTION PBMAIN
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 light And set position
DIM light AS LightNode
light = CreateLight(&h0ffffffff, 10, %ELT_POINT , %NULL)
PositionNode(light, 0,15,-8)
' change light Type -> SPOTLIGHT
TypeLight( light, %ELT_SPOT) ' Or iTypeLight( light, ELT_DIRECTIONAL)
' redefine internal parameters
RadiusLight( light, 30)
RotateNode( light, 60,0,0)
OuterConeLight( light, 30)
InnerConeLight( light, 25 )
' color light set element
'_AmbientColorLight( light, &hff999999)
'_DiffuseColorLight( light, &hff555555)
'----------------------------------------
' Create mesh
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(1.0)
DIM spheremesh AS Mesh
spheremesh = CreateSphereMesh(1.0, 16)
DIM cylindermesh AS Mesh
cylindermesh = CreateCylinderMesh(1.0, 3.0, &H0ffffffff, 8, %True, 0)
' Create a cube And set position
DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(cube, -6,0,0)
' first Method set
DIM mat_ AS NMaterial
mat_ = NodeMaterial(cube, 0)
ColorMaterial(mat_, %ECM_NONE)
DiffuseColorMaterial(mat_, &h0ff000044)
ShadowVolumeEntity(cube, %True, 10000.0 )
' Create a sphere And set position
DIM sphere AS EntityNode
sphere = CreateEntityNode(spheremesh, 0, 0, 0, %NULL)
PositionNode(sphere, -2,0,0)
' second metohd set
MaterialColorNode(sphere, %ECM_NONE)
DiffuseColorNode(sphere, &h0ff004400)
ShadowVolumeEntity(sphere, %True, 10000.0)
' Create a cylinder And set position
DIM cylinder AS EntityNode
cylinder = CreateEntityNode(cylindermesh, 0, 0, 0, %NULL)
PositionNode(cylinder, 2,2,0)
RotateNode(cylinder, 0,0,90)
' second metohd set
MaterialColorNode(cylinder, %ECM_NONE)
DiffuseColorNode(cylinder, &hff440000)
ShadowVolumeEntity(cylinder, %True, 10000.0)
'----------------------------------------
' quick ground For light spot test
DIM hillplanemesh AS Mesh
hillplanemesh = CreateHillPlaneMesh(50.0,50.0, 80,80, %NULL, 0, 0, 0, 1, 1)
DIM hillplane AS EntityNode
hillplane = CreateEntityNode(hillplanemesh, 0, 0, 0, %NULL)
PositionNode(hillplane, 0,-2,0)
ScaleMesh(hillplanemesh, 0.01, 0.01, 0.01)
' second metohd set
AmbientColorNode(hillplane, &h0ff444444)
DiffuseColorNode(hillplane, &hff888888)
' Create a camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, 0,10,-13)
RotateNode(cam, 20,0,0)
'-----------------------------------
' Load font png
LoadFont("media/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
' move light with dir key And mouse (Left click)
IF GetKeyDown(%KEY_CODE.KEY_ARROW_RIGHT) THEN MoveNode(light, 0.5,0,0, %COLLIDE_RESPONSE.RESP_NONE)
IF GetKeyDown(%KEY_CODE.KEY_ARROW_LEFT) THEN MoveNode(light, -0.5,0,0, %COLLIDE_RESPONSE.RESP_NONE)
IF GetKeyDown(%KEY_CODE.KEY_ARROW_UP) THEN MoveNode(light, 0,0,0.5, %COLLIDE_RESPONSE.RESP_NONE)
IF GetKeyDown(%KEY_CODE.KEY_ARROW_DOWN) THEN MoveNode(light, 0,0,-0.5, %COLLIDE_RESPONSE.RESP_NONE)
IF GetMouseEvent(%MOUSE_EVENT.MOUSE_BUTTON_LEFT) THEN
DIM angley AS SINGLE
angley = GetDeltaMouseX(0) / 4.0
DIM anglex AS SINGLE
anglex = GetDeltaMouseY(0) / 4.0
TurnNode(light, anglex, angley,0, 0)
END IF
'; ---------------
'; Render
'; ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
DrawText(font_, "for move spot light: dir key / mouse with leftclick", 10,10,0,0, &h0ffff99ff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Example 016 and other errors by eliminating N3xtD.bi
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 016 as Test transparent cubemesh
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
FUNCTION PBMAIN
' Dimes
DIM app AS DWORD
DIM Quit AS LONG
'----------------------------------------------------------
' open n3xt-D screen
app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app=%NULL THEN
EXIT FUNCTION
END IF
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(5.0)
DIM hillmesh AS Mesh
hillmesh = CreateHillPlaneMesh(10.0, 10.0, 10, 10, %NULL, 0, 0, 0, 1, 1)
'----------------------------------------
' Create a first cube And set position
DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(cube, 5,5,6)
LoadTextureNode(cube, "media/sp1.png", 0, 0)
MaterialTypeNode(cube, %EMT_TRANSPARENT_ALPHA_CHANNEL )
' Create a second cube And set position
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(cube, 0,5,0)
LoadTextureNode(cube, "media/sp1.png", 0, 0)
MaterialTypeNode(cube, %EMT_TRANSPARENT_ALPHA_CHANNEL )
'----------------------------------------
' quick ground
DIM hillplane AS EntityNode
hillplane = CreateEntityNode(hillmesh, 0, 0, 0, %NULL)
LoadTextureNode(hillplane, "media/wall.jpg", 0, 0)
' 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,-30)
'---------------------------------------
' Main loop
'---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' just turn our sphere
TurnNode(cube, 0,0.5,0, 0)
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Even a supplement for today 8)
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 017 as alpha blending test mesh
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
FUNCTION PBMAIN
' Dimes
DIM app AS DWORD
DIM Quit AS LONG
'----------------------------------------------------------
' open n3xt-D screen
app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app=%NULL THEN
END
END IF
'----------------------------------------
' Create light And set position
DIM light AS LightNode
light = CreateLight(&h0ffffffff, 100, %ELT_POINT , %NULL)
PositionNode(light, 0,15,-8)
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(5.0)
DIM hillmesh AS Mesh
hillmesh = CreateHillPlaneMesh(10.0, 10.0, 10, 10, %NULL, 0, 0, 0, 1, 1)
'----------------------------------------
' Create a first cube And set position
DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(cube, 5,5,6)
LoadTextureNode(cube, "media/glass.bmp", 0, 0)
DIM material AS NMaterial
material = NodeMaterial(cube, 0)
TypeMaterial(material, %EMT_TRANSPARENT_ADD_COLOR )
'----------------------------------------
' Create a second cube And set position
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(cube, 0,5,0)
LoadTextureNode(cube, "media/glass.bmp", 0, 0)
' work on material now
material = NodeMaterial(cube, 0)
ColorMaterial(material, %ECM_NONE)
TypeMaterial(material, %EMT_ONETEXTURE_BLEND )
TypeBlendMaterial(material, %EBF_SRC_ALPHA, %EBF_ONE_MINUS_SRC_ALPHA, %EMFN_MODULATE_1X, %EAS_TEXTURE OR %EAS_VERTEX_COLOR)
'----------------------------------------
' quick ground
DIM hillplane AS EntityNode
hillplane = CreateEntityNode(hillmesh, 0, 0, 0, %NULL)
LoadTextureNode(hillplane, "media/wall.jpg", 0, 0)
' 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,-18)
'-----------------------------------
' Load font png
LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
DIM font_ AS IGUIFont
font_ = GetFont()
' ---------------------------------------
' Main loop
' ---------------------------------------
DIM alpha AS LONG
DIM src AS LONG
src = 6
DIM dest AS LONG
dest = 7
DIM cColor AS LONG
WHILE Quit = 0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
TurnNode(cube, 0,0.5,0, 0)
IF GetKeyUp(%KEY_CODE.KEY_KEY_Y) THEN
src = src +1
TypeBlendMaterial(material, src, dest, %EMFN_MODULATE_1X, %EAS_TEXTURE OR %EAS_VERTEX_COLOR)
END IF
IF GetKeyUp(%KEY_CODE.KEY_KEY_H) THEN
src = src -1
TypeBlendMaterial(material, src, dest, %EMFN_MODULATE_1X, %EAS_TEXTURE OR %EAS_VERTEX_COLOR)
END IF
IF GetKeyUp(%KEY_CODE.KEY_KEY_U) THEN
dest = dest +1
TypeBlendMaterial(material, src, dest, %EMFN_MODULATE_1X, %EAS_TEXTURE OR %EAS_VERTEX_COLOR)
END IF
IF GetKeyUp(%KEY_CODE.KEY_KEY_J) THEN
dest = dest -1
TypeBlendMaterial(material, src, dest, %EMFN_MODULATE_1X, %EAS_TEXTURE OR %EAS_VERTEX_COLOR)
END IF
IF GetKeyDown(%KEY_CODE.KEY_KEY_T) THEN
alpha = alpha + 1
IF(alpha>254) THEN alpha = 0
cColor = &h01000000 * alpha + &h010000*alpha + &h0100 * alpha + alpha
DiffuseColorNode(cube, ccolor)
END IF
IF GetKeyDown(%KEY_CODE.KEY_KEY_G) THEN
alpha = alpha - 1
IF(alpha<1) THEN alpha = 255
cColor = &h01000000 * alpha + &h010000*alpha + &h0100 * alpha + alpha
DiffuseColorNode(cube, ccolor)
END IF
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
DrawText(font_, "Key T/G to change alpha as "+ STR$(alpha), 10,10,0,0, &h0ffff3333)
DrawText(font_, "Key Y/H to change src as "+ STR$(src), 10,30,0,0, &h0ffff3333)
DrawText(font_, "Key U/J to changedest as "+ STR$(dest), 10,45,0,0, &h0ffff3333)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Small charge for even today :-[
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 019 : Parallax mapping scene with bumpmap earth
' Historique :
' 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
'----------------------------------------
' fog definition
Fog(&h00908050, %FOG_TYPE.EFT_FOG_LINEAR, 250.0, 1000.0, 0.003, %True, %FALSE )
'----------------------------------------
' Load 3D objects
DIM obj AS Mesh
obj = LoadMesh("media/room.3ds", %HARDMAPPING.EHM_STATIC)
' change planar texture mapping on the mesh
MakePlanarTextureMappingMesh(obj, 0.003)
DIM obj2 AS Mesh
obj2 = CreateMeshWithTangents(obj, %False, %False, %False, %True)
FreeLoadedMesh(obj)
'----------------------------------------
' Create room
DIM room AS EntityNode
room = CreateEntityNode(obj2, 0, 0, 0, %NULL)
' Load two textures
DIM colormap AS NTexture
colormap = LoadTexture( "media/rockwall.bmp")
DIM normalmap AS NTexture
normalmap = LoadTexture( "media/rockwall_height.bmp")
' Creates a normal map from a height map texture.
NormalMapTexture(normalmap, 10.0)
' set texture in the New room (room2)
MaterialTextureNode(room, colormap , 0)
MaterialTextureNode(room, normalmap , 1)
' set material For room parallax mapping
DIM material AS NMaterial
material = NodeMaterial(room, 0)
SpecularColorMaterial(material, 0)
MaterialTypeNode(room, %EMT_PARALLAX_MAP_SOLID )
MaterialFlagNode(room, %EMF_FOG_ENABLE, %True)
TypeParamMaterial(material, 1.0/64.0)
'----------------------------------------
'----------------------------------------
DIM obj1 AS Mesh
obj1 = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)
DIM obj0 AS Mesh
obj0 = CreateMeshWithTangents(obj1, %False, %False, %False, %True)
FreeLoadedMesh(obj1)
' set the alpha value of all vertices To 200
VertexColorAlphaMesh(obj0, 190)
' scale And position mesh
ScaleMesh(obj0, 65,65,65)
'----------------------------------------
' Create EARTH
DIM sphere AS EntityNode
sphere = CreateEntityNode(obj0, 0, 0, 0, %NULL)
' Create New sphere with tangent composants
PositionNode(sphere, -70,130,45)
' Load heightmap, Create normal map from it And set it
DIM earthNormalMap AS NTexture
earthNormalMap = LoadTexture( "media/earthbump.bmp")
' Creates a normal map from a height map texture.
NormalMapTexture(earthNormalMap, 9.0)
MaterialTextureNode(sphere, earthNormalMap , 1)
' adjust material settings
MaterialTypeNode(sphere, %EMT_PARALLAX_MAP_TRANSPARENT_VERTEX_ALPHA )
MaterialFlagNode(sphere, %EMF_FOG_ENABLE, %True)
'----------------------------------------
' Create light And set position
DIM light AS LightNode
light = CreateLight(&h5588ff, 400, %ELT_POINT , %NULL)
PositionNode(light, 0,0,0)
CreateFlyCircleAnimator(light, 0,150,0, 200.0, 0.001)
'----------------------------------------
' create light and set position
DIM light1 AS LightNode
light1 = CreateLight(&hff8800, 400, %ELT_POINT , %NULL)
CreateFlyCircleAnimator(light1, 50,300,0, 190.0, -0.003)
'----------------------------------------
'----------------------------------------
' Create PARTICLE SYSTEM
DIM part AS ParticleSystemNode
part = CreateParticleSystem(%FALSE, light)
' Create a box particle emitter
DIM aabbox(6) AS SINGLE
aabbox(0)=-3 : aabbox(1)=0 : aabbox(2)=-3 : aabbox(3)=3 : aabbox(4)=1 : aabbox(5)=3
DIM box_emitter AS ParticleEmitter
box_emitter = CreateParticleBoxEmitter(part, 0, 0.03, 0, 80, 100, &h0Affffff, &h0Affffff, 400, 1000,0,5,5,5,5, BYVAL VARPTR( aabbox(0)))
' change SizeOf each particle inside the particle emitter
MinStartSizeParticle(box_emitter, 30.0, 40.0 )
MaxStartSizeParticle(box_emitter, 30.0, 40.0 )
' add New emitter inside the particlesystem
AddEmitterParticleSystem(part, box_emitter )
' fadeout element
FadeOutParticleSystem( part, 0, 1000)
' adjust some material settings
LoadTextureNode(part, "media/fireball.bmp", 0, 0)
DIM mat_ AS NMaterial
mat_ = NodeMaterial(part, 0)
TypeMaterial(mat_, %EMT_TRANSPARENT_ADD_COLOR)
'----------------------------------------
'----------------------------------------
' Create a camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam, -145,215,-263)
TargetCamera(cam, -70,130,45)
' simple text inside the scene area
LoadFont("media/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
TurnNode(sphere, 0,0.5,0, 0)
' ---------------
' Render
' ---------------
BeginScene(128,128,128, 255, 1, 1)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Today it is still what git :'(
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 020 as VolumeLight 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 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 volume light And set position
DIM vlight AS VolumeLightNode
vlight = CreateVolumeLight(0, &h000ffffff, 32,32, %NULL )
ScaleNode(vlight, 100.0, 100.0, 100.0)
PositionNode(vlight, -85,50,40)
' Import all the bmp file For animation
DIM texturelist AS NArray
texturelist = CreateArray()
DIM portal AS NTexture
FOR i = 1 TO 7
DIM nname AS STRING
nname = "media/portal"+TRIM$(STR$(i)+".bmp")
portal = LoadTexture( (nname))
PushbackArray( texturelist, BYVAL portal)
NEXT
' define And Create Texture animator
DIM anim AS NNodeAnimator
anim = CreateTextureAnimator( texturelist, 100, %TRUE)
' add inside the node (here vlight) the animator (Texture animator)
AddAnimatorTexture(vlight, anim)
'----------------------------------------
'----------------------------------------
' Load 3D objects
DIM obj AS Mesh
obj = LoadMesh("media/room.3ds", %HARDMAPPING.EHM_STATIC)
' change planar texture mapping on the mesh
MakePlanarTextureMappingMesh(obj, 0.004)
'----------------------------------------
' Create ROOM
DIM room AS EntityNode
room = CreateEntityNode(obj, 0, 0, 0, %NULL)
' Load two textures
DIM colormap AS NTexture
colormap = LoadTexture( "media/wall0.jpg")
' set texture in the New room (room2)
MaterialTextureNode(room, colormap , 0)
' set material For room parallax mapping
DIM material AS NMaterial
material = NodeMaterial(room, 0)
SpecularColorMaterial(material, 0)
'----------------------------------------
'----------------------------------------
'----------------------------------------
'----------------------------------------
' Create PARTICLE SYSTEM
DIM part AS ParticleSystemNode
part = CreateParticleSystem(%FALSE, %NULL)
' Create a box particle emitter
DIM cyl_emitter AS ParticleEmitter
cyl_emitter = CreateParticleCylinderEmitter(part, 0, 0.3, 0, 100, 0, 1, 0, 300, %False, 0, 0.03, 0, 15, 30, &h0ff000000, &h0ffffffff, 2000, 4000, 0, _
5.0, 5.0, 5.0, 5.0)
' change SizeOf each particle inside the particle emitter
MinStartSizeParticle(cyl_emitter, 10.0, 10.0 )
MaxStartSizeParticle(cyl_emitter, 10.0, 10.0 )
' add New emitter inside the particlesystem
AddEmitterParticleSystem(part, cyl_emitter )
' fadeout element
FadeOutParticleSystem(part, 0, 1000 )
LoadTextureNode(part, "media/fireball.bmp", 0, 0)
PositionNode(part, -50,100,0)
DIM mat_ AS NMaterial
mat_ = NodeMaterial(part, 0)
TypeMaterial(mat_, %EMT_TRANSPARENT_ADD_COLOR)
'----------------------------------------
' Create traditional light And set position
DIM light AS LightNode
light = CreateLight(&h0ffffffff, 300, %ELT_POINT , %NULL)
PositionNode(light, -80,130,40)
'----------------------------------------
' Create a camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL )
PositionNode(cam, -95,155,-263)
' simple text inside the scene area
LoadFont("media/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(128,128,128, 255, 1, 1)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
N3xtD.bi have changed again
Peter,
It is good to see somebody exploring gaming capabilities for PowerBASIC. Excellent work on making N3xtD accessible to PowerB users!
Peace,
Brice
Hi, I mainly have you helped the interest was not so great in the forum
That is true, there isn't a lot of interest on the forums. Hopefully, thanks to your efforts that might change a little. ;D Thank you for your hard work on this, I am sure it will be beneficial to others. :)
Next example
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 021 as Mesh particle demo.
' 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
'-----------------------------------------
' set ambient light
AmbientLight(&h0ffaaaaaa)
'----------------------------------------
' Load 3D objects
DIM obj AS Mesh
obj = LoadMesh("media/sphere.x", %HARDMAPPING.EHM_STATIC)
'-----------------------------------------
DIM sp AS EntityNode
sp = CreateEntityNode(obj, 0, 0, 0, %NULL)
'----------------------------------------
'----------------------------------------
' Create PARTICLE SYSTEM
DIM part AS ParticleSystemNode
part = CreateParticleSystem(%FALSE, %NULL )
' Create a box particle emitter
DIM mesh_emitter AS ParticleEmitter
mesh_emitter = CreateParticleMeshEmitter(part, obj, %TRUE, 0, 0.03, 0, 100, -1, %False, 50, 100, &h00ffffff, &h000000ff, 2000, _
4000, 0, 5.0, 5.0, 5.0, 5.0)
' change SizeOf each particle inside the particle emitter
MinStartSizeParticle(mesh_emitter, 10.0, 10.0 )
MaxStartSizeParticle(mesh_emitter, 10.0, 25.0 )
' add New emitter inside the particlesystem
AddEmitterParticleSystem(part, mesh_emitter )
' fadeout element
FadeOutParticleSystem( part, 0, 1000)
' adjust some material settings
LoadTextureNode(part, "media/fireball.bmp", 0, 0)
DIM mat_ AS NMaterial
mat_ = NodeMaterial(part, 0)
TypeMaterial(MAT_, %EMT_TRANSPARENT_ADD_COLOR)
'----------------------------------------
' Create a camera
DIM cam AS CameraNode
cam = CreateCamera(%Null)
PositionNode(cam, 0,1,-120)
'-----------------------------------
' simple text inside the scene area
LoadFont("media/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
TurnNode(sp, 0, 0.15, 0, 0)
' ---------------
' Render
' ---------------
BeginScene(128,128,128, 255, 1, 1)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
' ------------------------------------------------------------
' n3xt-D
'
' sample 023 as Pivot And Parent
' Historique as
' 07/04/09 19 as 16 by Comtois For Dreamotion3D adaptation TMyke
' 07/03/11 19 as 16 adaptation For N3xtD v2.0 by TMyke.
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
'-Constantes
%NBPivot = 4
%NbBranche = 7
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
'-Variable And tab
' Dimes
DIM i AS LONG, j AS LONG
DIM font_ AS IGUIFont
DIM cam AS CameraNode
DIM mesh_(%NbBranche+1, %NBPivot+1) AS EntityNode
DIM pivot(%NbBranche+1, %NBPivot+1) AS EntityNode
' simple text inside the scene area
LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
font_ = GetFont()
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(1.0)
ScaleMesh(cubemesh, 8,8,32)
'-----------------------------------------
'-build general mesh
FOR j = 0 TO %NbBranche
'center Pivot
pivot(j, 0) = CreatePivot(%NULL)
' fisrt bones on pivot 0
mesh_(j, 0) = CreateEntityNode(cubemesh, 0,0,0,pivot(j, 0))
LoadTextureNode(mesh_(j, 0), "media/glass.bmp", 0, 0)
TranslateNode( mesh_(j, 0), 0, 0, 25)
'other bones
FOR i = 0 TO %NBPivot - 1
pivot(j, i + 1) = CreatePivot(mesh_(j, i))
TranslateNode(pivot(j, i + 1), 0, 0, 25)
mesh_(j, i + 1) = CreateEntityNode(cubemesh , 0,0,0,pivot(j, i + 1))
LoadTextureNode(mesh_(j, i + 1), "media/glass.bmp", 0, 0)
TranslateNode(mesh_(j, i + 1), 0, 0, 25)
NEXT
NEXT
'----------------------------------------
' Create a camera
cam = CreateCamera(%NULL)
PositionNode(cam, 0,0,-400)
WHILE Quit = 0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
FOR j = 0 TO %NbBranche
RotateNode( pivot(j, 0), (45-(GetMouseY()/8)), 360.0/(%NbBranche+1) * j + (GetMouseX()/2), 0)
FOR i = 1 TO %NBPivot
RotateNode(pivot(j, i), 45-(GetMouseY()/8), 0, 0)
NEXT
NEXT
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
DrawText(font_, "mouve mouse", 10,10,0,0, &h0ff9999ff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
The views are unfortunately somewhat complicated because the Powerbasic can not >:(
DECLARE SUB DrawText CDECL LIB "N3XTD.DLL" ALIAS "_DrawText"(byval font as IGUIFont, byval text as asciz Ptr, _
byval x as long, _
byval y as long, _
opt byval rx as long, _
opt byval ry as long, _
opt byval col as long=&hff9999ff)
Visual Basic and FreeBasic can
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 024 as split 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(1024,768, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app = %NULL THEN
EXIT FUNCTION
END IF
'-----------------------------------
' add in memory management system a zip file
AddZipFileArchive( "media/map-20kdm2.pk3" )
'-----------------------------------
' Load Quake3 scene Object
DIM obj AS Mesh
obj = LoadMesh("20kdm2.bsp", %HARDMAPPING.EHM_STATIC)
' Create a mesh with one of the 3D Object loaded
DIM quake AS EntityNode
quake = CreateEntityNode(obj, 0, 0, 0, %NULL)
'-----------------------------------
' Create And position cameras
' camera 1
DIM cam1 AS CameraNode
cam1 = CreateCamera(%NULL)
PositionNode(cam1, 1850, 800, 1850)
RotateNode(cam1, 30,200, 0)
DIM cam2 AS CameraNode
cam2 = CreateCamera(%NULL)
PositionNode(cam2, 1300, 1800, 1300)
TargetCamera(cam2, 1300,1000, 1300)
' camera 3
DIM cam3 AS CameraNode
cam3 = CreateCamera(%NULL)
PositionNode(cam3, 100, 500, 150)
TargetCamera(cam3, 180,500,170)
' camera 4
DIM cam4 AS CameraNode
cam4 = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam4, 726, 724, 330)
TargetCamera(cam4, 826, 724, 830)
' simple text inside the scene area
LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
DIM font_ AS IGUIFont
font_ = GetFont()
DIM ResX AS LONG
ResX = 1024
DIM ResY AS LONG
ResY = 768
' ---------------------------------------
' Main loop
' ---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
TurnNode(cam1, 0, 0.25, 0, 0)
' ---------------
' Render
' ---------------
SetViewPort( 0,0,ResX,ResY)
BeginScene(0,0,0, 255, 1, 1)
ActiveCamera(cam1)
SetViewPort( 0,0,ResX/2,ResY/2)
DrawScene()
ActiveCamera(cam2)
SetViewPort( ResX/2,0,ResX,ResY/2)
DrawScene()
ActiveCamera(cam3)
SetViewPort( 0,ResY/2,ResX/2,ResY)
DrawScene()
ActiveCamera(cam4)
SetViewPort( ResX/2,ResY/2,ResX,ResY)
DrawScene()
DrawText(font_, "move camera4 with mouse(click left) and dir key", 10,10,0,0, &h0ff9999ff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
I have been following this thread with interest. When this engine was first mentioned I looked into it a little but I'm not sure it is the best but it would probably be fun to play with. Unfortunately I don't have much time to play with it myself at present but hopefully I will before the end of the year.
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 025 as SkyBox 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
'-----------------------------------------
' set ambient light
AmbientLight(&h0ffaaaaaa)
'-----------------------------------------
' Create a cube And set position
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(1.0)
DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(cube, 0,0,0)
LoadTextureNode(cube, "media/glass.bmp", 0, 0)
' Create Skybox
DIM sky AS EntityNode
sky = CreateSkybox(LoadTexture("media/up.jpg"), LoadTexture("media/dn.jpg"), LoadTexture("media/lf.jpg"), LoadTexture("media/rt.jpg"),_
LoadTexture("media/ft.jpg"), LoadTexture("media/bk.jpg"), %NULL)
'-----------------------------------------
' Create first camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam, 0,1,-10)
'-----------------------------------
' simple text inside the scene area
LoadFont("media/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
TurnNode(cube, 0,1,0, 0)
' ---------------
' Render
' ---------------
BeginScene(128,128,128, 255, 1, 1)
DrawScene()
DrawText(font_, "SkyBox demo", 10,10,0,0, &h0ff00ffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Quote from: Jeff Blakeney on September 28, 2011, 06:55:17 PMWhen this engine was first mentioned I looked into it a little but I'm not sure it is the best but it would probably be fun to play with.
Best is highly subjective. When it comes to free commercial-grade 3D engines, there are only two: OGRE and Irrlicht. Both are cross-platform and both support DirectX and OpenGL. OGRE has been used for commercial games, even some that have been on retail shelves. Irrlicht has been used for commercial games. Irrlicht has the reputation of being easier to work with.
N3xtD is a 3D game engine that is based on Irrlicht which is simply a 3D engine. N3xtD is a proven engine and has been used in commercial projects. Some key features of N3xtD:
~ Supports most features of Irrlicht
~ Newton Physics built in
~ DirectX, OpenGL and Software rendering
~ Supports many common model formats and has an excellent art pipeline
~ Shader support (GLSL/HLSL)
The current version of N3xtD is free. It has been used for commercial projects (game & app) and is capable of being used for apps and games with no problems. Future versions of N3xtD will cost $$. I can't speak to how well N3xtD works with PowerBASIC, you would have to ask a PowerBASIC user, but Peter seems to have no problems working with N3xtD and PowerBASIC. :)
Hello Manuel,
Who you know how to pass variables must be in the PowerBASIC no problem!
PowerBASIC is my favorite programming language!
The transfer of optional parameters and values is somewhat problematic! It is simply not optional parameter with a value in the declaration to show before!
example:
Declare TestFunction cdecl alias "_testfunction" (opt byval x as dword = 10)
Pointers to structures are manifested only returned as a DWORD not simply as a pointer named
It's just a shame Bob Zale has slept here something! There is much new in PowerBASIC 10
regards Peter
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 026 as SkyDome 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 LONG
'----------------------------------------------------------
' 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 ambient light
AmbientLight(&h0ffaaaaaa)
'-----------------------------------------
' Create a cube And set position
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(1.0)
DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(cube, 0,0,0)
LoadTextureNode(cube, "media/glass.bmp", 0, 0)
'Create skydome
DIM sky AS EntityNode
sky = CreateSkydome(LoadTexture("media/env_sky.jpg"), 16, 8, 0.95, 1.3, 1000.0, %NULL)
'-----------------------------------------
' Create first camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL )
PositionNode(cam, 0,1,-10)
'-----------------------------------
' simple text inside the scene area
LoadFont("media/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
TurnNode(cube, 0,1,0, 0)
' ---------------
' Render
' ---------------
BeginScene(128,128,128, 255, 1, 1)
DrawScene()
DrawText(font_, "SkyDome demo", 10,10,0,0, &h0ff00ffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 027 as Poursuite 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
'-----------------------------------------
' set ambient light
' _AmbientLight( &hffaaaaaa)
'----------------------------------------
' Create light And set position
DIM light AS LightNode
light = CreateLight(&h0ffffffff, 180, %ELT_POINT , %NULL)
PositionNode(light, 0,30,10)
' turn off MipMap
TextureCreation( %ETCF_CREATE_MIP_MAPS, %False )
'----------------------------------------
' Load 3D objects
DIM obj1 AS Mesh
obj1 = LoadMesh("media/plane.3ds", %HARDMAPPING.EHM_STATIC)
DIM obj2 AS Mesh
obj2 = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)
'-----------------------------------------
' Create plane
DIM plane AS EntityNode
plane = CreateEntityNode(obj1, 0, 0, 0, %NULL)
'-----------------------------------------
' Create sphere
DIM sphere AS EntityNode
sphere = CreateEntityNode(obj2, 0, 0, 0, %NULL)
PositionNode(sphere, 0,0.5,5)
ScaleNode(sphere, 1.5,1.5,1.5)
'-----------------------------------------
' Create arrow mesh
DIM obj3 AS Mesh
obj3 = CreateArrowMesh(4, 8, 1.0, 0.6, 0.05, 0.3, &h0ffffffff, &h0ffffffff)
ScaleMesh(obj3, 3,4,3)
RotateMesh(obj3, 90,0,0)
' And the node associed
DIM cc AS EntityNode
cc = CreateEntityNode(obj3, 0, 0, 0, %NULL)
PositionNode(cc, 0,5,0)
PointNode(cc, sphere, 0)
'-----------------------------------------
' Create first camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, 0,10,-15)
TurnNode(cam, 15,0,0, 0)
'-----------------------------------
' Load font png
LoadFont("media/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
' control earth
IF GetKeyDown(%KEY_CODE.KEY_ARROW_UP) THEN
TranslateNode(sphere, 0,0,0.5)
PointNode(cc, sphere, 0)
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_DOWN) THEN
TranslateNode(sphere, 0,0,-0.5)
PointNode(cc, sphere, 0)
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_RIGHT) THEN
TranslateNode(sphere, 0.5,0,0)
PointNode(cc, sphere, 0)
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_LEFT) THEN
TranslateNode(sphere, -0.5,0,0)
PointNode(cc, sphere, 0)
END IF
IF GetKeyDown(%KEY_CODE.KEY_KEY_R) THEN
TranslateNode(sphere, 0,0.5,0)
PointNode(cc, sphere, 0)
END IF
IF GetKeyDown(%KEY_CODE.KEY_KEY_F) THEN
TranslateNode(sphere, 0,-0.5,0)
PointNode(cc, sphere, 0)
END IF
IF GetMouseEvent(%MOUSE_EVENT.MOUSE_BUTTON_LEFT) THEN
DIM angley AS SINGLE
angley = GetDeltaMouseX(0) / 4.0
DIM anglex AS SINGLE
angley = GetDeltaMouseY(0) / 4.0
TurnNode(cam, anglex, angley, 0, 0)
END IF
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
DrawText(font_, "DirKey and R/F for move earth", 10,10,0,0, &h0ff00ffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 029 as Water demo.
' 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
'----------------------------------------
' Load 3D objects
DIM obj AS Mesh
obj = LoadMesh("media/room.3ds", %HARDMAPPING.EHM_STATIC)
'----------------------------------------
' Create traditional light And set position
DIM light AS LightNode
light = CreateLight(&h0ffaaaaaa, 250, %ELT_POINT , %NULL)
PositionNode(light, 0,100,0)
'----------------------------------------
'----------------------------------------
' Create ROOM
DIM room AS EntityNode
room = CreateEntityNode(obj, 0, 0, 0, %NULL)
' Load two textures
DIM colormap AS NTexture
colormap = LoadTexture( "media/wall0.jpg")
' change planar texture mapping on the mesh
MakePlanarTextureMappingMesh(obj, 0.004)
' set texture in the New room (room2)
MaterialTextureNode(room, colormap , 0)
' set material For room parallax mapping
DIM material AS NMaterial
material = NodeMaterial(room, 0)
SpecularColorMaterial(material, 0)
'----------------------------------------
'----------------------------------------
' Create one hillmesh
DIM hillMesh AS Mesh
hillMesh = CreateHillPlaneMesh(20,20, 40,40, %Null, 0, 0, 0,10,10)'
' Create WaterNode
DIM water AS EntityNode
water = CreateWater(hillMesh, 3.0, 300.0, 30.0, 0)
PositionNode(water, 0,7,0)
'
LoadTextureNode(water, "media/glass.bmp", 0, 0)
'_LoadTextureNode(water, "media/water1.jpg", 0, 0)
LoadTextureNode(water, "media/water.jpg", 0, 1)
'
'_MaterialTypeNode(water, EMT_REFLECTION_2_LAYER)
MaterialTypeNode(water, %EMT_TRANSPARENT_REFLECTION_2_LAYER)
'
'_ScaleTCoordsMesh(hillMesh, 4.0, 4.0, 2)
'_MakePlanarTextureMappingMesh(hillMesh, 0.02)
'----------------------------------------
'----------------------------------------
' Create a camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam, -95,155,-263)
TurnNode(cam, 17,15,0, 0)
' simple text inside the scene area
LoadFont("media/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(0, 0, 0, 255, 1, 1)
DrawScene()
DrawText(font_, "water demo", 10,10,0,0, &h0ff9999ff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 030 : Fighter demo.
' Historique :
' 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
'-----------------------------------------
' Create light And set position
DIM light AS LightNode
light = CreateLight(&h0ffffffff, 400, %ELT_POINT, %NULL)
PositionNode(light, 0,150,10)
'----------------------------------------
' Load 3D objects
DIM obj1 AS Mesh
obj1 = LoadMesh("media/land.x", %HARDMAPPING.EHM_STATIC)
DIM obj2 AS Mesh
obj2 = LoadMesh("media/su47.x", %HARDMAPPING.EHM_STATIC)
RotateMesh(obj2, 0,90,0)
ScaleMesh(obj2, 0.02,0.02,0.02)
'-----------------------------------------
' Create plane
DIM plane AS EntityNode
plane = CreateEntityNode(obj1, 0, 0, 0, %NULL)
'-----------------------------------------
' Create fighter
DIM fighter AS EntityNode
fighter = CreateEntityNode(obj2, 0, 0, 0, %NULL)
PositionNode(fighter, 0,10,0)
'-----------------------------------------
' add a little arm, no ?
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(1.0)
DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0,-1.3,0, fighter)
ScaleNode(cube, 0.75, 0.75, 2)
'-----------------------------------------
' Create first camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, 0,17,-18)
'-----------------------------------
' Load font png
LoadFont("media/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
Movenode(fighter, 0,0,0.2, %COLLIDE_RESPONSE.RESP_NONE)
' control fighter
IF GetKeyDown(%KEY_CODE.KEY_ARROW_UP) THEN
TurnNode(fighter, 2,0,0, %RT_QUATERNION )
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_DOWN) THEN
TurnNode(fighter, -2,0,0, %RT_QUATERNION )
END IF
IF GetKeyDown(%KEY_CODE.KEY_Key_B) THEN
TurnNode(fighter, 0,2,0, %RT_QUATERNION )
END IF
IF GetKeyDown(%KEY_CODE.KEY_Key_V) THEN
TurnNode(fighter, 0,-2,0, %RT_QUATERNION )
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_LEFT ) THEN
TurnNode(fighter, 0,0, 2, %RT_QUATERNION )
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_RIGHT) THEN
TurnNode(fighter, 0,0,-2, %RT_QUATERNION )
END IF
PointNode( cam, fighter, 0)
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
DrawText(font_, "DirKey and V/B for move fighter", 10,10,0,0, &h0ff00ffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Hello,
Include many new bug
regards Peter
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 031 as simple lightmapping 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
'---------------------------
' define a ManualContruct Mesh
DIM mesh_ AS Mesh
' Create empty mesh
mesh_ = CreateEmptyMesh(%VERTEX_TYPE.EVT_2TCOORDS)
' 3 first vertices
DIM v1 AS LONG
v1 = AddVertexMesh(mesh_, 0, 0,0,0, 0, 0, 0, &h0ffffffff, 0, 0, 0, 0)
DIM v2 AS LONG
v2 = AddVertexMesh(mesh_, 0, 2,2,0, 0, 0, 0, &h0ffffffff, 0, 0, 0, 0)
DIM v3 AS LONG
v3 = AddVertexMesh(mesh_, 0, 2,0,0, 0, 0, 0, &h0ffffffff, 0, 0, 0, 0)
' first face
AddFaceMesh(mesh_, 0, v1,v2,v3)
' 3 Next vertices
DIM v4 AS LONG
v4 = AddVertexMesh(mesh_, 0, 0,2,0, 0, 0, 0, &h0ffffffff, 0, 0, 0, 0)
DIM v5 AS LONG
v5 = AddVertexMesh(mesh_, 0, 2,2,0, 0, 0, 0, &h0ffffffff, 0, 0, 0, 0)
DIM v6 AS LONG
v6 = AddVertexMesh(mesh_, 0, 0,0,0, 0, 0, 0, &h0ffffffff, 0, 0, 0, 0)
' second face
AddFaceMesh(mesh_, 0, v4,v5,v6)
' texture coordinate layer 0
VertexTexCoord1Mesh( mesh_, 0,0, 0, 1)
VertexTexCoord1Mesh( mesh_, 0,1, 1, 0)
VertexTexCoord1Mesh( mesh_, 0,2, 0, 0)
VertexTexCoord1Mesh( mesh_, 0,3, 1, 1)
VertexTexCoord1Mesh( mesh_, 0,4, 1, 0)
VertexTexCoord1Mesh( mesh_, 0,5, 0, 1)
' texture coordinate layer 1 ( the same in this Case)
VertexTexCoord2Mesh( mesh_, 0,0, 0, 1)
VertexTexCoord2Mesh( mesh_, 0,1, 1, 0)
VertexTexCoord2Mesh( mesh_, 0,2, 0, 0)
VertexTexCoord2Mesh( mesh_, 0,3, 1, 1)
VertexTexCoord2Mesh( mesh_, 0,4, 1, 0)
VertexTexCoord2Mesh( mesh_, 0,5, 0, 1)
'
DIM entitymesh AS EntityNode
entitymesh = CreateEntityNode(mesh_, 0, 0, 0, %NULL)
' set material of the mesh with EMT_LIGHTMAP mode
MaterialTypeNode(entitymesh, %EMT_LIGHTMAP )
' Load two textures
DIM colormap AS NTexture
colormap = LoadTexture( "media/rockwall.bmp")
DIM lightmap AS NTexture
lightmap = LoadTexture( "media/lightmap.bmp")
' set two texture layer
MaterialTextureNode(entitymesh, colormap , 0)
MaterialTextureNode(entitymesh, lightmap , 1)
' Create a camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, 0,0,-4)
' ---------------------------------------
' Main loop
' ---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
TurnNode(entitymesh,0,0.5,0, 0)
' ---------------
' Render
' ---------------
BeginScene(30,20,10, 255, 1, 1)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 033 as sprite3D code.
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
FUNCTION PBMAIN
' Dimes
DIM app AS DWORD
DIM Quit AS LONG
'----------------------------------------------------------
' open n3xt-D screen
app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app = %NULL THEN
EXIT FUNCTION
END IF
'----------------------------------------
' Load 3D objects
DIM obj1 AS Mesh
obj1 = LoadMesh("media/plane.3ds", %HARDMAPPING.EHM_STATIC)
'-----------------------------------------
' Create plane
DIM plane AS EntityNode
plane = CreateEntityNode(obj1, 0, 0, 0, %NULL)
ScaleNode(plane, 2,2,2)
'----------------------------------------
'-----------------------------------------
' Create billboard
DIM spMesh AS Mesh
spMesh = CreateSpriteMesh( 8.0, &h022ffffff)
DIM i AS LONG
FOR i = 0 TO 64
DIM spG AS SpriteSceneNode
spG = CreateSprite3D(spMesh, "media/grass.bmp", %NULL)
PositionNode(spG, -40+RND()*80,11, -40+RND()*80)
MaterialTypeNode(spG, %EMT_TRANSPARENT_ALPHA_CHANNEL)
OrientationSprite3D(spG,1)
NEXT
'-----------------------------------------
' Create first camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL )
PositionNode(cam, 0,25,-60)
'-----------------------------------
' Load font png
LoadFont("media/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(100,100,100, 255, 1, 1)
DrawScene()
DrawText(font_, "Sprite3D demo", 10,10,0,0, &h0ff00ffff)
DrawText(font_, "Primitives as "+ STR$(PrimitiveCountDrawn() ) , 10,45,0,0, &h0ffffffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Hello,
Include many new bug
regards Peter
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 034 as test primitives 3D.
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
FUNCTION PBMAIN
' Dimes
DIM app AS DWORD
DIM Quit AS LONG
'----------------------------------------------------------
' 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 first camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam, 0,0,-60)
' ---------------------------------------
' define primitives 3D
DIM tri(9) AS SINGLE
tri(0)=20 : tri(1)=0 : tri(2)=0
tri(3)=20 : tri(4)=10 : tri(5)=0
tri(6)=30 : tri(7)=10 : tri(8)=0
DIM BOX(6) AS SINGLE
BOX(0)=-10 : BOX(1)=-10 : BOX(2)=-10
BOX(3)=10 : BOX(4)=10 : BOX(5)=10
DIM angle AS SINGLE
angle = 0
' ---------------------------------------
' Main loop
' ---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
angle = angle + 1
' ---------------
' Render
' ---------------
BeginScene(100,100,100, 255, 1, 1)
DrawScene()
SituatePrimitive3D(0, 0, 0, 0, 0, 0)
DrawTriangle3D(tri(0), &h0fff0000)
DrawLine3D(0,0,0,20,10,0, &h0ff0000ff)
SituatePrimitive3D( 0,0,0, 0,angle,0)
DrawBox3D(BOX(0), &h0ff00ff00)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
'
' Sample 035 as Picking Test.
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
DECLARE SUB DrawTriangle()
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 single sphere
DIM mesh_ AS Mesh
mesh_ = CreateSphereMesh(5,16)
DIM sphere AS EntityNode
sphere = CreateEntityNode(mesh_, 0, 0, 0, %NULL)
'-----------------------------------------
' Create first camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL )
PositionNode(cam, 0,0,-10)
'-----------------------------------
' Load font png
LoadFont("media/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
IF GetMouseEvent(%MOUSE_EVENT.MOUSE_BUTTON_LEFT) THEN
DIM node AS EntityNode
node = PickCamera(cam, GetMouseX(), GetMouseY(), %ENT_PICKFACE, 5000.0)
END IF
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
DrawTriangle()
DrawText(font_, "FPS as "+ STR$(FPS()) , 10,10,0,0, &h0ff00ffff)
DrawText(font_, "use click mouse for pick mesh as " , 10,25,0,0, &h0ff00ffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
SUB DrawTriangle()
DIM tri(0 to 8) AS SINGLE
Pickedtriangle (tri(0))
DrawTriangle3D(tri(0), &h0ffffff00)
END SUB
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 036 as Ray Collide Test And
' used Octtree system For large model
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
DECLARE SUB DrawTriangle()
FUNCTION PBMAIN
' Dimes
DIM app AS DWORD
DIM Quit AS LONG
'----------------------------------------------------------
' open n3xt-D screen
app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app = %NULL THEN
EXIT FUNCTION
END IF
'-----------------------------------
' add in memory management system a zip file
AddZipFileArchive( "media/chiropteradm.pk3" )
'-----------------------------------
' Load Quake3 scene Object
DIM obj AS Mesh
obj = LoadMesh("chiropteradm.bsp", %HARDMAPPING.EHM_STATIC)
' Create a mesh with one of the 3D Object loaded
' dim quake as EntityNode = _CreateEntityNode(obj)
DIM quake AS EntityNode
quake = CreatePopNodes(obj, %NULL)
'-----------------------------------------
' Create first camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam, 0,20,-50)
'-----------------------------------
' Load font png
LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
DIM font_ AS IGUIFont
font_ = GetFont()
'-----------------------------------
' define 3D Line ray test
DIM Lstart AS iVECTOR3
DIM Lend AS iVECTOR3
Lstart.x=0 : Lstart.y=30 : Lstart.z=0
Lend.x=0 : Lend.y=-70 : Lend.z=0
' ---------------------------------------
' Main loop
' ---------------------------------------
DIM a AS STRING
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
DIM res_ AS INTEGER
res_ = CollisionPoint(Lstart.x, Lstart.y, Lstart.z, Lend.x, Lend.y, Lend.z, quake)
a = "collision result = " + STR$(res_)
END IF
' move ray
IF GetKeyDown(%KEY_CODE.KEY_KEY_H) THEN
Lstart.x = Lstart.x+1
Lend.x = Lend.x+1
END IF
IF GetKeyDown(%KEY_CODE.KEY_KEY_G) THEN
Lstart.x = Lstart.x-1
Lend.x = Lend.x-1
END IF
IF GetKeyDown(%KEY_CODE.KEY_KEY_Y) THEN
Lstart.z = Lstart.z+1
Lend.z = Lend.z+1
END IF
IF GetKeyDown(%KEY_CODE.KEY_KEY_B) THEN
Lstart.z = Lstart.z-1
Lend.z = Lend.z-1
END IF
' ---------------
' Render
' ---------------
BeginScene(250,250,250, 255, 1, 1)
DrawScene()
DrawTriangle()
DrawLine3D(Lstart.x, Lstart.y, Lstart.z, Lend.x, Lend.y, Lend.z, &h0ff0000ff)
DrawText(font_, "FPS as "+ TRIM$(STR$(FPS())) , 10,10,0,0, &hff00ffff)
DrawText(font_, "Dir key and mous/Left-click for move camera", 10,25,0,0, &h0ffff00ff)
DrawText(font_, "H/G/Y/B for move Ray and SpaceKey for test collide", 10,40,0,0, &h0ffff00ff)
DrawText(font_, "Primitives as "+ STR$(PrimitiveCountDrawn()) , 10,55,0,0, &h0ffffffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
SUB DrawTriangle()
DIM tri(8) AS SINGLE
Pickedtriangle (tri(0))
DrawTriangle3D( tri(0), &h0ffff0000)
END SUB
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 038 : Occlusion Test.
' Historique :
' 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, %FALSE, %FALSE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app = %NULL THEN
EXIT FUNCTION
END IF
'---------------------------------------------
' Create light And set position
DIM light AS LightNode
light = CreateLight( &h0ffffffff, 50, %ELT_POINT , %NULL)
PositionNode(light, 0,5,-20)
'---------------------------------------------
' Create mesh
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(1.0)
DIM spheremesh AS Mesh
spheremesh = CreateSphereMesh(1.0, 32)
DIM cylindermesh AS Mesh
cylindermesh = CreateCylinderMesh(1.0, 3.0, &h0ffffffff, 8, %True, 0)
'---------------------------------------------
' Create a cube And set position
DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
ScaleNode(cube, 8,8,1)
PositionNode(cube, -1,0,-5)
'---------------------------------------------
' Create 12 sphere entities, with occlusion
' system test
DIM i AS LONG, j AS LONG
FOR i =0 TO 3
FOR j = 0 TO 3
DIM sphere AS EntityNode
sphere = CreateEntityNode(spheremesh, 0, 0, 0, %NULL)
PositionNode(sphere, -1.5+i, -1.5+j,0)
LoadTextureNode(sphere, "media/five.bmp", 0, 0)
AddOcclusionQuery(sphere, spheremesh)
NEXT
NEXT
'---------------------------------------------
' Create a cylinder entity And set position
DIM cylinder AS EntityNode
cylinder = CreateEntityNode(cylindermesh, 0, 0, 0, %NULL)
PositionNode(cylinder, 2,2,0)
' Create a camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80, 0.03, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam, 0,0,-20)
'-----------------------------------
' Load font png
LoadFont("media/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(128,128,128, 255, 1, 1)
DrawScene()
DrawText(font_, "Move arround the plane, FPS : "+ TRIM$(STR$(FPS())) , 10,25,0,0, &h0ffffffff)
DrawText(font_, "Primitives: "+ TRIM$(STR$(PrimitiveCountDrawn())) , 10,45,0,0, &h0ffffffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Hello,
Include many new bug
regards Peter
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 039 as Animate Texture.
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
FUNCTION PBMAIN
' Dimes
DIM app AS DWORD
DIM Quit AS LONG
'----------------------------------------------------------
' 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 cube And set position
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(2.0)
DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
DIM texturelist AS NArray
texturelist = CreateListTexture("media/ball2.png", 64,64)
'dim texturelist as NArray = _CreateListTexture("media/canvas.bmp", 32,32)
DIM anim AS NNodeAnimator
anim = CreateTextureAnimator( texturelist, 50, %TRUE)
' add inside the node the animator Texture animator)
AddAnimatorTexture(cube, anim)
'-----------------------------------------
' 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)
' ---------------------------------------
' Main loop
' ---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
TurnNode(cube, 0.3,0.3,0, 0)
' ---------------
' Render
' ---------------
BeginScene(200,200,200, 255, 1, 1)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Thank you for your hard work Peter. N3xtD seem like a fun package.
Jim
Hello James,
Thank you :). It gives me a lot of fun to work through that. If you work with it and give me notice an error occurs. I still have the problem with the delivery of optional parameters and variables that do can not be solved in PowerBASIC! :'( This is just only with Visual Basic and FreeBasic >:(
regards Peter
good job peter, I like your efforts! :)
It's a special interests library N3xtD, but very interesting stuff to play with. I've tried in springtime to adept Irrlichtwrapper library for pbwin 9 (with a friend he's programming on freebasic), but there's a certain amount of differences between freebasic and powerbasic languages (for example: "enum... end enum", "type... end type" blocks statements and the using of "equates") I've nearly managed to convert (translate) 80 per Cent of Irrlichtwrapper from freebasic to powerbasic, but I will wait until I am updating to pbwin 10. I hope that's the converting problems are decreasing to zero. It's a time problem too for me to work at this bigger job, but I will do that in nearby future. thanks. I've not tested yet your N3xtD.bi but I will check it next time and try to help if there are error messages.
one suggestion:
If you have updates of your library send all to your first post (include file and scene examples).
2) freebasic uses for example enum..end enum like type..end type block statements:
Quote
ENUM IRR_EGUI_EVENT_TYPE
' A gui element has lost its focus.
EGET_ELEMENT_FOCUS_LOST = 0',
' A gui element has got the focus.
EGET_ELEMENT_FOCUSED
' The mouse cursor hovered over a gui element.
EGET_ELEMENT_HOVERED
' The mouse cursor left the hovered element.
EGET_ELEMENT_LEFT
' An element would like to close.
EGET_ELEMENT_CLOSED
' A button was clicked.
EGET_BUTTON_CLICKED
' A scrollbar has changed its position.
EGET_SCROLL_BAR_CHANGED
' A checkbox has changed its check state.
EGET_CHECKBOX_CHANGED
' A new item in a listbox was seleted.
EGET_LISTBOX_CHANGED
' An item in the listbox was selected, which was already selected.
EGET_LISTBOX_SELECTED_AGAIN
' A file has been selected in the file dialog
EGET_FILE_SELECTED
' A directory has been selected in the file dialog
EGET_DIRECTORY_SELECTED
' A file open dialog has been closed without choosing a file
EGET_FILE_CHOOSE_DIALOG_CANCELLED
' 'Yes' was clicked on a messagebox
EGET_MESSAGEBOX_YES
' 'No' was clicked on a messagebox
EGET_MESSAGEBOX_NO
' 'OK' was clicked on a messagebox
EGET_MESSAGEBOX_OK
' 'Cancel' was clicked on a messagebox
EGET_MESSAGEBOX_CANCEL
' In an editbox 'ENTER' was pressed
EGET_EDITBOX_ENTER
' The text in an editbox was changed. This does not include automatic changes in text-breaking.
EGET_EDITBOX_CHANGED
' The marked area in an editbox was changed.
EGET_EDITBOX_MARKING_CHANGED
' The tab was changed in an tab control
EGET_TAB_CHANGED
' A menu item was selected in a (context) menu
EGET_MENU_ITEM_SELECTED
' The selection in a combo box has been changed
EGET_COMBO_BOX_CHANGED
' The value of a spin box has changed
EGET_SPINBOX_CHANGED
' A table has changed
EGET_TABLE_CHANGED
EGET_TABLE_HEADER_CHANGED
EGET_TABLE_SELECTED_AGAIN
' A tree view node lost selection. See IGUITreeView::getLastEventNode().
EGET_TREEVIEW_NODE_DESELECT
' A tree view node was selected. See IGUITreeView::getLastEventNode().
EGET_TREEVIEW_NODE_SELECT
' A tree view node was expanded. See IGUITreeView::getLastEventNode().
EGET_TREEVIEW_NODE_EXPAND
' A tree view node was collapsed. See IGUITreeView::getLastEventNode().
EGET_TREEVIEW_NODE_COLLAPS
' No real event. Just for convenience to get number of events
EGET_COUNT
END ENUM
TYPE IRR_GUI_EVENT
id AS INTEGER
' event as IRR_EGUI_EVENT_TYPE ' that's not possible with Powerbasic !
x AS INTEGER
y AS INTEGER
END TYPE
but if you're calling "IRR_GUI_EVENT" Powerbasic doesn't accept "event" as "IRR_EGUI_EVENT" (last part) and there are few more problems but I am looking for a good solution to solve these problems.
best regards, frank
Hello Frank,
Give me the Organal include file. I want to watch it once in Enum type that goes to Free Basic but not because the data width of the constant is not well known!
But I would like to view the original file FreeBasic times. Who do you send me it might perhaps I can help! :)
regards Peter
Hello,
Include many new bug
regards Peter
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 040 as first terrain sample.
' 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
'------------------------------------------------------------------------------------
DIM terrain AS TerrainNode
terrain = CreateTerrain("media/height113.bmp", 1, 2.0, 0.45,2.0, 32, %TRUE, %HARDMAPPING.EHM_STATIC)
TextureTerrain(terrain, 0 , "media/Sol113.jpg", -1, -1)
TextureTerrain(terrain, 1 , "media/detailmap3.jpg", -1, -1)
MaterialTypeNode(terrain, %EMT_LIGHTMAP_M2)
'_DebugModeNode(terrain, True)
'------------------------------------------------------------------------------------
' Create a camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam, 100,70,100)
'-----------------------------------
' Load font png
LoadFont("media/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
'--------------------------------------------------------
' terrain picking zone test
IF GetMouseEvent(%MOUSE_EVENT.MOUSE_BUTTON_RIGHT) THEN
DIM res_ AS INTEGER
res_ = PickTerrain(terrain)
IF res_ THEN
DIM pPos(4) AS SINGLE
TerrainPickedPosition(terrain, ppos(0))
HeightTerrain(terrain, 16.0, ppos(0), ppos(2), 1.0, %TH_UP)
END IF
END IF
' ---------------
' Render
' ---------------
BeginScene(1,128,128, 255, 1, 1)
DrawScene()
DrawText(font_, "Right click mouse to change height of terrain" , 10,5,0,0, &h0ffffffff)
DrawText(font_, "FPS as "+ TRIM$(STR$(FPS())), 10,25,0,0, &h0ffffffff)
DrawText(font_, "Primitives as "+ TRIM$(STR$(PrimitiveCountDrawn())), 10,45,0,0, &h0ffffffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 041 : terrain with light.
' Historique :
' 29/03/09 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
'------------------------------------------------------------------------------------
' Create light And set position
DIM light AS LightNode
light = CreateLight(&h0ffffffff, 256.0, %ELT_POINT, %NULL)
PositionNode(light, 50,100,50)
'------------------------------------------------------------------------------------
DIM terrain AS TerrainNode
terrain = CreateTerrain("media/height113.bmp", 1, 2.0, 0.45, 2.0, 32, %TRUE, %HARDMAPPING.EHM_STATIC)
TextureTerrain(terrain, 0 , "media/Sol113.jpg", -1, -1)
TextureTerrain(terrain, 1 , "media/detailmap3.jpg", -1, -1)
MaterialTypeNode(terrain, %EMT_LIGHTMAP_LIGHTING_M2)
'_DebugModeNode(terrain, TRUE)
'------------------------------------------------------------------------------------
' Create a camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam, 100,80,100)
'-----------------------------------
' Load font png
LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
DIM font_ AS IGUIFont
font_ = GetFont()
' ---------------------------------------
' Main loop
' ---------------------------------------
DIM hh AS SINGLE
WHILE Quit = 0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' move camera with dir key And mouse (Left click)
IF GetKeyDown(%KEY_CODE.KEY_ARROW_LEFT) THEN
hh = TerrainHeight(terrain, NodeX(cam), NodeZ(cam), 0)+10.0
PositionNode(cam, NodeX(cam), hh, NodeZ(cam))
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_RIGHT) THEN
hh= TerrainHeight(terrain, NodeX(cam), NodeZ(cam), 0)+10.0
PositionNode(cam, NodeX(cam), hh, NodeZ(cam))
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_UP) THEN
hh = TerrainHeight(terrain, NodeX(cam), NodeZ(cam), 0)+10.0
PositionNode(cam, NodeX(cam), hh, NodeZ(cam))
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_DOWN) THEN
hh= TerrainHeight(terrain, NodeX(cam), NodeZ(cam), 0)+10.0
PositionNode(cam, NodeX(cam), hh, NodeZ(cam))
END IF
' ---------------
' Render
' ---------------
BeginScene(1,128,128, 255, 1, 1)
DrawScene()
DrawText(font_, "FPS : " + TRIM$(STR$(FPS())), 10,25,0,0, &h0ffffffff)
DrawText(font_, "Primitives: "+ TRIM$(STR$(PrimitiveCountDrawn())) , 10,45,0,0, &h0ffffffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 042: terrain splatting
' Historique :
' 29/03/09 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
DIM light AS LightNode
light = CreateLight(&h0ffff0000, 256.0, %ELT_POINT , %NULL)
PositionNode(light, 50,100,50)
'------------------------------------------------------------------------------------
DIM terrain AS TerrainNode
terrain = CreateTerrain("media/aterrain1.bmp", %TQ_MEDIUM, 2.0, 0.35, 2.0, 4, %TRUE, %HARDMAPPING.EHM_STATIC)
SplattingTerrain(terrain, -500.0, &hffffffff)
DIM alphamap AS NTexture
alphamap = TextureTerrain(terrain, 0,"media/alpha1.bmp", -1, -1)
TextureTerrain(terrain, 1,"media/025.jpg", -1, -1)
TextureTerrain(terrain, 2,"media/stone.bmp", -1, -1)
TextureTerrain(terrain, 3,"media/splatting3.png", -1, -1)
TextureTerrain(terrain, 4,"media/dirt.bmp", -1, -1)
TextureTerrain(terrain, 5,"media/detailmap3.jpg", -1, -1)
'_TextureTerrain(terrain, 6,"media/lightmap.jpg")
'------------------------------------------------------------------------------------
' Create a camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam, -100,280,-100)
'-----------------------------------
' Load font png
LoadFont("media/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
'--------------------------------------------------------
' terrain picking zone test
IF GetMouseEvent(%MOUSE_EVENT.MOUSE_BUTTON_RIGHT) THEN
DIM res_ AS INTEGER
res_ = PickTerrain(terrain)
IF res_ THEN
DIM pPos(4) AS SINGLE
TerrainPickedPosition(terrain, pPos(0))
WriteTextureTerrain(terrain, alphamap, pPos(0), pPos(2), 8, &h0ffff0000)
END IF
END IF
' ---------------
' Render
' ---------------
BeginScene(1,128,128, 255, 1, 1)
DrawScene()
DrawText(font_, "Right click mouse on terrain to change texture splat" , 10,5,0,0, &h0ffffffff)
DrawText(font_, "FPS : " + TRIM$(STR$(FPS())), 10,25,0,0, &h0ffffffff)
DrawText(font_, "Primitives: "+ TRIM$(STR$(PrimitiveCountDrawn())), 10, 45, 0, 0, &h0ffffffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Hello,
Include many new bug
regards Peter
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 043 : 10.000 grass element with wind simulation
' Historique :
' 29/03/09 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")
'----------------------------------------
' Load 3D objects
DIM obj1 AS Mesh
obj1 = LoadMesh("plane.3ds", %HARDMAPPING.EHM_STATIC)
'-----------------------------------------
' Create plane
DIM plane AS EntityNode
plane = CreateEntityNode(obj1, 0, 0, 0, %NULL)
ScaleNode(plane, 6,5,6)
'----------------------------------------
'----------------------------------------
' grass zone
DIM spritemesh AS Mesh
spritemesh = LoadMesh("grass1.3ds", %HARDMAPPING.EHM_STATIC)
ScaleMesh(spritemesh, 0.15, 0.1, 0.15)
DIM staticArea AS EntityNode
staticArea = CreateBatchNode(spritemesh, %EMT_TRANSPARENT_ALPHA_CHANNEL_REF, %TRUE, %NULL)
WindValueBatchZone(staticArea, 0.10, 30)
DIM k AS LONG
DIM x AS SINGLE, z AS SINGLE, sac AS SINGLE
FOR k = 0 TO 10000
x = -140+RND()*280
z = -140+RND()*280
sac = 0.65 + RND()*0.55
AddBatchElement(staticArea, x, 6.5 ,z, 0,0,0, sac,1,sac)
NEXT
'_DebugModeNode(staticArea, DEBUG_BBOX )
'----------------------------------------
' def camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam, 0, 20, -0)
'-----------------------------------
' 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(128,128,128, 255, 1, 1)
DrawScene()
DrawText(FONT_, "FPS : " + TRIM$(STR$(FPS())) , 10,25,0,0, &h0ffffffff)
DrawText(FONT_, "Primitives: "+ TRIM$(STR$(PrimitiveCountDrawn())) , 10,45,0,0, &h0ffffffff)
DrawText(FONT_, "10.000 grass element with wind simulation", 10,65,0,0, &h0ffffffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 044 as LOD Entity system
' 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
' Load the different mesh To construct LOD dim mesh
DIM earthMesh1 AS Mesh
earthMesh1 = LoadMesh("media/sphereLOD1.3ds", %HARDMAPPING.EHM_STATIC)
DIM earthMesh2 AS Mesh
earthMesh2 = LoadMesh("media/sphereLOD2.3ds", %HARDMAPPING.EHM_STATIC)
DIM earthMesh3 AS Mesh
earthMesh3 = LoadMesh("media/sphereLOD3.3ds", %HARDMAPPING.EHM_STATIC)
DIM earthMesh4 AS Mesh
earthMesh4 = LoadMesh("media/sphereLOD4.3ds", %HARDMAPPING.EHM_STATIC)
DIM earthMesh5 AS Mesh
earthMesh5 = LoadMesh("media/sphereLOD5.3ds", %HARDMAPPING.EHM_STATIC)
DIM earthMesh6 AS Mesh
earthMesh6 = LoadMesh("media/sphereLOD6.3ds", %HARDMAPPING.EHM_STATIC)
'----------------------------------------
DIM hillmesh AS Mesh
hillmesh = CreateHillPlaneMesh(10.0, 10.0, 10, 10, %NULL, 0, 0, 0, 1, 1)
' quick ground
DIM hillplane AS EntityNode
hillplane = CreateEntityNode(hillmesh, 0, 0, 0, %NULL)
LoadTextureNode(hillplane, "media/wall.jpg", 0, 0)
DistanceLOD( 80.0, 150.0, 210.0, 250.0, 280.0, 320.0)
'----------------------------------------
' one entitynode LOD setting
DIM entitylod AS EntityNode
entitylod = CreateLODEntityNode(earthMesh1, 0)
AddMeshLODEntityNode(entitylod, earthMesh2, 1 )
AddMeshLODEntityNode(entitylod, earthMesh3, 2 )
AddMeshLODEntityNode(entitylod, earthMesh4, 3 )
AddMeshLODEntityNode(entitylod, earthMesh5, 4 )
AddMeshLODEntityNode(entitylod, earthMesh6, 5 )
PositionNode(entitylod, 80,80,0)
'----------------------------------------
' set static zone with entitynode LOD setting
DIM lod AS EntityNode
lod = CreateStaticZone(earthMesh1, %NULL)
SetLODStaticZoneEntityNode(lod, earthMesh2, 1 )
SetLODStaticZoneEntityNode(lod, earthMesh3, 2 )
SetLODStaticZoneEntityNode(lod, earthMesh4, 3 )
SetLODStaticZoneEntityNode(lod, earthMesh5, 4 )
SetLODStaticZoneEntityNode(lod, earthMesh6, 5 )
DIM cube AS EntityNode
DIM i AS INTEGER
FOR i = 0 TO 60
DIM sac AS SINGLE
sac = RND()*10+5
sac=sac/10.0
AddElementStaticZone(lod, RND()*150.0-75 ,0, RND()*150.0-75, 0,0,0, sac,sac,sac)
NEXT
DebugModeNode(lod, %DEBUG_BBOX )
' Create a camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam, 0,50,-40)
'-----------------------------------
' Load font png
LoadFont("media/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(0, 0, 0, 255, 1, 1)
DrawScene()
DrawText(font_, "FPS as "+ TRIM$(STR$(FPS())), 10,25,0,0, &h0ffffffff)
DrawText(font_, "Primitives as "+ TRIM$(STR$(PrimitiveCountDrawn())), 10,45,0,0, &h0ffffffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Hello,
Include many new bug
regards Peter
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 045 as Little2D game
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
DECLARE SUB Init()
DECLARE SUB CreateMeteor(rad AS SINGLE, numcol AS LONG)
DECLARE SUB CreateProjectil()
DECLARE SUB UpdatePlayer()
DECLARE SUB UpdateMeteor()
DECLARE SUB UpdateExplode()
DECLARE SUB UpdateProjectil()
DECLARE SUB DeathPlayer()
DECLARE SUB RenderAllSprite2D()
DECLARE SUB DeleteProjectil(num AS LONG)
DECLARE FUNCTION CollideProjectil(numProj AS LONG) AS LONG
DECLARE SUB GenerateExplode(COL AS LONG)
DECLARE SUB DeleteMeteor(num AS LONG)
DECLARE FUNCTION CollideMeteor(numMeteor AS LONG) AS LONG
'{ Player definition
'--}
TYPE PLAYER
sp AS Sprite2D
posx AS SINGLE
posy AS SINGLE
radius AS SINGLE
END TYPE
'{ Meteor definition
TYPE METEOR
sprite AS Sprite2D
posx AS SINGLE
posy AS SINGLE
transx AS SINGLE
transy AS SINGLE
vcreated AS LONG
radius AS SINGLE
END TYPE
'--}
'{ Projectil definition
TYPE BALL
sprite AS Sprite2D
posx AS SINGLE
posy AS SINGLE
transx AS SINGLE
transy AS SINGLE
created AS LONG
radius AS SINGLE
END TYPE
'--}
'{ Explode definition
TYPE EXPLO
sp AS Sprite2D
anim AS NNodeAnimator
posx AS SINGLE
posy AS SINGLE
END TYPE
'--}
%MAXEXPLODE = 8
FUNCTION PBMAIN
' dimes
DIM app AS DWORD
DIM Quit AS LONG
'----------------------------------------------------------
' open n3xt-D screen
app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app = %NULL THEN
EXIT FUNCTION
END IF
'----------------------------------------------------------
' Structures definition
'----------------------------------------------------------
DIM play_ AS GLOBAL PLAYER
DIM EndPlayer AS GLOBAL LONG
DIM speed_ AS GLOBAL SINGLE : speed_ = 10.0
DIM proj(17) AS GLOBAL BALL
DIM num_proj AS GLOBAL SINGLE
DIM meteorB(64) AS GLOBAL METEOR
DIM exp0(%MAXEXPLODE) AS GLOBAL EXPLO
DIM proj_matrix(16) AS GLOBAL SINGLE
DIM score AS GLOBAL LONG
DIM longerval_score AS GLOBAL LONG
LOCAL i AS LONG
'----------------------------------------------------------
'----------------------------------------------------------
' init all values And structures
Init()
'-----------------------------------------
'-----------------------------------------
' Create balll sprite
GLOBAL balll AS Sprite2D
balll = CreateSprite2D("media/Particle.png", 1.5, &h0ffffffff, %NULL)
MaterialTypeNode(balll, %EMT_TRANSPARENT_ALPHA_CHANNEL)
VisibleNode(balll, %False) ' no render
'-----------------------------------------
'-----------------------------------------
' Create PLAYER
play_.sp = CreateSprite2D("media/Space1.png", 1.0, &h0ffffffff, %NULL)
MaterialTypeNode(play_.sp, %EMT_TRANSPARENT_ALPHA_CHANNEL)
PositionNode(play_.sp, 0,0,1)
play_.radius = 40.0
'-----------------------------------------
'-----------------------------------------
' Create EXPLODE PLAYER
GLOBAL player_explode AS Sprite2D
player_explode = CreateSprite2D("media/Particle.png", 16.0, &h00ffffff, %NULL)
MaterialTypeNode(player_explode, %EMT_TRANSPARENT_VERTEX_ALPHA)
' Create explose sequance texture
DIM texturelist AS NArray
texturelist = CreateListTexture("media/explo2.bmp",64,64)
DIM anim AS NNodeAnimator
anim = CreateTextureAnimator( texturelist, 130, %true)
AddAnimatorTexture(player_explode, anim)
'-----------------------------------------
'-----------------------------------------
' Create thie first meteors
FOR i = 0 TO 7
CreateMeteor(50.0, -1)
NEXT
'-----------------------------------------
'-----------------------------------------
' Create first camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam,0,0,0)
'-----------------------------------------
'-----------------------------------
' Load background textures
DIM texture AS NTexture
texture = LoadTexture("media/metal13.jpg")
'-----------------------------------------
'-----------------------------------------
' Load fonts
LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
DIM font_ AS IGUIFont
font_ = GetFont()
LoadFont("media/font0.xml", %FONT_TYPE.EGDF_DEFAULT)
DIM font2 AS IGUIFont
font2 = GetFont()
'-----------------------------------------
'-----------------------------------------
' 3D elements
DIM boxmesh AS Mesh
boxmesh = CreateCubeMesh(50)
DIM box_ AS EntityNode
box_ = CreateEntityNode(boxmesh, 0, 0, 0, %NULL)
PositionNode(box_, 0,0,100)
LoadTextureNode(box_, "media/metal13.jpg", 0, 0)
'-----------------------------------------
' ---------------------------------------
' Main loop
' ---------------------------------------
'-----------------------------------------
WHILE Quit = 0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
TurnNode(box_,0,0.5,0.5, 0)
IF GetKeyDown(%KEY_CODE.KEY_ARROW_LEFT) THEN
TurnNode(play_.sp, 0,0,3, 0)
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_RIGHT) THEN
TurnNode(play_.sp, 0,0,-3, 0)
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_UP) THEN
MoveNode(play_.sp,0,-3,0, 0)
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_DOWN) THEN
MoveNode(play_.sp,0,3,0, 0)
END IF
IF GetKeyUp(%KEY_CODE.KEY_SPACE) THEN
CreateProjectil()
END IF
IF EndPlayer = 0 THEN
UpdatePlayer()
UpdateProjectil()
UpdateMeteor()
UpdateExplode()
ELSE
DeathPlayer()
END IF
' ---------------
' Render
' ---------------
BeginScene(20,20,20, 255, 1, 1)
' 3D render
DrawRectImage2D(texture , 0, 0, 0, 0, 800, 600, &h0ff777777, BYVAL %NULL, %FALSE)
DrawScene()
' 2D sprites render
Begin2D(800,600)
RenderSprite2D(play_.sp)
RenderAllSprite2D()
IF EndPlayer<>0 THEN RenderSprite2D(player_explode)
End2D()
DrawText(font_, "score: "+ TRIM$(STR$(score)), 10,10,0,0, &h0ffffffff)
DrawText(font_, "Use 'dir' and 'space' key", 450,8,0,0, &h0ff00ffff)
IF EndPlayer<>0 THEN
DrawText(font2, "END", 360,250,0,0, &h0ffffff00)
DrawText(font2, "score: "+ TRIM$(STR$(score)) , 350,310,0,0, &h0ffff00ff)
END IF
EndScene()
' ---------------
' End Render
' ---------------
WEND
' end
FreeEngine()
END FUNCTION
'-----------------------------------------
'-----------------------------------------
'-----------------------------------------
SUB RenderAllSprite2D()
DIM i AS LONG
FOR i = 0 TO 63
IF meteorB(i).vcreated <> 0 THEN
RenderSprite2D( meteorB(i).sprite)
END IF
NEXT
FOR i = 0 TO 16
IF proj(i).created <> 0 THEN
RenderSprite2D( proj(i).sprite)
END IF
NEXT
FOR i = 0 TO %MAXEXPLODE-1
IF(exp0(i).sp ) THEN
RenderSprite2D(exp0(i).sp)
END IF
NEXT
END SUB
'-----------------------------------------
'-----------------------------------------
'-----------------------------------------
' { initialise structures
SUB Init()
DIM i AS LONG
' init projectil tab
FOR i = 0 TO 16
proj(i).sprite = %Null
proj(i).created = 0
NEXT
FOR i = 0 TO %MAXEXPLODE-1
exp0(i).sp = %Null
exp0(i).anim = %Null
NEXT
END SUB
' }
'-----------------------------------------
'-----------------------------------------
' { update player
SUB UpdatePlayer()
DIM pos_space(3) AS SINGLE
NodePosition(play_.sp, pos_space(0))
play_.posx = pos_space(0)
play_.posy = pos_space(1)
IF ( play_.posx>450 ) THEN
play_.posx = -450
PositionNode(play_.sp, play_.posx, play_.posy, 1)
END IF
IF ( play_.posx<-450 )THEN
play_.posx = 450
PositionNode(play_.sp, play_.posx, play_.posy, 1)
END IF
IF ( play_.posy>350 ) THEN
play_.posy = -350
PositionNode(play_.sp, play_.posx, play_.posy, 1)
END IF
IF ( play_.posy<-350 ) THEN
play_.posy = 350
PositionNode(play_.sp, play_.posx, play_.posy, 1)
END IF
END SUB
' }
'-----------------------------------------
' { update all projectils
SUB UpdateProjectil()
DIM COL AS LONG, rd AS SINGLE, i AS LONG
FOR i = 0 TO 16
IF proj(i).created <> 0 THEN
proj(i).posx = proj(i).posx + proj(i).transx
proj(i).posy = proj(i).posy + proj(i).transy
PositionNode( proj(i).sprite, proj(i).posx, proj(i).posy, 1)
IF ( proj(i).posx>400 OR proj(i).posx<-400 ) THEN DeleteProjectil(i)
IF ( proj(i).posy>300 OR proj(i).posy<-300 ) THEN DeleteProjectil(i)
COL = CollideProjectil(i)
IF COL<>-1 THEN
rd = meteorB(COL).radius
DeleteProjectil(i)
IF rd>13 THEN
rd = rd / 2.0
CreateMeteor(rd, COL)
CreateMeteor(rd, COL)
ELSE
' explosion
GenerateExplode(COL)
END IF
DeleteMeteor(COL)
END IF
END IF
NEXT
END SUB
' }
' { Create projectils (16 maxi)
SUB CreateProjectil()
DIM pos_space(3) AS SINGLE
DIM rot_space(3) AS SINGLE
DIM i AS LONG
num_proj = -1
FOR i = 0 TO 15
IF proj(i).created = 0 THEN
num_proj = i
EXIT FOR
END IF
NEXT
IF num_proj<0 THEN RETURN
proj(num_proj).sprite = CloneNode(balll, %NULL)
NodePosition(play_.sp, pos_space(0))
NodeRotation(play_.sp, rot_space(0))
pos_space(0) = pos_space(0) + SIN( -rot_space(2)*0.01745329 ) * 55.0
pos_space(1) = pos_space(1) + COS( -rot_space(2)*0.01745329 ) * 55.0
PositionNode(proj(num_proj).sprite, pos_space(0), pos_space(1), pos_space(2))
proj(num_proj).posx = pos_space(0)
proj(num_proj).posy = pos_space(1)
proj(num_proj).transx = SIN( -rot_space(2)*0.01745329) * speed_
proj(num_proj).transy = COS( -rot_space(2)*0.01745329) * speed_
proj(num_proj).created = 1
proj(num_proj).radius = 10.0
END SUB
' }
' { destruct projectil
SUB DeleteProjectil(num AS LONG)
IF (proj(num).sprite) THEN
FreeNode(proj(num).sprite)
proj(num).sprite = %Null
proj(num).created = 0
END IF
END SUB
' }
'-----------------------------------------
' { Create Meteor
SUB CreateMeteor(rad AS SINGLE, numcol AS LONG)
DIM pos_space(3) AS SINGLE
DIM rot_space(3) AS SINGLE
DIM i AS LONG
DIM num_meteor AS LONG, posx AS SINGLE, posy AS SINGLE
num_meteor = -1
FOR i = 0 TO 63
IF meteorB(i).vcreated = 0 THEN
num_meteor = i
EXIT FOR
END IF
NEXT
IF num_meteor<0 THEN RETURN
meteorB(num_meteor).sprite = CreateSprite2D("media/meteor.png", rad*0.01, &h0ffffffff, %NULL)
MaterialTypeNode(meteorB(num_meteor).sprite, %EMT_TRANSPARENT_ALPHA_CHANNEL)
IF numcol<0 THEN
DO
posx = RND()*800.0
LOOP UNTIL (posx<250.0 OR posx>550.0)
posx = posx -400.0
DO
posy = RND()*600.0
LOOP UNTIL (posy<200.0 OR posy>400.0)
posy = posy -300.0
ELSE
posx = meteorB(numcol).posx
posy = meteorB(numcol).posy
END IF
PositionNode(meteorB(num_meteor).sprite, posx, posy, 1 )
meteorB(num_meteor).posx = posx
meteorB(num_meteor).posy = posy
meteorB(num_meteor).transx = -1.5+RND()*3.0
meteorB(num_meteor).transy = -1.5+RND()*3.0
meteorB(num_meteor).vcreated = 1
meteorB(num_meteor).radius = rad
END SUB
' }
' { update all meteor
SUB UpdateMeteor()
DIM i AS LONG
FOR i = 0 TO 63
IF meteorB(i).vcreated<> 0 THEN
meteorB(i).posx = meteorB(i).posx + meteorB(i).transx
meteorB(i).posy = meteorB(i).posy + meteorB(i).transy
PositionNode( meteorB(i).sprite, meteorB(i).posx, meteorB(i).posy, 1)
IF ( meteorB(i).posx>450 ) THEN meteorB(i).posx = -450
IF ( meteorB(i).posx<-450 )THEN meteorB(i).posx = 450
IF ( meteorB(i).posy>350 ) THEN meteorB(i).posy = -350
IF ( meteorB(i).posy<-350 )THEN meteorB(i).posy = 350
TurnNode(meteorB(i).sprite, 0,0,0.5, 0)
IF CollideMeteor(i)<>0 THEN
EndPlayer = 11
END IF
END IF
NEXT
END SUB
' }
' { destruct meteor
SUB DeleteMeteor(num AS LONG)
FreeNode(meteorB(num).sprite)
meteorB(num).sprite = %Null
meteorB(num).vcreated = 0
END SUB
' }
'-----------------------------------------
' { test collide between palyer spaceship And one meteor
FUNCTION CollideMeteor (numMeteor AS LONG)AS LONG
DIM dist AS SINGLE, bt AS SINGLE, COL AS SINGLE
dist = play_.radius + meteorB(numMeteor).radius
' cal distance
bt = (play_.posx - meteorB(numMeteor).posx)*(play_.posx - meteorB(numMeteor).posx) + (play_.posy - meteorB(numMeteor).posy)*(play_.posy - _
meteorB(numMeteor).posy)
bt = SQR(bt)
COL = 0
IF bt<dist THEN COL = 1
FUNCTION = COL
END FUNCTION
' }
' { test collide between palyer spaceship And one meteor
FUNCTION CollideProjectil(numProj AS LONG) AS LONG
DIM dist AS SINGLE, bt AS SINGLE, COL AS LONG
DIM i AS LONG
COL = -1
FOR i = 0 TO 63
IF meteorB(i).vcreated <> 0 THEN
dist = proj(numProj).radius + meteorB(i).radius
' cal distance
bt = (proj(numProj).posx - meteorB(i).posx)*(proj(numProj).posx - meteorB(i).posx) + (proj(numProj).posy - _
meteorB(i).posy)*(proj(numProj).posy - meteorB(i).posy)
bt = SQR(bt)
IF bt<dist THEN
COL = i
FUNCTION = COL
EXIT FUNCTION
END IF
END IF
NEXT
FUNCTION = -1
END FUNCTION
' }
'-----------------------------------------
' { Generate Explode
SUB GenerateExplode(COL AS LONG)
DIM posx AS SINGLE, posy AS SINGLE
DIM num_exp AS LONG
num_exp =-1
DIM i AS LONG
score = score + 1
longerval_score = longerval_score + 1
IF (longerval_score=4) THEN
longerval_score=0
CreateMeteor(50.0, -1)
END IF
posx = meteorB(COL).posx
posy = meteorB(COL).posy
num_exp = -1
FOR i = 0 TO %MAXEXPLODE-1
IF exp0(i).sp = %Null THEN
num_exp = i
EXIT FOR
END IF
NEXT
IF num_exp<0 THEN EXIT SUB
exp0(num_exp).sp = CreateSprite2D("media/Particle.png", 2.0, &h0ffffffff, %NULL)
MaterialTypeNode(exp0(num_exp).sp, %EMT_TRANSPARENT_ALPHA_CHANNEL)
' Create explose sequance texture
DIM texturelist AS NArray
texturelist = CreateListTexture("media/explode.png", 64, 64)
exp0(num_exp).anim = CreateTextureAnimator( texturelist, 130, %False)
AddAnimatorTexture(exp0(num_exp).sp, exp0(num_exp).anim)
PositionNode( exp0(num_exp).sp, posx, posy, 1)
VisibleNode( exp0(num_exp).sp, %True)
END SUB
' }
' { Update Explode
SUB UpdateExplode()
LOCAL i AS LONG
FOR i = 0 TO %MAXEXPLODE-1
IF(exp0(i).sp) THEN
IF ( AnimatorTextureIndex(exp0(i).anim) = AnimatorTextureSize(exp0(i).anim)-1 ) THEN
FreeNode( exp0(i).sp )
exp0(i).sp = %Null
exp0(i).anim = %Null
END IF
END IF
NEXT
END SUB
' }
'-----------------------------------------
' { Death Player
SUB DeathPlayer()
DIM pos_space(3) AS SINGLE
NodePosition(play_.sp, pos_space(0))
PositionNode(player_explode, pos_space(0), pos_space(1), 0.1)
END SUB
' }
I trtied to compile and run that game.
To get the needed DLL's i downloaded the PureBasic Package on that site.
It compiles fine with PB 10, but when i run that game-executable it crashes.
Quote from: Theo Gottwald on October 04, 2011, 08:24:59 PM
I trtied to compile and run that game.
To get the needed DLL's i downloaded the PureBasic Package on that site.
It compiles fine with PB 10, but when i run that game-executable it crashes.
I haven't tried it, but from looking at the code, he is using DX9. Do you have the DirectX 9 runtimes installed? DX9 support does not ship with Vista/7 and must be downloaded and installed separately.
If you do not have DX9, in the last file Pete posted "Little2D game", you can change this line:
app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
to
app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_OPENGL, %TRUE)
and recompile it. This will set it to use hardware OpenGL (which you should have as long as you have downloaded the graphics card drivers from your manufacturer's site).
Hi Theo,
Of course you always have the latest current use include file and the example of mine that I've rewritten it should work for me it goes anyway
Today there is a new include
regards Peter
Hello Manuel,
I have no problem with Windows 7 Who is this a problem with Vista, then it must also be so with PureBasic! Definitely has nothing to do with the PowerBASIC
regards Peter
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 045 : Little2D game version 3D
' Historique :
' 29/03/09 19:16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
DECLARE SUB Init()
DECLARE SUB CreateMeteor(rad AS SINGLE, numcol AS LONG)
DECLARE SUB CreateProjectil()
DECLARE SUB UpdatePlayer()
DECLARE SUB UpdateMeteor()
DECLARE SUB UpdateExplode()
DECLARE SUB UpdateProjectil()
DECLARE SUB DeathPlayer()
DECLARE SUB RenderAllSprite2D()
DECLARE SUB DeleteProjectil(num AS LONG)
DECLARE FUNCTION CollideProjectil(numProj AS LONG) AS LONG
DECLARE SUB GenerateExplode(COL AS LONG)
DECLARE SUB DeleteMeteor(num AS LONG)
DECLARE FUNCTION CollideMeteor(numMeteor AS LONG) AS LONG
DECLARE SUB Set2DCamera(wwidth AS SINGLE, height AS SINGLE)
DECLARE SUB Set3DCamera()
DECLARE SUB Visible3D( flag AS BYTE)
DECLARE SUB Visible2D( flag AS BYTE)
'----------------------------------------------------------
' Structures definition
'----------------------------------------------------------
'{ Player definition
TYPE PLAYER
sp AS SpriteSceneNode
posx AS SINGLE
posy AS SINGLE
radius AS SINGLE
END TYPE
'--}
'{ Meteor definition
TYPE METEOR
pbmesh AS EntityNode
posx AS SINGLE
posy AS SINGLE
transx AS SINGLE
transy AS SINGLE
vcreated AS LONG
radius AS SINGLE
END TYPE
'--}
'{ Projectil definition
TYPE BALL
sprite AS SpriteSceneNode
posx AS SINGLE
posy AS SINGLE
transx AS SINGLE
transy AS SINGLE
created AS LONG
radius AS SINGLE
END TYPE
'--}
'{ Explode definition
TYPE EXPLO
sp AS SpriteSceneNode
anim AS NNodeAnimator
posx AS SINGLE
posy AS SINGLE
END TYPE
%MAXEXPLODE = 8
FUNCTION PBMAIN
' dimes
DIM app AS DWORD
DIM Quit AS LONG
'----------------------------------------------------------
' open n3xt-D screen
app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app = %NULL THEN
EXIT FUNCTION
END IF
'--}
DIM PBPLAY AS GLOBAL PLAYER
DIM EndPlayer AS GLOBAL LONG
DIM PBSPEED AS GLOBAL SINGLE : PBSPEED =10.0
DIM proj(17) AS GLOBAL BALL
DIM num_proj AS GLOBAL SINGLE
DIM meteorB(64) AS GLOBAL METEOR
DIM exp0(%MAXEXPLODE) AS GLOBAL EXPLO
DIM proj_matrix(17) AS GLOBAL SINGLE
DIM score AS GLOBAL LONG
DIM integererval_score AS GLOBAL LONG
LOCAL i AS LONG
'----------------------------------------------------------
'----------------------------------------------------------
' init all values And structures
Init()
'-----------------------------------------
'-----------------------------------------
' Create ball sprite
DIM ballmesh AS GLOBAL Mesh
ballmesh = CreateSpriteMesh( 12.0, &h0ffffffff)
'-----------------------------------------
' Create sphere meteor mesh
DIM spheremesh AS GLOBAL Mesh
spheremesh = CreateSphereMesh(1.0, 6)
'-----------------------------------------
'-----------------------------------------
' Create PLAYER
DIM playmesh AS GLOBAL Mesh
playmesh = CreateSpriteMesh( 50.0, &h0ffffffff)
pbplay.sp = CreateSprite3D(playmesh, "media/space1.png", %NULL)
MaterialTypeNode(pbplay.sp, %EMT_TRANSPARENT_ALPHA_CHANNEL)
PositionNode(pbplay.sp, 0,0,1)
pbplay.radius = 40.0
'-----------------------------------------
'-----------------------------------------
' Create EXPLODE PLAYER
DIM playerexplodemesh AS GLOBAL Mesh
playerexplodemesh = CreateSpriteMesh(160, &h00ffffff)
DIM player_explode AS GLOBAL SpriteSceneNode
player_explode = CreateSprite3D(playerexplodemesh, "media/Particle.png", %NULL)
' adapt material blend value
DIM material AS NMaterial
material = NodeMaterial(player_explode, 0)
TypeMaterial(material, %EMT_ONETEXTURE_BLEND )
TypeBlendMaterial(material, %EBF_ONE, %EBF_ONE_MINUS_SRC_COLOR, %EMFN_MODULATE_1X, %EAS_TEXTURE OR %EAS_VERTEX_COLOR)
' Create explose sequance texture
DIM texturelist AS NArray
texturelist = CreateListTexture("media/explo2.bmp",64,64)
DIM anim AS NNodeAnimator
anim = CreateTextureAnimator( texturelist, 130, %TRUE)
AddAnimatorTexture(player_explode, anim)
VisibleNode(player_explode, %False) ' no render
'-----------------------------------------
'-----------------------------------------
' Create thie first meteors
FOR i = 0 TO 7
CreateMeteor(50.0, -1)
NEXT
'-----------------------------------------
'-----------------------------------------
' Create first camera
DIM cam AS GLOBAL CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam,0,0,-50)
'-----------------------------------------
'-----------------------------------
' Load background textures
DIM texture AS NTexture
texture = LoadTexture("media/metal13.jpg")
'-----------------------------------------
' Load fonts
_LoadFont("media/courriernew.png")
DIM FONT_ AS IGUIFont
font_ = GetFont()
LoadFont("media/font0.xml", %FONT_TYPE.EGDF_DEFAULT)
DIM font2 AS IGUIFont
font2 = GetFont()
'----------------------------------------
' Create EARTH
'----------------------------------------
DIM obj1 AS Mesh
obj1 = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)
DIM obj0 AS Mesh
obj0 = CreateMeshWithTangents(obj1, %False, %False, %False, %True)
FreeLoadedMesh(obj1)
' set the alpha value of all vertices To 200
VertexColorAlphaMesh(obj0, 190)
' scale And position mesh
ScaleMesh(obj0, 16,16,16)
DIM sphere AS GLOBAL EntityNode
sphere = CreateEntityNode(obj0, 0, 0, 0, %NULL)
' Create New sphere with tangent composants
PositionNode(sphere, -70,130,45)
' Load heightmap, Create normal map from it And set it
DIM earthNormalMap AS NTexture
earthNormalMap = LoadTexture( "media/earthbump.bmp")
' Creates a normal map from a height map texture.
NormalMapTexture(earthNormalMap, 9.0)
MaterialTextureNode(sphere, earthNormalMap , 1)
' adjust material settings
MaterialTypeNode(sphere, %EMT_NORMAL_MAP_TRANSPARENT_VERTEX_ALPHA )
PositionNode(sphere, 0,0,5)
'-----------------------------------------
'----------------------------------------
' Create light And set position
DIM light AS GLOBAL LightNode
light = CreateLight(&hffffffff, 150, %ELT_POINT , %NULL)
PositionNode(light, 10, 20,-2)
'----------------------------------------
' save 3D data
Set2DCamera(800,600)
'-----------------------------------------
' ---------------------------------------
' Main loop
' ---------------------------------------
'-----------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
TurnNode(sphere,0,0.2,0, 0)
IF GetKeyDown(%KEY_CODE.KEY_ARROW_LEFT) THEN
TurnNode(pbplay.sp, 0, 0, 3, 0)
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_RIGHT) THEN
TurnNode(pbplay.sp, 0, 0, -3, 0)
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_UP) THEN
MoveNode(pbplay.sp, 0, -3, 0, 0)
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_DOWN) THEN
MoveNode(pbplay.sp, 0, 3, 0, 0)
END IF
IF GetKeyUp(%KEY_CODE.KEY_SPACE) THEN
CreateProjectil()
END IF
IF EndPlayer=0 THEN
UpdatePlayer()
UpdateProjectil()
UpdateMeteor()
UpdateExplode()
ELSE
DeathPlayer()
END IF
' ---------------
' Render
' ---------------
BeginScene(20,20,20, 255, 1, 1)
VisibleNode(player_explode, %False)
Visible3D( %True)
Visible2D( %False)
Set3DCamera()
IF EndPlayer<>0 THEN VisibleNode(player_explode, %False)
DrawRectImage2D(texture , 0, 0, 0, 0, 800, 600, &h0ff555555, BYVAL %NULL, %FALSE)
DrawScene()
Visible2D( %True)
Visible3D( %False)
Set2DCamera(800,600)
IF EndPlayer<>0 THEN VisibleNode(player_explode, %True)
DrawScene()
DrawText(font_, "score: "+ TRIM$(STR$(score)), 10,10,0,0, &h0ffffffff)
DrawText(font_, "Use 'dir' and 'space' key", 450,8,0,0, &h0ff00ffff)
IF EndPlayer<>0 THEN
DrawText(font2, "END", 360,250,0,0, &h0ffffff00)
DrawText(font2, "score: "+ TRIM$(STR$(score)), 350,310,0,0, &h0ffff00ff)
END IF
EndScene()
' ---------------
' End Render
' ---------------
WEND
' end
FreeEngine()
END FUNCTION
'-----------------------------------------
'-----------------------------------------
'-----------------------------------------
' { initialise structures
SUB Init()
DIM i AS LONG
' init projectil tab
FOR i = 0 TO 16
proj(i).sprite = %NULL
proj(i).created = 0
NEXT
FOR i = 0 TO %MAXEXPLODE-1
exp0(i).sp = %NULL
exp0(i).anim = %NULL
NEXT
END SUB
' }
'-----------------------------------------
' { set camera in 2D mode
SUB Set2DCamera(wwidth AS SINGLE, height AS SINGLE)
DIM PBMAT(17) AS SINGLE
CameraProjectionMatrix(cam, proj_matrix(0))
ProjectionMatrixOrthoLH( wwidth, height, pbMAT(0), 0.1, 100.0)
ProjectionMatrixCamera(cam, PBMAT(0), %FALSE)
END SUB
' }
' { set camera in 2D mode
SUB Set3DCamera()
ProjectionMatrixCamera(cam, proj_matrix(0), %False)
END SUB
' }
'-----------------------------------------
' { update player
SUB UpdatePlayer()
DIM pos_space(3) AS SINGLE
NodePosition(pbplay.sp, pos_space(0))
pbplay.posx = pos_space(0)
pbplay.posy = pos_space(1)
IF ( pbplay.posx>450 ) THEN pbplay.posx = -450 : PositionNode(pbplay.sp, pbplay.posx, pbplay.posy, 1)
IF ( pbplay.posx<-450 )THEN pbplay.posx = 450 : PositionNode(pbplay.sp, pbplay.posx, pbplay.posy, 1)
IF ( pbplay.posy>350 ) THEN pbplay.posy = -350 : PositionNode(pbplay.sp, pbplay.posx, pbplay.posy, 1)
IF ( pbplay.posy<-350 ) THEN pbplay.posy = 350 : PositionNode(pbplay.sp, pbplay.posx, pbplay.posy, 1)
END SUB
' }
'-----------------------------------------
' { update all projectils
SUB UpdateProjectil()
DIM COL AS LONG, rd AS SINGLE, i AS LONG
FOR i = 0 TO 16
IF proj(i).created <> 0 THEN
proj(i).posx = proj(i).posx + proj(i).transx
proj(i).posy = proj(i).posy + proj(i).transy
PositionNode( proj(i).sprite, proj(i).posx, proj(i).posy, 1)
IF ( proj(i).posx>400 OR proj(i).posx<-400 ) THEN DeleteProjectil(i)
IF ( proj(i).posy>300 OR proj(i).posy<-300 ) THEN DeleteProjectil(i)
COL = CollideProjectil(i)
IF COL<>-1 THEN
rd = meteorB(COL).radius
DeleteProjectil(i)
IF rd>13 THEN
rd = rd / 2.0
CreateMeteor(rd, COL)
CreateMeteor(rd, COL)
ELSE
' explosion
GenerateExplode(COL)
END IF
DeleteMeteor(COL)
END IF
END IF
NEXT
END SUB
' }
' { Create projectils (16 maxi)
SUB CreateProjectil()
DIM pos_space(3) AS SINGLE
DIM rot_space(3) AS SINGLE
DIM i AS LONG
num_proj = -1
FOR i = 0 TO 15
IF proj(i).created = 0 THEN
num_proj = i
EXIT FOR
END IF
NEXT
IF num_proj<0 THEN EXIT SUB
proj(num_proj).sprite = CreateSprite3D(ballmesh, "media/Particle.png", %NULL)
MaterialTypeNode(proj(num_proj).sprite, %EMT_TRANSPARENT_ALPHA_CHANNEL)
NodePosition(pbplay.sp, pos_space(0))
NodeRotation(pbplay.sp, rot_space(0))
pos_space(0) = pos_space(0) + SIN( -rot_space(2)*0.01745329 ) * 55.0
pos_space(1) = pos_space(1) + COS( -rot_space(2)*0.01745329 ) * 55.0
PositionNode(proj(num_proj).sprite, pos_space(0), pos_space(1), pos_space(2))
proj(num_proj).posx = pos_space(0)
proj(num_proj).posy = pos_space(1)
proj(num_proj).transx = SIN( -rot_space(2)*0.01745329) * pbSPEED
proj(num_proj).transy = COS( -rot_space(2)*0.01745329) * pbSPEED
proj(num_proj).created = 1
proj(num_proj).radius = 10.0
END SUB
' }
' { destruct projectil
SUB DeleteProjectil(num AS LONG)
IF (proj(num).sprite) THEN
FreeNode(proj(num).sprite)
proj(num).sprite = %NULL
proj(num).created = 0
END IF
END SUB
' }
'-----------------------------------------
' { Create Meteor
SUB CreateMeteor(rad AS SINGLE, numcol AS LONG)
DIM pos_space(3) AS SINGLE
DIM rot_space(3) AS SINGLE
DIM i AS LONG
DIM num_meteor AS LONG, posx AS SINGLE, posy AS SINGLE
num_meteor = -1
FOR i = 0 TO 63
IF meteorB(i).vcreated = 0 THEN
num_meteor = i
EXIT FOR
END IF
NEXT
IF num_meteor<0 THEN EXIT SUB
meteorB(num_meteor).pbmesh = CreateEntityNode(spheremesh, 0, 0, 0, %NULL)
ScaleNode(meteorB(num_meteor).pbmesh, rad,rad,rad)
LoadTextureNode( meteorB(num_meteor).pbmesh, "media/wall.jpg", 0, 0)
MaterialFlagNode(meteorB(num_meteor).pbmesh, %EMF_LIGHTING, %False )
IF numcol<0 THEN
DO
posx = RND()*800.0
LOOP UNTIL (posx<250.0 OR posx>550.0)
posx = posx -400.0
DO
posy = RND()*600.0
LOOP UNTIL (posy<200.0 OR posy>400.0)
posy = posy -300.0
ELSE
posx = meteorB(numcol).posx
posy = meteorB(numcol).posy
END IF
PositionNode(meteorB(num_meteor).pbmesh, posx, posy, 1 )
meteorB(num_meteor).posx = posx
meteorB(num_meteor).posy = posy
meteorB(num_meteor).transx = -1.5+RND()*3.0
meteorB(num_meteor).transy = -1.5+RND()*3.0
meteorB(num_meteor).vcreated = 1
meteorB(num_meteor).radius = rad
END SUB
' }
' { update all meteor
SUB UpdateMeteor()
DIM i AS LONG
FOR i = 0 TO 63
IF meteorB(i).vcreated<> 0 THEN
meteorB(i).posx = meteorB(i).posx + meteorB(i).transx
meteorB(i).posy = meteorB(i).posy + meteorB(i).transy
PositionNode( meteorB(i).pbmesh, meteorB(i).posx, meteorB(i).posy, 1)
IF ( meteorB(i).posx>450 ) THEN meteorB(i).posx = -450
IF ( meteorB(i).posx<-450 )THEN meteorB(i).posx = 450
IF ( meteorB(i).posy>350 ) THEN meteorB(i).posy = -350
IF ( meteorB(i).posy<-350 )THEN meteorB(i).posy = 350
TurnNode(meteorB(i).pbmesh, 0,0,0.5, 0)
IF CollideMeteor(i)<>0 THEN
EndPlayer = 11
END IF
END IF
NEXT
END SUB
' }
' { destruct meteor
SUB DeleteMeteor(num AS LONG)
FreeNode(meteorB(num).pbmesh)
meteorB(num).pbmesh = %NULL
meteorB(num).vcreated = 0
END SUB
' }
'-----------------------------------------
' { test collide between palyer spaceship And one meteor
FUNCTION CollideMeteor(numMeteor AS LONG) AS LONG
DIM dist AS SINGLE, bt AS SINGLE, COL AS SINGLE
dist = pbplay.radius + meteorB(numMeteor).radius
' cal distance
bt = (pbplay.posx - meteorB(numMeteor).posx)*(pbplay.posx - meteorB(numMeteor).posx) + (pbplay.posy - meteorB(numMeteor).posy)* _
(pbplay.posy - meteorB(numMeteor).posy)
bt = SQR(bt)
COL = 0
IF bt<dist THEN COL = 1
FUNCTION = COL
END FUNCTION
' }
' { test collide between palyer spaceship And one meteor
FUNCTION CollideProjectil(numProj AS LONG) AS LONG
DIM dist AS SINGLE, bt AS SINGLE, COL AS LONG
DIM i AS LONG
COL = -1
FOR i = 0 TO 63
IF meteorB(i).vcreated <> 0 THEN
dist = proj(numProj).radius + meteorB(i).radius
' cal distance
bt = (proj(numProj).posx - meteorB(i).posx)*(proj(numProj).posx - meteorB(i).posx) + (proj(numProj).posy - meteorB(i).posy)* _
(proj(numProj).posy - meteorB(i).posy)
bt = SQR(bt)
IF bt<dist THEN
COL = i
FUNCTION = COL
EXIT FUNCTION
END IF
END IF
NEXT
FUNCTION = -1
END FUNCTION
' }
'-----------------------------------------
' { Generate Explode
SUB GenerateExplode(COL AS LONG)
DIM posx AS SINGLE, posy AS SINGLE
DIM num_exp AS LONG
num_exp = -1
LOCAL i AS LONG
score = score + 1
integererval_score = integererval_score + 1
IF (integererval_score=4) THEN
integererval_score=0
CreateMeteor(50.0, -1)
END IF
posx = meteorB(COL).posx
posy = meteorB(COL).posy
num_exp = -1
FOR i = 0 TO %MAXEXPLODE-1
IF exp0(i).sp = %NULL THEN
num_exp = i
EXIT FOR
END IF
NEXT
IF num_exp<0 THEN EXIT SUB
DIM spmesh AS Mesh
spmesh = CreateSpriteMesh( 50.0, &h0ffffffff)
Exp0(num_exp).sp = CreateSprite3D(spmesh, "media/Particle.png", %NULL)
MaterialTypeNode(Exp0(num_exp).sp, %EMT_TRANSPARENT_ALPHA_CHANNEL)
' Create explose sequance texture
DIM texturelist AS NArray
texturelist = CreateListTexture("media/explode.png", 64, 64)
exp0(num_exp).anim = CreateTextureAnimator( texturelist, 130, %False)
AddAnimatorTexture(exp0(num_exp).sp, exp0(num_exp).anim)
PositionNode( exp0(num_exp).sp, posx, posy, 1)
VisibleNode( exp0(num_exp).sp, %TRUE )
END SUB
' }
' { Update Explode
SUB UpdateExplode()
DIM i AS LONG
FOR i = 0 TO %MAXEXPLODE-1
IF(exp0(i).sp) THEN
IF ( AnimatorTextureIndex(exp0(i).anim) = AnimatorTextureSize(exp0(i).anim)-1 ) THEN
FreeNode( exp0(i).sp )
exp0(i).sp = %NULL
exp0(i).anim = %NULL
END IF
END IF
NEXT
END SUB
' }
'-----------------------------------------
' { Death Player
SUB DeathPlayer()
DIM pos_space(3) AS SINGLE
NodePosition(pbplay.sp, pos_space(0))
PositionNode(player_explode, pos_space(0), pos_space(1), 0.1)
END SUB
' }
'-----------------------------------------
' { turn OFF Or ON 3D elements
SUB Visible3D( flag AS BYTE)
VisibleNode(light, flag)
VisibleNode(sphere, flag)
END SUB
' }
' { turn OFF Or ON 2D elements
SUB Visible2D( flag AS BYTE)
DIM i AS LONG
VisibleNode(pbplay.sp, flag)
FOR i = 0 TO 16
IF ( proj(i).sprite ) THEN VisibleNode(proj(i).sprite, flag)
NEXT
FOR i = 0 TO 63
IF ( meteorB(i).pbmesh ) THEN VisibleNode(meteorB(i).pbmesh, flag)
NEXT
FOR i = 0 TO %MAXEXPLODE-1
IF ( Exp0(i).sp ) THEN VisibleNode(Exp0(i).sp, flag)
NEXT
END SUB
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 047 as Test Multi SceneManager.
' 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 cube in the base SceneManager
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(1)
LOCAL i AS INTEGER
FOR i = 0 TO 15
DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(cube, -6+RND()*12,0,-6+RND()*12)
LoadTextureNode(cube, "media/body.bmp", 0, 0)
NEXT
' Create a camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam, 0,0,-5)
'-----------------------------------------
' Create New SceneManager
DIM smgr2 AS BYTE PTR
smgr2 = CreateSceneManager()
'-----------------------------------------
' set the N3xtD system with the New SceneManager
DIM smgr1 AS BYTE PTR
smgr1 = CurentSceneManager(smgr2)
'-----------------------------------------
' Create a cube in the second SceneManager
FOR i = 0 TO 15
DIM pbcube AS EntityNode
pbcube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(pbcube, -6+RND()*12, -4, -6 + RND()*12)
LoadTextureNode(pbcube, "media/five.bmp", 0, 0)
NEXT
' Create a camera in the New SceneManager
' (each SceneManager must have a camera)
DIM cam2 AS CameraNode
cam2 = CreateCamera(%NULL)
PositionNode(cam2, 0,0,-5)
'-----------------------------------
' Load font png
LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
DIM PBfont AS IGUIFont
PBFont = GetFont()
DIM flag AS INTEGER
' ---------------------------------------
' 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_F1) THEN
CurentSceneManager(smgr1)
flag=0
END IF
IF GetKeyUp(%KEY_CODE.KEY_F2) THEN
CurentSceneManager(smgr2)
flag=1
END IF
IF GetKeyUp(%KEY_CODE.KEY_F3) THEN
flag=2
END IF
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
IF(flag=2) THEN DrawSceneManager(smgr1)
DrawScene()
DrawText(pbfont, "F1/F2 to switch between SceneManager", 10,10,0,0, &h0ff9999ff)
DrawText(pbfont, "F3 Draw to SceneManager", 10,30,0,0, &h0ff9999ff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Thanks Peter, when i get it it, I'll give it another try.
Hi Theo,
Include the hang to it but still.
But here again especially for you the newest
regards Peter
Hello,
a new example and include new
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 048 as load irr scene
' 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 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/irrEdit")
'------------------------------
' Load irrscene
LoadIrrScene("scenes/example.irr", BYVAL %NULL)
DIM node_list AS NArray
node_list = CreateArray()
SceneNodesFromType(node_list, %ESNT_ANY, BYVAL %NULL)
FOR i = 0 TO ArraySize(node_list) - 1
DIM node AS EntityNode
node = ArrayElement(node_list, i)
'print _Text(_NodeName(*node))
NEXT
'------------------------------
' Create a camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam, 0,20,-70)
' ---------------------------------------
' Main loop
' ---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
regards Peter
Thanks, Peter.
The problem with all the 3D stuff is the missing usability for GUI.
Actually i do not make games, but i may want to make realistic looking drag'n drop.
I would like to have great looking 3D-Buttons (not the 3D from EZGUI* looking like a Bin, REAL 3D like on on iPhone).
For this, all these libraries are just the base of what is needed.
They are optimized for games and gamers. Not for GUI's.
Thats the problem.
While most people here work on GUI's (including me right now) - not on games - at least here.
So whats missing in my opinion is the next Level.
Make 3D usable for GUI's. Really, easily usable for GUI's.
3D Controls, 3D Items, the user can manipulate and doing so control the program.
Buttons that shine like a LED?
Or Texts that graphically appear and dissapear when i write in a Textbox-Control?
Items that i can REALLY drag from here to there.
Buttons that really go in and out in 3D when the user presses them!
There are usable things thinkable for the GUI of the future.
Yet many people today prodive 3D for gaming, but most people here do not program games!
Think of making a 3D-Controls Library! Not just gaming.
While actually i have not time to take a closer look because i am busy with other things.
This is something that i may take a look at in the future.
Reason:
The average intelligence of the average American (or german) citizen is decreasing, thanks to drugs and MTV.
Means there is a big demand for making GUIs more intuitive to use.
As a result even the most stupid person, can read his mails or drag them into the mail-trashcan.
Look at Windows 8!
It's not more professional then windows 2000, its just safer (internally) and more easy to use for people with low IQ.
This is the direction to go, 3D will play a role then. Aside from gaming.
*I just remember EZGUI 5 because it also includes (nice!) 3D Features, which would be nice for gaming or making 3D Desginers. But I have discussed this with CB also. Who really needs it? We make GUI's not games. At all this stuff is missing the final step to make the 3D really usable for GUI's. How about a 3D-Treview? This is advanced programming, we must try to go ahead, not look to just follow old trends.
Peter, I tried one example that was completely in b/w (see attached picture).
Even using the newest includes, the "game" crashed as before.
Wouldn't it be good if there would be a warning "component not available" or like that?
Because it just doesn't say why it crashes,
I can say that the PureBasic Examples worked fine.
Hi Theo,
can you give me the number or the name of the example to tell me at all to work now that I've rewritten!
The examples are not nice I know. I've taken from the Free Basic because they are easier to write about because FreeBasic and PowerBASIC are similar!
Get me the look of PureBasic whom I'm done
Excuse my English still is not very good
regards Peter
Hi Theo,
What I really wanted to say I'm really not a game programmer! I really wanted to show only the one written with PowerBASIC on the tools for other programming languages can access!
In addition, here in this forum provides an interface to N3xtD was required!
Whether it makes sense or not I can not say at this time
What happened to me. noticed Bob's has not done its homework properly must be reworked for PowerBASIC here!
The transfer of optional parameters and constants is bugging me for PowerBASIC! They can not pre-assign a value to how to do it in Visual Basic and FreeeBasic
regards Peter
Theo: I am not sure why you are insisting on using the PureBasic version when Peter is following my advice and working from the FreeBasic version. There are four different versions of the engine for a reason. It would be best to use the version that Peter is working from. As long as you are doing that and running the example from the correct path and have your resources in the correct directories, you should have no problems (as long as you have the runtimes installed for whatever rendering API you are using).
Peter, if you have really stuff that you think is not working as expected, please sent me a mail with example code that can be compiled.
I am actually not aware of any Bug in PB 10, but if there are some, i want to know it and look that they get reported.
Hi Theo,
I may have misunderstood you, or you misunderstood me. PB 10 has no fault! It is not merely beautiful
That is the bottom written in PowerBASIC do not!
declare Function CloneNode cdecl alias "_CloneNode"(opt ByVal node As long = 5, opt ByVal parent As integer =NULL) As EntityNode
But anyway I'll send you all the examples I've rewritten it to now work with me
regards Peter
Quote from: Peter Weis on October 07, 2011, 03:10:52 PMThat is the bottom written in PowerBASIC do not!
declare Function CloneNode cdecl alias "_CloneNode"(opt ByVal node As long = 5, opt ByVal parent As integer =NULL) As EntityNode
I have never seen this form of declare before and I mentioned it to my brother and he told me that in some languages, this is used to set the value to send to the routine if the optional parameter is not given.
In my mind, this is pretty silly. If a routine wants a specific value if a parameter is not passed in, then why doesn't it just set the value in the routine rather than expecting the calling program to supply it?
To get around this in PowerBASIC you could create a wrapper function to call the routines that need this. Using your example above you could do something like this:
DECLARE FUNCTION CloneNode2 CDECL ALIAS "_CloneNode"(OPT BYVAL node AS LONG, OPT BYVAL parent AS INTEGER) AS EntityNode
FUNCTION CloneNode(OPT BYVAL node AS LONG, OPT BYVAL parent AS INTEGER) AS EntityNode
IF ISMISSING(node) THEN
node = 5
END IF
IF ISMISSING(parent) THEN
PARENT = %NULL
END IF
FUNCTION = CloneNode2(node, parent)
END FUNCTION
Hello,
Respect of the declaration was changed to DrawText NX3_DrawText because they are not compatible with Windows API because it gives the name already had the call must be changed in each example
regards Peter
ISMISSING does not work with optional BYVAL scalar parameters. You have to use optional BYREF scalar parameters or optional BYVAL/BYREF VARIANTs.
Jeff Blakeney,
IsMissing comes to me out of the question, because it will be decided until runtime what the program is passed. Furthermore, an additional feature requires what makes the program more slowly! Additionally, as Jose already writes the values must be handed over the charge of byref pointer costs even more time!
I wish that just as in free Basic or Visual Basic where the compiler decides what is passed!
regards Peter
' ------------------------------------------------------------
' 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
' ------------------------------------------------------------
' 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
' ------------------------------------------------------------
' 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
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.
...
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
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.
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.
Hi Jeff,
The idea I had with macro that works well is not!
regards Peter
' ------------------------------------------------------------
' 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
' ------------------------------------------------------------
' 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
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,
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
Hi Patrice,
The color is wrong because the AmbientLight(&h0ffffff00) is called. The panel then made the wrong color
regards Peter
' ------------------------------------------------------------
' 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
' ------------------------------------------------------------
' 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
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 104 as terrain physic 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
' set the curent folder
ChangeWorkingDirectory("media")
'------------------------------------------------------------------------------------
' resize physic world space
SetWorldSize(-1000,-1000,-1000,1000,1000,1000)
'------------------------------------------------------------------------------------
DIM terrain AS TerrainNode
terrain = CreateTerrain("height113.bmp", %TQ_MEDIUM, 2.0, 0.3, 2.0, 32, %TRUE, %HARDMAPPING.EHM_STATIC)
TextureTerrain(terrain, 0 , "Sol113.jpg", -1 , -1)
TextureTerrain(terrain, 1 , "detailmap3.jpg", -1, -1)
MaterialTypeNode(terrain, %EMT_LIGHTMAP_LIGHTING_M2)
' Create terrain body
' first Method, less accurate, but lighter And faster.
CreateTerrainBody(terrain, %HEIGHTFIELD_METHOD)
' << Or >>
' second Method, accurate, but heavier
'_CreateTerrainBody(terrain, VERTICES_METHOD)
'------------------------------------------------------------------------------------
'-----------------------------------------
' Create a static base
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(4.0)
'-----------------------------------------
' Create a cube
DIM i AS INTEGER
FOR i = 0 TO 25
DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(cube, -25+RND()*50+50,100,-25+RND()*50+50)
LoadTextureNode(cube, "body.bmp", 0, 0)
' Create body, dynamique
CreateBody(cube, %BOX_PRIMITIVE, %True, 1.0, 0, 0, 0)
NEXT
'----------------------------------------
' Create a camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam, 0,120,-70)
'----------------------------------------
' Load font png
LoadFont("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
' ---------------
' Render
' ---------------
BeginScene(1,128,128, 255, 1, 1)
DrawScene()
NX3_DrawText(pbfont, "FPS as " + TRIM$(STR$(FPS())), 10,25,0,0, &h0ffffffff)
NX3_DrawText(pbfont, "Primitives as "+ TRIM$(STR$(PrimitiveCountDrawn())) , 10,45,0,0, &h0ffffffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 105 as scene 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
DIM i 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")
'-----------------------------------
' add in memory management system a zip file
AddZipFileArchive( "chiropteradm.pk3" )
'-----------------------------------
' Load Quake3 scene Object
DIM obj AS Mesh
obj = LoadMesh("chiropteradm.bsp", %HARDMAPPING.EHM_STATIC)
ScaleMesh(obj, 0.2, 0.2, 0.2)
' Create a mesh with one of the 3D Object loaded
DIM quake AS EntityNode
quake = CreatePopNodes(obj, %NULL)
' resize world box dimension
SetWorldSize(-1000,-1000,-1000,1000,1000,1000)
' Create static body scene
CreateBody(quake, %COMPLEX_PRIMITIVE_SURFACE, %False, 1.0, 0, 0, 0)
'-----------------------------------------
' Create a static base
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(2.0)
'-----------------------------------------
' Create a cube
FOR i = 0 TO 25
DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(cube, -20+RND()*40,10+RND()*10,-10+RND()*12)
LoadTextureNode(cube, "wcrate.bmp", 0, 0)
' Create body, dynamique
CreateBody(cube, %BOX_PRIMITIVE, %True, 1.0, 0, 0, 0)
NEXT
'-----------------------------------------
' Load an 3D Object
obj = LoadMesh("teapot.b3d", %HARDMAPPING.EHM_STATIC)
' Create a mesh with one of the 3D Object loaded
DIM teapot AS EntityNode
teapot = CreateEntityNode(obj, 0, 0, 0, %NULL)
PositionNode(teapot, 5,6,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,20,-40)
'-----------------------------------
' Load font png
LoadFont("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 GetKeyUp(%KEY_CODE.KEY_SPACE) THEN
FOR i = 0 TO 7
'DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(cube, -20+RND()*40,10+RND()*10,-10+RND()*20)
Scalenode(cube, 1.5,1.5,1.5)
LoadTextureNode(cube, "object.jpg", 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
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 106 as Raycast Test 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
DIM i 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,25,3)
'-----------------------------------------
' 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)
'dim mat as NMaterial
pbmat = NodeMaterial(cube, 0)
ColorMaterial(pbmat, %ECM_NONE)
' Create collide Type
CreateNodeCollide(cube, %BOX_PRIMITIVE, 1, 0, 0, 0)
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, 0, 0, 0)
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, 0, 0, 0)
'-----------------------------------------
' 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()
DIM dist AS SINGLE
dist = -1.0
DIM start AS iVECTOR3
DIM eend AS iVECTOR3
start.x=0 : start.y = 10 : start.z=0
eend.x=0 : eend.y = -1 : eend.z=0
' ---------------------------------------
' Main loop
' ---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' move line raycast with dir key
IF GetKeyDown(%KEY_CODE.KEY_ARROW_UP) THEN
start.z = start.z + 0.15
eend.z = eend.z + 0.15
DIM pbres AS EntityNode
pbres = CollideRayCastAll( start.x, start.y, start.z, eend.x, eend.y, eend.z, 1, dist)
IF pbres THEN
TurnNode(pbres,0,2,0, 0)
DiffuseColorNode(pbres, &h0ff111111)
END IF
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_DOWN) THEN
start.z = start.z - 0.15
eend.z = eend.z - 0.15
'dim pbres as EntityNode
pbres = CollideRayCastAll( start.x, start.y, start.z, eend.x, eend.y, eend.z, 1, dist)
IF pbres THEN
TurnNode(pbres,0,2,0, 0)
DiffuseColorNode(pbres, &h0ff111111)
END IF
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_LEFT) THEN
start.x = start.x - 0.15
eend.x = eend.x - 0.15
'dim pbres as EntityNode
pbres = CollideRayCastAll( start.x, start.y, start.z, eend.x, eend.y, eend.z, 1, dist)
IF pbres THEN
TurnNode(pbres,0,2,0, 0)
DiffuseColorNode(pbres, &h0ff111111)
END IF
END IF
IF GetKeyDown(%KEY_CODE.KEY_ARROW_RIGHT) THEN
start.x = start.x + 0.15
eend.x = eend.x + 0.15
'dim pbres as EntityNode
pbres = CollideRayCastAll( start.x, start.y, start.z, eend.x, eend.y, eend.z, 1, dist)
IF pbres THEN
TurnNode(pbres,0,2,0, 0)
DiffuseColorNode(pbres, &h0ff111111)
END IF
END IF
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
DrawLine3D(start.x, start.y, start.z, eend.x, eend.y, eend.z, &h0ffff00ff)
NX3_DrawText(pbfont, "Dist as "+ TRIM$(STR$(dist)), 10,10,0,0, &h0ff9999ff)
NX3_DrawText(pbfont, "Use Dir key to move raycast line", 10,25,0,0, &h0ff9999ff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
New Include
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 108 as test material 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
DIM i 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,25,3)
AmbientLight(&h0ff222222)
' -----------------------------------------
' Create And init some physicmaterial
' -----------------------------------------
DIM pbmat(6) AS LONG
pbmat(1)= CreatePhysicMaterial()
pbmat(2)= CreatePhysicMaterial()
pbmat(3)= CreatePhysicMaterial()
pbmat(4)= CreatePhysicMaterial()
pbmat(5)= CreatePhysicMaterial()
DIM pair1 AS NMaterialPair
pair1 = CreatePhysicMaterialPair(pbmat(1), pbmat(1), 0.1, 0.3, 0.25, 0)
DIM pair2 AS NMaterialPair
pair2 = CreatePhysicMaterialPair(pbmat(1), pbmat(2), 0.3, 1.1, 0.82, 0)
DIM pair3 AS NMaterialPair
pair3 = CreatePhysicMaterialPair(pbmat(1), pbmat(3), 0.5, 0.025, 0.01, 0)
DIM pair4 AS NMaterialPair
pair4 = CreatePhysicMaterialPair(pbmat(1), pbmat(4), 0.7, 1.0, 1.0, 0)
DIM pair5 AS NMaterialPair
pair5 = CreatePhysicMaterialPair(pbmat(1), pbmat(5), 0.9, 0.1, 0.5, 0)
'-----------------------------------------
' 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, 30,1,30)
RotateNode(cube, 0,0,25)
' Create body, no dynamique
CreateBody(cube, %BOX_PRIMITIVE, %False, 1.0, 0, 0, 0)
GroupPhysicMaterialBody(cube, pbmat(1))
'-----------------------------------------
' Create 5 random cubes
FOR i = 0 TO 4
DIM pbmesh AS Entitynode
pbmesh = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
ScaleNode(pbmesh, 2,2,2)
PositionNode(pbmesh, 10, 10 ,-4+4*i)
MaterialColorNode(pbmesh, %ECM_NONE)
DiffuseColorNode(pbmesh, &h0ff000000+RND()*&h0ffffff)
LoadTextureNode(pbmesh, "media/body.bmp", 0, 0)
CreateBody(pbmesh, %BOX_PRIMITIVE, %True, 1.0, 0, 0, 0)
GroupPhysicMaterialBody(pbmesh, pbmat(i+1))
NEXT
'-----------------------------------------
' Create first camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam, -5,7,-20)
' ---------------------------------------
' Main loop
' ---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' ---------------
' Render
' ---------------
BeginScene(128, 128, 128, 255, 1, 1)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
Hello
So all FreeBasic demos for PowerBASIC implemented
Include seen so far removed but still some errors in it. Now I'm still missing the examples PureBasic with the controls to work, then that's all in PowerBASIC.
Who else someone finds fault in the include files I ask you to inform me that would like to eliminate these errors
regards Peter
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 109 as physic engine - Elastic values with callback traitement
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
DECLARE SUB MaterialEventCallBack CDECL(BYVAL node1 AS EntityNode, BYVAL node2 AS EntityNode, BYVAL material AS NPMaterial, BYVAL contact AS BYTE PTR)
FUNCTION PBMAIN
' Dimes
DIM app AS DWORD
DIM Quit AS INTEGER
DIM i AS LONG
'----------------------------------------------------------
' 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(&h0ff555555)
'-----------------------------------------
' 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 base PhysicMaterial
' ---------------------------------------
DIM mat0 AS LONG
mat0 = CreatePhysicMaterial()
DIM mat1 AS LONG
mat1 = CreatePhysicMaterial()
DIM mat2 AS LONG
mat2 = CreatePhysicMaterial()
DIM pair0 AS NMaterialPair
pair0 = CreatePhysicMaterialPair( mat0, mat0, 0.3, 1.1, 0.82, 0) ' Create a New PhysicMaterial pair interaction
DIM pair1 AS NMaterialPair
pair1 = CreatePhysicMaterialPair( mat1, mat1, 1.0, 1.1, 0.82, 0) ' Create a New PhysicMaterial pair interaction
'_CollisionMemPhysicMaterial(pair0) ' memorize collision body inside a stack
PhysicMaterialEventCallBack(pair0, CODEPTR(MaterialEventCallBack)) ' set callback collide PhysicMaterial
'_CollisionMemPhysicMaterial(pair1) ' memorize collision body inside a stack
PhysicMaterialEventCallBack(pair1, CODEPTR(MaterialEventCallBack)) ' set callback collide PhysicMaterial
'-----------------------------------------
' Create spheres group 0
DIM spmesh AS Mesh
spmesh = CreateSphereMesh(0.5, 16)
FOR i = 0 TO 3
DIM sp AS EntityNode
sp = CreateEntityNode(spmesh, 0, 0, 0, %NULL)
PositionNode(sp, 0,1+i*2.5, 0)
LoadTextureNode(sp, "media/body.bmp", 0, 0)
' Create body, no dynamique
CreateBody(sp, %SPHERE_PRIMITIVE, %True, 1.0, 0, 0, 0)
GroupPhysicMaterialBody(sp, mat0)
NEXT
'-----------------------------------------
' Create spheres group 1
' creates second sphere mesh, because Newton consider that both geometry
' is identical, so it is the same body.
spmesh = CreateSphereMesh(0.51, 16)
FOR i = 0 TO 3
'dim sp As EntityNode
sp = CreateEntityNode(spmesh, 0, 0, 0, %NULL)
PositionNode(sp, 5,1+i*2.5, 0)
LoadTextureNode(sp, "media/body.bmp", 0, 0)
' Create body, no dynamique
CreateBody(sp, %SPHERE_PRIMITIVE, %True, 1.0, 0, 0, 0)
GroupPhysicMaterialBody(sp, mat1)
NEXT
'-----------------------------------------
' 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,-10)
'-----------------------------------
' Load font png
LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
DIM pbfont AS IGUIFont
pbfont = GetFont()
DIM restitution AS GLOBAL SINGLE
restitution=1.0
' ---------------------------------------
' 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_T) THEN
restitution = restitution + 0.01
END IF
IF GetKeyDown(%KEY_CODE.KEY_KEY_G) THEN
restitution = restitution - 0.01
END IF
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
NX3_DrawText(pbfont, "KEY T/G for change restitution as "+ TRIM$(STR$(restitution)), 10,10,0,0, &h0ff00ffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
'-----------------------------------------------------
' callback procedure
' it's a derivation of the treatment of collisions and
' associated PhysicMaterials.
SUB MaterialEventCallBack CDECL(BYVAL node1 AS EntityNode, BYVAL node2 AS EntityNode, BYVAL material AS NPMaterial, BYVAL contact AS BYTE PTR)
ContactElasticityPhysicMaterial( material, restitution )
END SUB
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 110 as physic joint test
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
DECLARE SUB ApplyForceAndTorque CDECL(BYVAL bdy AS NBody)
' dimes
FUNCTION PBMAIN
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, 20, %ELT_POINT, %NULL)
PositionNode(light, 5,15,3)
AmbientLight(&h0ff555555)
'-----------------------------------------
' Create And Load mesh
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(1.0)
' Load
DIM obj1 AS Mesh
obj1 = LoadMesh("media/N1.b3d", %HARDMAPPING.EHM_STATIC)
DIM obj2 AS Mesh
obj2 = LoadMesh("media/N2.b3d", %HARDMAPPING.EHM_STATIC)
RotateMesh(obj2, 0,90,0)
ScaleMesh(obj1 , 0.25,0.25,0.25)
'-----------------------------------------
' Create a static base
DIM cube AS Entitynode
cube = CreateEntityNode(cubemesh, 0, 0, 0, %NULL)
PositionNode(cube, 0,0,0)
LoadTextureNode(cube, "media/dirt.bmp", 0, 0)
ScaleNode( cube, 50,1,50)
' Create body, no dynamique
CreateBody(cube, %BOX_PRIMITIVE, %False, 1.0, 0, 0, 0)
'=============================================================
' Create two mesh For Ball Joint
'=============================================================
DIM mesh1 AS Entitynode
mesh1 = CreateEntityNode(obj1, 0, 0, 0, %NULL)
PositionNode(mesh1, 10, 10 ,0)
GlobalColorNode(mesh1, &h0ff00ff00)
CreateBody(mesh1, %BOX_PRIMITIVE, %True, 1.0, 0, 0, 0)
DIM mesh2 AS Entitynode
mesh2 = CreateEntityNode(obj2, 0, 0, 0, %NULL)
RotateNode(mesh2, 0,180,0)
PositionNode(mesh2, 10, 10 ,3.5)
GlobalColorNode(mesh2, &h0ff00ffff)
CreateBody(mesh2, %BOX_PRIMITIVE, %True, 1.0, 0, 0, 0)
' Create Ball Joint
DIM ball AS NJoint
ball = CreateBallJoint(mesh2, mesh1 , 10,10,1.5)
BallSetConeLimits(ball, 10,10,3.0, 0, 20)
'=============================================================
' Create two mesh For Hinge Joint
'=============================================================
DIM mesh3 AS Entitynode
mesh3 = CreateEntityNode(obj1, 0, 0, 0, %NULL)
PositionNode(mesh3, -20, 10 ,2.5)
GlobalColorNode(mesh3, &h0ffffff00)
CreateBody(mesh3, %BOX_PRIMITIVE, %True, 3,3,3, 0)
DIM mesh4 AS Entitynode
mesh4 = CreateEntityNode(obj2, 0, 0, 0, %NULL)
' For good orientation cylinder For physical engine
PositionNode(mesh4, -20, 10 ,5)
RotateNode(mesh4, 0,0,90)
GlobalColorNode(mesh4, &h0ffff0000)
CreateBody(mesh4, %CYLINDER_PRIMITIVE, %False, 1.0, 0, 0, 0)
' Create Hinge Joint
CreateHingeJoint(mesh3, mesh4, -20,10, 5.0, 0, 1, 0)
'=============================================================
' Create two mesh For Slider Joint
'=============================================================
DIM mesh5 AS Entitynode
mesh5 = CreateEntityNode(obj1, 0, 0, 0, %NULL)
PositionNode(mesh5, -10, 10 ,2.5)
GlobalColorNode(mesh5, &h0ffff00ff)
CreateBody(mesh5, %BOX_PRIMITIVE, %True, 3, 3, 3, 0)
DIM mesh6 AS Entitynode
mesh6 = CreateEntityNode(obj2, 0, 0, 0, %NULL)
' For good orientation cylinder For physical engine
PositionNode(mesh6, -10, 12 ,7)
RotateNode(mesh6, 0,0,90)
GlobalColorNode(mesh6, &h0ff0f00ff)
CreateBody(mesh6, %CYLINDER_PRIMITIVE, %False, 1.0, 0, 0, 0)
' Create Hinge Joint
CreateSliderJoint(mesh5, mesh6, -10,10, 6.5, 0, 1, 0)
'=============================================================
' Create two mesh For Corks Crew Joint
'=============================================================
DIM mesh7 AS Entitynode
mesh7 = CreateEntityNode(obj1, 0, 0, 0, %NULL)
PositionNode(mesh7, 0, 10 ,2.5)
GlobalColorNode(mesh7, &h0ff0f000f)
CreateBody(mesh7, %BOX_PRIMITIVE, %True, 1.0, 0, 0, 0)
DIM mesh8 AS Entitynode
mesh8 = CreateEntityNode(obj2, 0, 0, 0, %NULL)
' For good orientation cylinder For physical engine
PositionNode(mesh8, 0, 12 ,7)
RotateNode(mesh8, 0,0,90)
GlobalColorNode(mesh8, &h0ff0ff00f)
CreateBody(mesh8, %CYLINDER_PRIMITIVE, %False, 1.0, 0, 0, 0)
' Create Hinge Joint
CreateCorkScrewJoint(mesh7, mesh8, 0,10, 6.5, 0, 1, 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,20,-27)
'-----------------------------------------
LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
DIM pbFONT AS IGUIFont
pbfont = GetFont()
' ---------------------------------------
' Main loop
' ---------------------------------------
GLOBAL dirx, diry, dirz AS SINGLE
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit = 1
END IF
IF GetKeyDown(%KEY_CODE.KEY_KEY_O) THEN
ApplyForceAndTorqueBody(mesh2, CODEPTR(ApplyForceAndTorque))
dirz=0
dirx=0
diry=8
END IF
IF GetKeyDown(%KEY_CODE.KEY_KEY_P) THEN
PulseBody(mesh3, 1,0,0, 1,0,0)
END IF
IF GetKeyDown(%KEY_CODE.KEY_KEY_I) THEN
PulseBody(mesh5, 0,5.8,0, 0,5.8,0)
END IF
IF GetKeyDown(%KEY_CODE.KEY_KEY_U) THEN
PulseBody(mesh7, 1,0,0, 1,0,0)
END IF
IF GetKeyDown(%KEY_CODE.KEY_KEY_J) THEN
PulseBody(mesh7, 0,5,0, 0,2,0)
END IF
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
NX3_DrawText(pbfont, "O Ball Joint", 10, 35,0,0, &h0ff9999ff)
NX3_DrawText(pbfont, "P Hinge joint", 10, 50,0,0, &h0ff9999ff)
NX3_DrawText(pbfont, "I Slider joint", 10, 65,0,0, &h0ff9999ff)
NX3_DrawText(pbfont, "U/J CorksCrew joint", 10, 80,0,0, &h0ff9999ff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
SUB ApplyForceAndTorque CDECL(BYVAL bdy AS NBody)
DirectForceBody(bdy, dirx, diry, dirz)
END SUB
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 201 as Test HighLevelShaders.
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
DECLARE SUB CallbackShader CDECL(BYVAL services AS NMaterialServices,BYVAL userData AS LONG)
DECLARE SUB CallbackShaderMaterial CDECL(BYVAL pbmat AS NMaterial)
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
DIM video AS LONG
video = %DEVICE_TYPES.EDT_DIRECT3D9
' Load an 3D Object
DIM obj2 AS Mesh
obj2 = CreateCubeMesh(1.0)
' Create a camera
DIM cam AS GLOBAL CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, 0,0,-5)
'-----------------------------------------
' Load And Create shader
DIM shad AS LONG
DIM shad2 AS LONG
VersionShader(%VERTEXSHADER_VERSION.EVST_VS_1_1, %PIXELSHADER_VERSION.EPST_PS_2_0)
IF video = %DEVICE_TYPES.EDT_DIRECT3D9 THEN
shad = CreateShaderHighLevel("media/d3d9.hlsl", _
"vertexMain", _
"media/d3d9.hlsl", _
"pixelMain", _
%EMT_SOLID, _
CODEPTR(CallbackShader), _
CODEPTR(CallbackShaderMaterial))
shad2 = CreateShaderHighLevel("media/d3d9.hlsl", _
"vertexMain", _
"media/d3d9.hlsl", _
"pixelMain", _
%EMT_TRANSPARENT_ADD_COLOR, _
CODEPTR(CallbackShader), CODEPTR(CallbackShaderMaterial))
ELSE
shad = CreateShaderHighLevel("media/opengl.vert", _
"vertexMain", _
"media/opengl.frag", _
"pixelMain", _
%EMT_SOLID, _
CODEPTR(CallbackShader), _
CODEPTR(CallbackShaderMaterial))
shad2 = CreateShaderHighLevel("media/opengl.vert", _
"vertexMain", _
"media/opengl.frag", _
"pixelMain", _
%EMT_TRANSPARENT_ADD_COLOR, _
CODEPTR(CallbackShader), _
CODEPTR(CallbackShaderMaterial))
END IF
' Create Skybox
DIM sky AS EntityNode
sky = CreateSkybox(LoadTexture("media/up.jpg"), _
LoadTexture("media/dn.jpg"), _
LoadTexture("media/lf.jpg"), _
LoadTexture("media/rt.jpg"), _
LoadTexture("media/ft.jpg"), _
LoadTexture("media/bk.jpg"), %NULL)
'-----------------------------------------
' add cube
DIM cube0 AS EntityNode
cube0 = CreateEntityNode(obj2, 0, 0, 0, %NULL)
PositionNode(cube0, -1,-1,1)
LoadTextureNode(cube0, "media/wall.jpg", 0, 0)
MaterialFlagNode(cube0, %EMF_LIGHTING, %False)
'-----------------------------------------
' add second cube
DIM cube AS EntityNode
cube = CreateEntityNode(obj2, 0, 0, 0, %NULL)
PositionNode(cube, 0,-1.3,0)
LoadTextureNode(cube, "media/wall.jpg", 0, 0)
MaterialFlagNode(cube, %EMF_LIGHTING, %False)
MaterialTypeNode(cube, shad)
'-----------------------------------------
' add third cube
DIM cube2 AS EntityNode
cube2 = CreateEntityNode(obj2, 0, 0, 0, %NULL)
PositionNode(cube2, 1,-1.3,1)
LoadTextureNode(cube2, "media/wall.jpg", 0, 0)
MaterialFlagNode(cube2, %EMF_LIGHTING, %False)
MaterialTypeNode(cube2, shad)
'-----------------------------------
' 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
TurnNode(cube0, 0,0.5,0, 0)
TurnNode(cube, 0,0.5,0, 0)
TurnNode(cube2, 0,0.5,0, 0)
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
NX3_DrawText(pbfont, "FPS as " + TRIM$(STR$(FPS())), 10, 25, 0, 0, &h0ffffffff)
NX3_DrawText(pbfont, "Primitives as "+ TRIM$(STR$(PrimitiveCountDrawn())), 10, 45, 0, 0, &h0ffffffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
SUB CallbackShaderMaterial CDECL(BYVAL pbmat AS NMaterial)
END SUB
' ShaderCallback as
' this procedure call at the each render pass.
' it is this area which will provide the data necessary
' For the shader run.
SUB CallbackShader CDECL(BYVAL services AS NMaterialServices, BYVAL userData AS LONG)
DIM mvp(17) AS SINGLE
DIM invWorld(17) AS SINGLE
DIM worldViewProj(17) AS SINGLE
DIM ppos(4) AS SINGLE
DIM pbcol(4) AS SINGLE
DIM world(17) AS SINGLE
NX3_GetWorldTransform(invWorld(0))
Matrix_Inverse(invWorld(0), invWorld(0))
VertexShaderConstantNMaterialServices(services, "mInvWorld", invWorld(0), 16)
'set clip matrix
GetProjectionTransform(worldViewProj(0))
GetViewTransform(mvp(0))
Matrix_Mul(worldViewProj(0), worldViewProj(0), mvp(0))
NX3_GetWorldTransform(mvp(0))
Matrix_Mul(worldViewProj(0), worldViewProj(0), mvp(0))
VertexShaderConstantNMaterialServices(services, "mWorldViewProj", worldViewProj(0), 16)
' set camera position
NodePosition(cam, ppos(0))
VertexShaderConstantNMaterialServices(services, "mLightPos", ppos(0), 3)
' set light color
pbcol(0)=0.0
pbcol(1)=1.0
pbcol(2)=1.0
pbcol(3)=0.0
VertexShaderConstantNMaterialServices(services, "mLightColor", pbcol(0), 4)
' set transposed world matrix
NX3_GetWorldTransform(world(0))
Matrix_Transposed(world(0), world(0))
VertexShaderConstantNMaterialServices(services, "mTransWorld", world(0), 16)
END SUB
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 203 as FIRST POSTPROCESSING TEST.
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
' Includes libraries
#INCLUDE "N3xtD.bi"
DECLARE SUB CallbackShader CDECL(BYVAL services AS NMaterialServices,BYVAL userData AS INTEGER)
DECLARE SUB EffectRender()
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
DIM shaderparameters(7) AS SINGLE
DIM video AS INTEGER
video = %DEVICE_TYPES.EDT_DIRECT3D9
ChangeWorkingDirectory("media")
'-----------------------------------
' add in memory management system a zip file
AddZipFileArchive("map-20kdm2.pk3" )
'-----------------------------------
' Load Quake3 scene Object
DIM obj AS Mesh
obj = LoadMesh("20kdm2.bsp", %HARDMAPPING.EHM_STATIC)
'-----------------------------------
' Create a mesh with one of the 3D Object loaded
DIM scene AS EntityNode
scene = CreateEntityNode(obj, 0, 0, 0, %NULL)
'-----------------------------------------
' Load And Create shader
DIM shad AS INTEGER
VersionShader(%VERTEXSHADER_VERSION.EVST_VS_1_1, %PIXELSHADER_VERSION.EPST_PS_2_0)
IF video = %DEVICE_TYPES.EDT_DIRECT3D9 THEN
shad = CreateShaderHighLevel(_
"Shaders/PP_DX_Vertex.fx",_
"main", _
"Shaders/PP_DX_Invert.fx", _
"main", _
%EMT_SOLID, CODEPTR(CallbackShader), _
%Null)
ELSE
shad = CreateShaderHighLevel(_
"Shaders/PP_GL_Vertex.fx", _
"main", _
"Shaders/PP_GL_Invert.fx", _
"main", %EMT_SOLID, _
CODEPTR(CallbackShader), _
%Null)
'shad = _CreateShaderHighLevel("Shaders/PP_GL_Vertex.fx","main", "Shaders/PP_GL_Bloom1.fx", "main", EMT_SOLID, @CallbackShader, Null)
'shaderparameters(0)=0.10
'shad = _CreateShaderHighLevel("Shaders/PP_GL_Vertex.fx","main", "Shaders/PP_GL_Bloom2.fx", "main", EMT_SOLID, @CallbackShader, Null)
'shaderparameters(0)=0.00185
'shad = _CreateShaderHighLevel("Shaders/PP_GL_Vertex.fx","main", "Shaders/PP_GL_Bloom3.fx", "main", EMT_SOLID, @CallbackShader, Null)
'shaderparameters(0)=0.00185
'shad = _CreateShaderHighLevel("Shaders/PP_GL_Vertex.fx","main", "Shaders/PP_GL_Bloom4.fx", "main", EMT_SOLID, @CallbackShader, Null)
'shaderparameters(0)=0.98
END IF
'---------------------------
' quad plane definition
' define 4 vertices
DIM pbid(6) AS GLOBAL INTEGER
DIM vvv(9*4) AS GLOBAL SINGLE
vvv(0) = -1 : vvv(1) = -1 : vvv(2) = 0 : vvv(3) = 0 : vvv(4) = 0 : vvv(5) = 0 : vvv(6) = &hff00ffff : vvv(7) = 0 : vvv(8) = 1
vvv(9) = -1 : vvv(10) = 1 : vvv(11) = 0 : vvv(12) = 0 : vvv(13) = 0 : vvv(14) = 0: vvv(15) = &hff00ffff : vvv(16) = 0 : vvv(17) = 0
vvv(18) = 1 : vvv(19) = 1 : vvv(20) = 0 : vvv(21) = 0 : vvv(22) = 0 : vvv(23) = 0: vvv(24) = &hff00ffff : vvv(25) = 1 : vvv(26) = 0
vvv(27) = 1 : vvv(28) = -1 : vvv(29) = 0 : vvv(30) = 0 : vvv(31) = 0 : vvv(32) = 0: vvv(33) = &hff00ffff : vvv(34) = 1 : vvv(35) = 1
' define 6 indices, For two triangles
pbid(0) = 0 : pbid(1) = 1 : pbid(2) = 2
pbid(3) = 0 : pbid(4) = 2 : pbid(5) = 3
' texture render definition
DIM firstmap AS NTexture
firstmap = CreateRenderTargetTexture( 512, 512, %ECF_UNKNOWN)
'dim secondmap as NTexture = Null
' New material
DIM material AS GLOBAL NMaterial
material = CreateMaterial(%NULL)
FlagMaterial( material, %EMF_WIREFRAME, %False)
FlagMaterial( material, %EMF_LIGHTING, %False)
TextureMaterial(material, 0, firstmap)
'_TextureMaterial(material, 1, secondmap)
FlagMaterial(material, %EMF_TEXTURE_WRAP, %ETC_CLAMP)
TypeMaterial(material, shad)
'-----------------------------------
' Create And position camera
DIM cam AS CameraNode
cam = CreateCameraFPS(80.0, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, %NULL)
PositionNode(cam, 726, 724, 330)
TargetCamera(cam, 800,730,400)
' ---------------------------------------
' Main loop
' ---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' ---------------
' Render
' ---------------
BeginScene(100,100,100, 255, 1, 1)
' element of scene render
RenderTarget( firstmap , %True, %True, &h0ff660000)
DrawScene()
' effect render
RenderTarget( %Null , %True, %True, 0)
' render effect
EffectRender()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
'--------------------------------
' effect render procedure
SUB EffectRender()
SetMaterial(material)
'_DrawIndexedTriangleList(varptr(vvv(0)), 4, Varptr(id(0)), 2)
DrawIndexedTriangleList(vvv(0), 4, pbid(0), 2)
END SUB
'--------------------------------
' ShaderCallback as
' this procedure call at the each render pass.
' it is this area which will provide the data necessary
' For the shader run.
SUB CallbackShader CDECL(BYVAL services AS NMaterialServices, BYVAL userData AS INTEGER)
DIM text1 AS SINGLE, text2 AS SINGLE
' with Bloom process as
'_PixelShaderConstantNMaterialServices(services, "vecValues" , varptr(shaderparameters(0)), 8)
IF(userData = 1) THEN
text1 = 0
PixelShaderConstantNMaterialServices(services, "texture1" , text1, 1)
text2 = 1
'_PixelShaderConstantNMaterialServices(services, "texture2" , Varptr(text2), 1)
END IF
END SUB
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 060 : test GUI: Button and CheckBox
' Historique :
' 05/05/09 19:16 TMyke
'
' ------------------------------------------------------------
'; Include files
#INCLUDE "n3xtD.bi"
'; Globales
FUNCTION PBMAIN
DIM app AS LONG
DIM i AS LONG
DIM Quit AS LONG
DIM angley AS SINGLE
DIM anglex AS SINGLE
';----------------------------------------------------------
'; open n3xt-D screen
app = CreateGraphics3D(800, 600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app = %Null THEN
EXIT FUNCTION
END IF
'-----------------------------------
' load an 3D object
DIM obj1 AS Mesh
obj1 = LoadMesh("media/earth.x" , %HARDMAPPING.EHM_STATIC)
' create several mesh
'-----------------------------------
FOR i = 0 TO 3
' create a mesh with one of the 3D object loaded
DIM sphere AS EntityNode
sphere = CreateEntityNode(obj1, 0, 0, 0, %NULL)
' set position
PositionNode(sphere, 3*i,0,0)
NEXT
'-----------------------------------
' load font png
LoadFont("media/font2.bmp", %FONT_TYPE.EGDF_DEFAULT)
DIM pbfont AS IGUIFont
pbfont = GetFont()
'-----------------------
' load Image
DIM logo AS NTexture
logo = LoadTexture("media/fireball.bmp")
'-----------------------
' add buttons
DIM button1 AS IGUIElement
button1 = AddButtonGUI(20, 195, 120, 224, "text1", "", %NULL , -1)
DIM button2 AS IGUIElement
button2 = AddButtonGUI(20,295,120,324, "text2", "button2", %NULL , -1)
Image_GUIButton(button2, logo)
'-----------------------
' add CheckBox
DIM check1 AS IGUICheckBox
check1 = AddCheckBoxGUI(%True, 10, 400, 110, 500, "checkbox", %NULL, -1)
'-----------------------------------------
' create first camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, 6,0,-10)
' ---------------------------------------
' main loop
' ---------------------------------------
WHILE Quit=0
' ------------------------------------------------
' move camera with dir key and mouse (left click)
IF GetMouseEvent(%MOUSE_EVENT.MOUSE_BUTTON_LEFT) THEN
angley = GetDeltaMouseX(0) / 4.0
anglex = GetDeltaMouseY(0) / 4.0
TurnNode(cam, anglex, angley, 0, 0)
END IF
'; if Escape Key, exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' ---------------
' Render
' ---------------
BeginScene(100,100,100, 255, 1, 1)
DrawScene()
DrawGUI()
NX3_DrawText(pbfont, "Button1 state: "+TRIM$(STR$(GUIButton_Pressed(button1))), 10,10,0,0, &H0ff00ffff)
NX3_DrawText(pbfont, "Button2 state: "+TRIM$(STR$(GUIButton_Pressed(button2))), 10,30,0,0, &H0ff00ffff)
NX3_DrawText(pbfont, "GUI CheckBox: "+TRIM$(STR$(GUICheckBox_Check(check1))), 10,50,0,0, &H0ff00ffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 061 : GUI Test: TextStatic, EditBox and Cursor Control
' Historique :
' 07/05/09 19:16 TMyke
'
' ------------------------------------------------------------
' Include files
#INCLUDE ONCE "windows.inc"
#INCLUDE "n3xtD.bi"
FUNCTION PBMAIN
DIM app AS DWORD
DIM Quit AS LONG
DIM i AS LONG
DIM pbres AS STRING
DIM angley AS SINGLE
DIM anglex AS SINGLE
'----------------------------------------------------------
' open n3xt-D screen
app = CreateGraphics3D(800, 600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app = %Null THEN
EXIT FUNCTION
END IF
'-----------------------------------
' load an 3D object
DIM obj1 AS GLOBAL Mesh
obj1 = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)
' create several mesh
'-----------------------------------
FOR i = 0 TO 3
' create a mesh with one of the 3D object loaded
DIM sphere AS EntityNode
sphere = CreateEntityNode(obj1, 0, 0, 0, %NULL)
' set position
PositionNode(sphere, 3*i,0,0)
NEXT
'-----------------------------------
' load font png
LoadFont("media/font2.bmp", %FONT_TYPE.EGDF_DEFAULT)
DIM pbfont AS GLOBAL IGUIFont
pbfont = GetFont()
'-----------------------
' zone text
DIM pbtext AS IGUIStaticText
pbtext = AddStaticText("text text text", 120, 10, 450, 230, %True, %True, %False, %NULL, -1)
BackgroundColor_GUIText(pbtext, &H055808099)
'-----------------------
' edit box
DIM editbox AS IGUIEditBox
editbox = AddEditBox("essais", 20, 335, 260, 400, %True, %Null, -1)
Multiline_GUIEditBox(editbox, %True)
AutoScroll_GUIEditBox(editbox, %true)
OverrideColor_GUIEditBox(editbox, &H0ffff0000)
' set alignment of text inside the EditBox
TextAlignment_GUIEditBox(editbox, %TEXT_ALIGN.EGUIA_UPPERLEFT, %TEXT_ALIGN.EGUIA_SCALE)
'-----------------------------------------
' create first camera
DIM cam AS GLOBAL CameraNode
cam = CreateCamera(%Null)
PositionNode(cam, 6,0,-10)
' ---------------------------------------
' main loop
' ---------------------------------------
GLOBAL posx AS LONG
GLOBAL posy AS LONG
WHILE Quit=0
CursorControlPosition(posx, posy)
IF GetKeyUp(%KEY_CODE.KEY_SPACE) THEN
';_PositionCursorControl( 400, 300)
TextGUI(pbtext, "other" + CHR$(13) + " text area")
END IF
IF GetKeyUp(%KEY_CODE.KEY_KEY_T) THEN
pbres = CONST2STR(BYVAL GUIText(editbox))
TextGUI(pbtext, (pbres))
END IF
' move camera with dir key and mouse (left click)
IF GetKeyDown(%KEY_CODE.KEY_KEY_F) THEN
MoveGUI(pbtext, 1,0)
END IF
IF GetKeyDown(%KEY_CODE.KEY_KEY_G) THEN
MoveGUI(pbtext, 0,1)
END IF
' ------------------------------------------------
' move camera with dir key and mouse (left click)
IF GetMouseEvent(%MOUSE_EVENT.MOUSE_BUTTON_LEFT) THEN
angley = GetDeltaMouseX(0) / 4.0
anglex = GetDeltaMouseY(0) / 4.0
TurnNode(cam, anglex, angley,0, 0)
END IF
' if Escape Key, exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' ---------------
' Render
' ---------------
BeginScene(100, 100, 100, 255, 1, 1)
DrawScene()
DrawGUI()
NX3_DrawText(pbfont, "Press SPACE key to change Text inside TextZone", 10,600-20,0,0, &H0ff00ffff)
NX3_DrawText(pbfont, "Press T key to get and draw in TextZone the EditBox Text", 10,600-40,0,0, &H0ff00ffff)
NX3_DrawText(pbfont, "Cursor Position: "+TRIM$(STR$(posx))+" " + TRIM$(STR$(posy)), 10,600-60,0,0, &H0ff00ffff)
NX3_DrawText(pbfont, "Press F/G key for move TextStatic Zone", 10,600-80,0,0, &H0ff00ffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
new Include
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 062 : TestGUI with FileOpenDialog and ContextMenu
' Historique :
' 15/05/09 19:16 TMyke
'
' ------------------------------------------------------------
#INCLUDE "windows.inc"
#INCLUDE "n3xtD.bi"
DECLARE SUB ContextMenu CDECL()
DECLARE SUB pbGUIEventCallBack CDECL(BYVAL eventGUI AS LONG, BYVAL idGUI AS LONG, BYVAL GUIElement AS IGUIElement)
FUNCTION PBMAIN
' Globales
DIM app AS LONG
DIM Quit AS LONG
'----------------------------------------------------------
' open n3xt-D screen
app = CreateGraphics3D(800, 600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app = %Null THEN
EXIT FUNCTION
END IF
'-----------------------------------
' load an 3D object
DIM obj1 AS GLOBAL Mesh
obj1 = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)
' create several mesh
'-----------------------------------
' create a mesh with one of the 3D object loaded
DIM sphere AS EntityNode
sphere = CreateEntityNode(obj1, 0, 0, 0, %NULL)
'-----------------------------------
' load font png
LoadFont("media/font2.bmp", %FONT_TYPE.EGDF_DEFAULT)
DIM pbfont AS IGUIFont
pbfont = GetFont()
'-----------------------
' add buttons
DIM button1 AS IGUIElement
button1 = AddButtonGUI(20,20,120,45, "fileselector","button1", %Null, 1 )
DIM button2 AS IGUIElement
button2 = AddButtonGUI(120,20,220,45, "contextMenu", "button2", %Null, 2 )
'-----------------------
' ADD COMBOBOX
DIM combo AS IGUIComboBox
combo = AddComboBoxGUI( 10, 300, 150, 320, %Null, 10)
AddItem_GUIComboBox(combo, "one")
AddItem_GUIComboBox(combo, "two")
AddItem_GUIComboBox(combo, "tree")
AddItem_GUIComboBox(combo, "four")
'------------------------------------------------------------------
' SET CALLBACK procedure FOR EVENT interpret
GUIEventCallBack(CODEPTR (pbGUIEventCallBack))
'-----------------------------------------
' CREATE first camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, 0,0,-7)
' ---------------------------------------
' MAIN LOOP
' ---------------------------------------
DIM pbres AS GLOBAL STRING
pbres ="a"
DIM tt AS GLOBAL STRING
DIM dial AS IGUIFileOpenDialog
WHILE Quit = 0
' IF Escape Key, EXIT
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' ---------------
' RENDER
' ---------------
BeginScene(100,100,100, 255, 1, 1)
DrawScene()
DrawGUI()
EndScene()
WEND
' END
FreeEngine()
END FUNCTION
'------------------------------------------------------------------
' CALLBACK procedure FOR EVENT interpret
SUB pbGUIEventCallBack CDECL(BYVAL eventGUI AS LONG, BYVAL pbidGUI AS LONG, BYVAL GUIElement AS IGUIElement)
LOCAL pbitem AS LONG
LOCAL idx AS IGUIContextMenu
'---------------------------------------------
' DISPLAY the ComboxBox SELECT
IF eventGUI = %GUI_EVENT_TYPE.EGET_COMBO_BOX_CHANGED THEN
pbitem = GUIComboBox_Selected(GUIElement)
MSGBOX CONST2STR(BYVAL GUIComboBox_Item(GUIElement, pbitem))
END IF
'---------------------------------------------
' buttons test EVENTS
IF eventGUI = %GUI_EVENT_TYPE.EGET_BUTTON_CLICKED THEN
IF pbidGUI = 2 THEN ' ContextMenu buttom
ContextMenu()
ELSE
AddFileOpenDialogGUI( "title", %True, %Null, 100)
END IF
END IF
'---------------------------------------------
' END fileOpenDialog AND DISPLAY the filename
IF eventGUI = %GUI_EVENT_TYPE.EGET_FILE_SELECTED THEN
'; GET curent GUIElement detected
MSGBOX CONST2STR(BYVAL GUIFileOpenDialog_FileName(GUIElement))
END IF
'---------------------------------------------
' CONTEXT MENU interpret
IF eventGUI = %GUI_EVENT_TYPE.EGET_MENU_ITEM_SELECTED THEN
idx = GUIContexMenu_ItemSelected(GUIElement)
'Debug idx
MSGBOX CONST2STR(BYVAL GUIContexMenu_ItemText(GUIElement, idx))
END IF
END SUB
SUB ContextMenu CDECL()
DIM pbmenu AS IGUIContextMenu
DIM pbsubmenu AS IGUIContextMenu
pbmenu = AddContexMenuGUI(210, 150, 350, 250, %Null, 49)
AddItem_GUIContexMenu(pbmenu, "text1", 50, %True, %False, %False)
AddItem_GUIContexMenu(pbmenu, "text2", 51, %True, %False, %False)
AddSeparator_GUIContexMenu(pbmenu)
AddItem_GUIContexMenu(pbmenu, "text3", 52, %True, %True, %False)
AddItem_GUIContexMenu(pbmenu, "text4", 55, %True, %False, %False)
' SUB MENU
pbsubmenu = GUIContexMenu_SubMenu(pbmenu, 3)
AddItem_GUIContexMenu(pbsubmenu, "subText31", 53, %True, %False, %True)
AddItem_GUIContexMenu(pbsubmenu, "subText32", 54, %True, %False, %True)
END SUB
New Include
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 063 : test GUI InOutFader
' Historique :
' 15/05/09 19:16 TMyke
'
' ------------------------------------------------------------
'; Include files
#INCLUDE "n3xtD.bi"
FUNCTION PBMAIN
' Globales
DIM app AS LONG
DIM Quit AS LONG
'----------------------------------------------------------
' open n3xt-D screen
app = CreateGraphics3D(800, 600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app = %Null THEN
EXIT FUNCTION
END IF
'-----------------------------------
' load an 3D object
DIM obj1 AS Mesh
OBJ1 = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)
' create several mesh
'-----------------------------------
' create a mesh with one of the 3D object loaded
DIM sphere AS EntityNode
sphere = CreateEntityNode(obj1, 0, 0, 0, %NULL)
'-----------------------------------
' load font png
LoadFont("media/font2.bmp", %FONT_TYPE.EGDF_DEFAULT)
DIM pbfont AS IGUIFont
pbfont = GetFont()
'-----------------------
' create GUI Image
DIM logo AS NTexture
logo = LoadTexture("media/logo_320.png")
DIM img AS IGUIImage
img = AddImageGUI(logo, 0,15, %True, "text", %Null, -1)
'-----------------------
' create InOutFader
DIM pbrect(3) AS GLOBAL LONG
pbrect(0) = 0
pbrect(1) = 0
pbrect(2) = 320
pbrect(3) = 200
DIM pbinout AS LONG
pbinout = AddInOutFaderGUI(pbrect(0), BYVAL %Null, -1)
Color_GUIInOutFader(pbinout, &H00646464)
'-----------------------------------------
' create first camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, 6,0,-10)
' ---------------------------------------
' main loop
' ---------------------------------------
WHILE Quit = %Null
IF GetKeyUp(%KEY_CODE.KEY_KEY_I) THEN
FadeIn_GUIInOutFader(pbinout, 1500)
END IF
IF GetKeyUp(%KEY_CODE.KEY_KEY_O) THEN
FadeOut_GUIInOutFader(pbinout, 1500)
END IF
'; if Escape Key, exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' ---------------
' Render
' ---------------
BeginScene(100, 100, 100, 255, 1, 1)
DrawScene()
DrawGUI()
NX3_DrawText(pbfont, "Press O, and after I Keys", 10,510,0,0, &H0ff00ffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
New Include
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 065 : TestGUI with Menu
' Historique :
' 15/05/09 19:16 TMyke
'
' ------------------------------------------------------------
#INCLUDE "n3xtD.bi"
DECLARE SUB pbGUIEventCallBack CDECL(BYVAL eventGUI AS LONG, BYVAL idGUI AS LONG, BYVAL GUIElement AS IGUIElement)
FUNCTION PBMAIN
' Globales
DIM app AS LONG
DIM Quit AS LONG
'----------------------------------------------------------
' open n3xt-D screen
app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app = %Null THEN
EXIT FUNCTION
END IF
'-----------------------------------
' load an 3D object
DIM obj1 AS GLOBAL Mesh
obj1 = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)
' create several mesh
'-----------------------------------
' create a mesh with one of the 3D object loaded
DIM sphere AS EntityNode
sphere = CreateEntityNode(obj1, 0, 0, 0, %NULL)
'-----------------------------------
' load font png
LoadFont("media/font2.bmp", %FONT_TYPE.EGDF_DEFAULT)
DIM pbfont AS IGUIFont
pbfont = GetFont()
'--------------------------------------------------------
' create menu
DIM pbmenu AS GLOBAL IGUIContextMenu
DIM submenu AS GLOBAL IGUIContextMenu
pbmenu = AddMenuGUI(%NULL, -1)
' main menu item
AddItem_GUIContexMenu(pbmenu, "menu1", -1, %True, %True, %False)
AddItem_GUIContexMenu(pbmenu, "menu2", -1, %True, %True, %False)
AddItem_GUIContexMenu(pbmenu, "menu3", -1, %True, %True, %False)
AddItem_GUIContexMenu(pbmenu, "menu4", -1, %True, %True, %False)
' sub menu 0
submenu = GUIContexMenu_SubMenu(pbmenu, 0)
AddItem_GUIContexMenu(submenu, "submenu01", 501, %True, %False, %False)
AddItem_GUIContexMenu(submenu, "submenu02", 502, %True, %False, %False)
'; sub menu 1
submenu = GUIContexMenu_SubMenu(pbmenu, 1)
AddItem_GUIContexMenu(submenu, "submenu11", 511, %True, %False, %False)
AddItem_GUIContexMenu(submenu, "submenu12", 512, %True, %False, %False)
'; sub menu 2
submenu = GUIContexMenu_SubMenu(pbmenu, 2)
AddItem_GUIContexMenu(submenu, "submenu21", 521, %True, %False, %False)
AddItem_GUIContexMenu(submenu, "submenu22", 522, %True, %False, %False)
AddItem_GUIContexMenu(submenu, "submenu23", 523, %True, %False, %False)
AddItem_GUIContexMenu(submenu, "submenu23", 524, %True, %False, %False)
'; sub menu 3
submenu = GUIContexMenu_SubMenu(pbmenu, 3)
AddItem_GUIContexMenu(submenu, "subText31", 531, %True, %False, %True )
AddSeparator_GUIContexMenu(submenu)
AddItem_GUIContexMenu(submenu, "subText32", 532, %True, %False, %False)
'------------------------------------------------------------------
' set callback procedure for event interpret
GUIEventCallBack(CODEPTR (pbGUIEventCallBack))
'-----------------------------------------
' create first camera
DIM cam AS GLOBAL CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, 0,0,-7)
' ---------------------------------------
' main loop
' ---------------------------------------
WHILE Quit = 0
' if Escape Key, exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' ---------------
' Render
' ---------------
BeginScene(100,100,100, 255, 1, 1)
DrawScene()
DrawGUI()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
';------------------------------------------------------------------
'; callback procedure for event interpret
SUB pbGUIEventCallBack(BYVAL eventGUI AS LONG, BYVAL pbidGUI AS LONG, BYVAL GUIElement AS IGUIElement)
LOCAL idx AS LONG
IF eventGUI = %GUI_EVENT_TYPE.EGET_MENU_ITEM_SELECTED THEN
idx = GUIContexMenu_ItemSelected(GUIElement)
ztrace TRIM$(STR$(idx))
ztrace BYVAL GUIContexMenu_ItemText(GUIElement, idx)
END IF
END SUB
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 066 : TestGUI with ScrollBar, tabControl ,spinbox, etc...
' Historique :
' 20/05/09 19:16 TMyke
'
' ------------------------------------------------------------
'
#INCLUDE "n3xtD.bi"
DECLARE SUB pbGUIEventCallBack CDECL (BYVAL eventGUI AS LONG, BYVAL idGUI AS LONG, BYVAL GUIElement AS IGUIElement)
FUNCTION PBMAIN
' Globales
DIM app AS LONG
DIM Quit AS LONG
DIM i 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
'-----------------------------------
' load an 3D object
DIM obj1 AS Mesh
obj1 = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)
' create several mesh
'-----------------------------------
' create a mesh with one of the 3D object loaded
DIM sphere AS EntityNode
sphere = CreateEntityNode(obj1, 0, 0, 0, %NULL)
'-----------------------------------
' load font png
LoadFont("media/font2.bmp", %FONT_TYPE.EGDF_DEFAULT)
DIM pbfont AS GLOBAL IGUIFont
pbfont = GetFont()
'--------------------------------------------------------
' create scrollbar
AddScrollBarGUI(%True, 10,80,150,95, %NULL, -1)
AddScrollBarGUI(%False, 165 ,80, 180, 200, %NULL, -1)
'--------------------------------------------------------
' create spinbox
DIM spinbox AS IGUISpinBox
spinbox = AddSpinBoxGUI("text", 20, 300, 250, 325, %True, BYVAL %NULL, -1)
DecimalPlaces_GUISpinBox(spinbox, 3)
'--------------------------------------------------------
' create tabcontrol
DIM tabcontrol AS IGUITabControl
tabcontrol = AddTabControlGUI(380,15,750,350, %False, %True, BYVAL %NULL, -1)
' add tab 1
DIM tab1 AS IGUITab
tab1 = AddTab_GUITabControl(tabcontrol, "caption1", -1)
' add tab 2
DIM tab2 AS IGUITab
tab2 = AddTab_GUITabControl(tabcontrol, "caption2", -1)
DrawBackground_GUITab(tab2, %True)
BackgroundColor_GUITab(tab2, &H0ffFF5500)
TextColor_GUITab(tab2, &H0ffFF5500)
' zone text in tab1
AddStaticText("n3xtDn3xtDn3xtDn3xtDn3xtD", 10,20,190,45, %False, %False, %False, tab1, -1)
' add buttons in tab1
AddButtonGUI(20,150,120,170, "button1","button1", tab1, -1)
' zone text in Tab2
AddStaticText("PowerBASICPowerBASICPowerBASIC", 10,20,190,45, %False, %False, %False, tab2, -1)
AddScrollBarGUI( %True, 10,80,150,95, tab2, -1)
'--------------------------------------------------------
' create table
DIM table AS IGUITable
table = AddTableGUI(20, 350, 214, 580, %True, BYVAL %NULL, -1)
AddColumn_GUITable(table, "column1", -1)
AddColumn_GUITable(table, "column2", -1)
AddColumn_GUITable(table, "column3", -1)
FOR i = 0 TO 7
AddRow_GUITable(table, i )
NEXT
CellText_GUITable(table,1,1, "text1", &h0ffffffff)
CellText_GUITable(table,1,2, "text2", &h0ffffffff)
CellText_GUITable(table,0,2, "text3", &h0ffffffff)
CellText_GUITable(table,4,0, "text4", &H0ffff00ff)
' change window caption color
DIM skin AS IGUISkin
skin = SkinGUI_Curent()
Color_GUISkin(skin, %APP_FLAG.EGDC_ACTIVE_CAPTION , &H0ffffff00)
' create window
DIM win AS IGUIWindow
win = AddWindowGUI(300, 400, 550, 590, "PressSPACE bar", %FALSE, BYVAL %NULL, -1)
' add buttons in windows
AddButtonGUI(20,100,80,120, "button1","button1", win, -1)
'------------------------------------------------------------------
' set callback procedure for event interpret
GUIEventCallBack(CODEPTR (pbGUIEventCallBack))
'-----------------------------------------
' create first camera
DIM cam AS CameraNode
cam = CreateCamera(BYVAL %NULL)
PositionNode(cam, 0,0,-7)
' ---------------------------------------
' main loop
' ---------------------------------------
WHILE Quit = 0
' if Escape Key, exit
IF GetKeyUp(%KEY_CODE.KEY_SPACE) THEN
AddMessageBoxGUI("Messagebox", "test message", %True, %EMBF_OK, BYVAL %NULL, -1)
END IF
' if Escape Key, exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit = 1
END IF
' ---------------
' Render
' ---------------
BeginScene(100, 100, 100, 255, 1, 1)
DrawScene()
DrawGUI()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
'------------------------------------------------------------------
' callback procedure for event interpret
SUB pbGUIEventCallBack CDECL(BYVAL eventGUI AS LONG, BYVAL pbidGUI AS LONG, BYVAL GUIElement AS IGUIElement)
DIM idx AS LONG
DIM ids AS SINGLE
DIM pbrow AS LONG
DIM pbcolumn AS LONG
IF eventGUI = %GUI_EVENT_TYPE.EGET_SCROLL_BAR_CHANGED THEN
idx = GUIScrollBar_Pos(GUIElement)
ztrace STR$(idx)
END IF
IF eventGUI = %GUI_EVENT_TYPE.EGET_SPINBOX_CHANGED THEN
ids = GUISpinBox_Value(GUIElement)
ztrace STR$(ids)
END IF
IF eventGUI = %GUI_EVENT_TYPE.EGET_TABLE_CHANGED THEN
pbrow = GUITable_Selected(GUIElement)
pbcolumn = GUITable_ActiveColumn(GUIElement)
ztrace BYVAL GUITable_CellText(GUIElement, pbrow, pbcolumn )
END IF
END SUB
New Include
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 067 : TestGUI load GUI Elements..
' Historique :
' 22/05/09 19:16 TMyke
'
' ------------------------------------------------------------
#INCLUDE "n3xtD.bi"
DECLARE SUB pbGUIEventCallBack CDECL (BYVAL eventGUI AS LONG, BYVAL idGUI AS LONG, BYVAL GUIElement AS IGUIElement)
FUNCTION PBMAIN
' Globales
DIM app AS LONG
DIM Quit AS LONG
'----------------------------------------------------------
' open n3xt-D screen
app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app = %Null THEN
EXIT FUNCTION
END IF
'-----------------------------------
' load an 3D object
DIM obj1 AS Mesh
obj1 = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)
' create several mesh
'-----------------------------------
' create a mesh with one of the 3D object loaded
DIM sphere AS EntityNode
sphere = CreateEntityNode(obj1, 0, 0, 0, %NULL)
'-----------------------------------
' load font png
LoadFont("media/font2.bmp", %FONT_TYPE.EGDF_DEFAULT)
DIM pbfont AS GLOBAL IGUIFont
pbfont = GetFont()
'-----------------------------------------
' create first camera
DIM cam AS CameraNode
cam = CreateCamera(BYVAL %NULL)
PositionNode(cam, 0,0,-7)
DIM flag AS LONG
Flag = %True
' ---------------------------------------
' main loop
' ---------------------------------------
WHILE Quit = 0
' if Escape Key, exit
IF GetKeyUp(%KEY_CODE.KEY_SPACE) AND flag THEN
Load_GUI( "media/guiTest.gui", BYVAL %Null)
flag = %False
' set callback procedure for event interpret
GUIEventCallBack(CODEPTR (pbGUIEventCallBack))
END IF
' if Escape Key, exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' ---------------
' Render
' ---------------
BeginScene(100, 100, 100, 255, 1, 1)
DrawScene()
DrawGUI()
nx3_DrawText(pbfont, "Press SPACE Bar to load GUI elements", 550,10,0,0, &Hff00ffff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
'------------------------------------------------------------------
' callback procedure for event interpret
'------------------------------------------------------------------
' callback procedure for event interpret
SUB pbGUIEventCallBack CDECL(BYVAL eventGUI AS LONG, BYVAL pbidGUI AS LONG, BYVAL GUIElement AS IGUIElement)
DIM idx AS LONG
DIM ids AS SINGLE
DIM pbrow AS LONG
DIM pbcolumn AS LONG
IF eventGUI = %GUI_EVENT_TYPE.EGET_SCROLL_BAR_CHANGED THEN
idx = GUIScrollBar_Pos(GUIElement)
ztrace STR$(idx)
END IF
IF eventGUI = %GUI_EVENT_TYPE.EGET_SPINBOX_CHANGED THEN
ids = GUISpinBox_Value(GUIElement)
ztrace STR$(ids)
END IF
IF eventGUI = %GUI_EVENT_TYPE.EGET_TABLE_CHANGED THEN
pbrow = GUITable_Selected(GUIElement)
pbcolumn = GUITable_ActiveColumn(GUIElement)
IF pbcolumn >= 0 THEN
ztrace BYVAL GUITable_CellText(GUIElement, pbrow, pbcolumn )
END IF
END IF
END SUB
New Include
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 068 : TestGUI with Menu and toolbar
' Historique :
' 10/06/09 19:16 TMyke
'
' ------------------------------------------------------------
#INCLUDE "n3xtD.bi"
DECLARE SUB pbGUIEventCallBack CDECL(BYVAL eventGUI AS LONG, BYVAL idGUI AS LONG, BYVAL GUIElement AS IGUIElement)
GLOBAL nullstring AS ASCIZ * 10
FUNCTION PBMAIN
' Globales
DIM app AS LONG PTR
DIM Quit AS LONG
DIM i AS LONG
'----------------------------------------------------------
' open n3xt-D screen
app = CreateGraphics3D(800, 600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app = %Null THEN
EXIT FUNCTION
END IF
'-----------------------------------
' load an 3D object
DIM obj1 AS Mesh
obj1 = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)
' create several mesh
'-----------------------------------
' create a mesh with one of the 3D object loaded
DIM sphere AS EntityNode
sphere = CreateEntityNode(obj1, 0, 0, 0, %NULL)
'-----------------------------------
' load font png
LoadFont("media/font2.bmp", %FONT_TYPE.EGDF_DEFAULT)
DIM pbfont AS GLOBAL IGUIFont
pbfont = GetFont()
'--------------------------------------------------------
' create menu
DIM pbmenu AS IGUIContextMenu
DIM submenu AS IGUIContextMenu
pbmenu = AddMenuGUI(BYVAL %NULL, -1)
'; main menu item
AddItem_GUIContexMenu(pbmenu, "menu1", -1, %True, %True, %False)
AddItem_GUIContexMenu(pbmenu, "menu2", -1, %True, %True, %False)
AddItem_GUIContexMenu(pbmenu, "menu3", -1, %True, %True, %False)
AddItem_GUIContexMenu(pbmenu, "menu4", -1, %True, %True, %False)
' sub menu 0
submenu = GUIContexMenu_SubMenu(pbmenu, 0)
AddItem_GUIContexMenu(submenu, "submenu01", 501, %True, %False, %False)
AddItem_GUIContexMenu(submenu, "submenu02", 502, %True, %False, %False)
' sub menu 1
submenu = GUIContexMenu_SubMenu(pbmenu, 1)
AddItem_GUIContexMenu(submenu, "submenu11", 511, %True, %False, %False)
AddItem_GUIContexMenu(submenu, "submenu12", 512, %True, %False, %False)
' sub menu 2
submenu = GUIContexMenu_SubMenu(pbmenu, 2)
AddItem_GUIContexMenu(submenu, "submenu21", 521, %True, %False, %False)
AddItem_GUIContexMenu(submenu, "submenu22", 522, %True, %False, %False)
AddItem_GUIContexMenu(submenu, "submenu23", 523, %True, %False, %False)
AddItem_GUIContexMenu(submenu, "submenu23", 524, %True, %False, %False)
' sub menu 3
submenu = GUIContexMenu_SubMenu(pbmenu, 3)
AddItem_GUIContexMenu(submenu, "subText31", 531, %True, %False, %True )
AddSeparator_GUIContexMenu(submenu)
AddItem_GUIContexMenu(submenu, "subText32", 532, %True, %False, %False)
'------------------------------------------------
' create tool bar
DIM tb AS IGUIToolBar
tb = AddToolBarGUI(BYVAL %NULL, -1)
DIM pbimage AS NTexture
pbimage = LoadTexture("media/open.png")
AddButton_GUIToolBar(tb, nullstring, "Open a model", pbimage, BYVAL %Null, %False, %True, 1000)
pbimage = LoadTexture("media/tools.png")
AddButton_GUIToolBar(tb, nullstring, "Open Toolset", pbimage, BYVAL %Null, %False, %True, 1001)
pbimage = LoadTexture("media/zip.png")
AddButton_GUIToolBar(tb, nullstring, "Zip Archive", pbimage, BYVAL %Null, %False, %True, 1002)
pbimage = LoadTexture("media/help.png")
AddButton_GUIToolBar(tb, nullstring, "Help menu", pbimage, BYVAL %Null, %False, %True, 1003)
DIM pbcolor AS DWORD
'; disable alpha of the menu items
FOR i = 0 TO 2
pbcolor = GUIColor( i)
pbcolor = (pbcolor OR &H0ff000000)
ColorGUI(i, pbcolor)
NEXT
'------------------------------------------------------------------
' set callback procedure for event interpret
GUIEventCallBack(CODEPTR(pbGUIEventCallBack()))
'-----------------------------------------
' create first camera
DIM cam AS GLOBAL CameraNode
cam = CreateCamera(BYVAL %NULL)
PositionNode(cam, 0,0,-7)
' ---------------------------------------
' main loop
' ---------------------------------------
WHILE Quit = 0
' if Escape Key, exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' ---------------
' Render
' ---------------
BeginScene(100, 100, 100, 255, 1, 1)
DrawScene()
DrawGUI()
EndScene()
WEND
'; end
FreeEngine()
END FUNCTION
';------------------------------------------------------------------
'; callback procedure for event interpret
SUB pbGUIEventCallBack CDECL(BYVAL eventGUI AS LONG, BYVAL pbidGUI AS LONG, BYVAL GUIElement AS IGUIElement)
DIM idx AS LONG
IF eventGUI= %GUI_EVENT_TYPE.EGET_MENU_ITEM_SELECTED THEN
idx = GUIContexMenu_ItemSelected(GUIElement)
ztrace(STR$(idx))
ztrace(BYVAL GUIContexMenu_ItemText(GUIElement, idx))
END IF
IF eventGUI = %GUI_EVENT_TYPE.EGET_BUTTON_CLICKED THEN
ztrace STR$(pbidGUI)
END IF
END SUB
New Include
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 069 : Skin GUI test 1
' Historique :
' 07/08/09 19:16 TMyke
'
' ------------------------------------------------------------
' Include files
#INCLUDE "n3xtD.bi"
GLOBAL nullstr AS ASCIZ * 10
' Globales
FUNCTION PBMAIN
DIM app AS DWORD PTR
DIM Quit AS LONG
'----------------------------------------------------------
' 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
SetCurrentDirectory("media/")
'-----------------------------------
' LOAD an 3D OBJECT
DIM obj1 AS GLOBAL Mesh
obj1 = LoadMesh("earth.x", %HARDMAPPING.EHM_STATIC)
' CREATE several mesh
'-----------------------------------
' CREATE a mesh WITH one OF the 3D OBJECT loaded
DIM sphere AS EntityNode
sphere = CreateEntityNode(obj1, 0, 0, 0, %NULL)
' CREATE Skybox
DIM sky AS GLOBAL EntityNode
sky = CreateSkybox(LoadTexture("up.jpg"), _
LoadTexture("dn.jpg"), _
LoadTexture("lf.jpg"), _
LoadTexture("rt.jpg"), _
LoadTexture("ft.jpg"), _
LoadTexture("bk.jpg"), _
BYVAL %NULL)
'-----------------------------------------
' CREATE first camera
DIM cam AS GLOBAL CameraNode
cam = CreateCamera(BYVAL %NULL)
PositionNode(cam, 0,0,-5)
'-----------------------------------------------
'-----------------------------------------------
' GUI AREA
'-----------------------------------
' LOAD FONT png
LoadFont("ui1/fontlucida.png", %FONT_TYPE.EGDF_DEFAULT)
' LOAD AND CREATE Skin GUI
DIM skin AS CCustomGUISkin
skin = CustomSkinGUI("ui1/guiskin.cfg")
' SET differents Skin COLOR
Color_GUISkin(skin, %APP_FLAG.EGDC_3D_FACE , &H0eecccccc)
Color_GUISkin(skin, %APP_FLAG.EGDC_ACTIVE_CAPTION , &H0ff000000)
Color_GUISkin(skin, %APP_FLAG.EGDC_BUTTON_TEXT , &H0ff000000)
'-----------------------------------------------
' some gadget FOR test
DIM win AS IGUIWindow
win = AddWindowGUI(60,60,260,260, "SkinGUI", %False, BYVAL %NULL, 1)
AddButtonGUI(10,40,80,65, "Button", nullstr, win, -1)
AddStaticText("Checkbox", 30, 130, 120, 150, %False, %True, %False, win, -1)
AddButtonGUI(700,40,760,75, "Quit", "quit!", BYVAL %NULL, -1)
DIM editbox AS IGUIEditBox
editbox = AddEditBox("Edit Box", 310,120,460,250, %True, BYVAL %Null , -1)
Multiline_GUIEditBox(editbox, %True)
AutoScroll_GUIEditBox(editbox, %True)
OverrideColor_GUIEditBox(editbox, &Hffff0000)
' SET alignment OF TEXT inside the EditBox
TextAlignment_GUIEditBox(editbox, %TEXT_ALIGN.EGUIA_UPPERLEFT, %TEXT_ALIGN.EGUIA_SCALE)
'--------------------------------------------------------
' progress BAR
DIM pbbar AS IGUIProgressBar
pbbar = AddProgressBarGUI(60,300,260,330, BYVAL %NULL)
Value_ProgressBarGUI(pbbar, 0.5)
Color_GUIProgressBar(pbbar, &Hffaaaa00)
AutomaticText_GUIProgressBar(pbbar, "progress")
'--------------------------------------------------------
' CREATE SCROLLBAR
AddScrollBarGUI( %True, 310,80,450, 95, BYVAL %NULL, -1)
'-----------------------
' ADD COMBOBOX
DIM combo AS IGUIComboBox
combo = AddComboBoxGUI( 480, 120, 620, 140, %Null, 10)
AddItem_GUIComboBox(combo, "one")
AddItem_GUIComboBox(combo, "two")
AddItem_GUIComboBox(combo, "tree")
AddItem_GUIComboBox(combo, "four")
' ---------------------------------------
' MAIN LOOP
' ---------------------------------------
WHILE quit = 0
' just turn our sphere
TurnNode(sphere, 0,0.5,0, 0)
' IF Escape Key, EXIT
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit = 1
END IF
' ---------------
' RENDER
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
DrawGUI()
EndScene()
WEND
' END
FreeEngine()
END FUNCTION
New Include
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 112 : Test body with bridge
' 23/08/09 19:16 TMyke
'
' ------------------------------------------------------------
' Include files
#INCLUDE "n3xtD.bi"
DECLARE FUNCTION CreateRope(BYVAL posx AS SINGLE, BYVAL posy AS SINGLE, BYVAL posz AS SINGLE) AS LONG
DECLARE SUB JointCallBack CDECL(BYVAL joint AS NJoint, BYVAL desc AS NewtonHingeSliderUpdateDesc)
FUNCTION PBMAIN
'; Globales
DIM app AS GLOBAL LONG PTR
DIM Quit AS GLOBAL LONG
DIM cylT AS GLOBAL 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 and load mesh
DIM cubemesh AS GLOBAL Mesh
cubemesh = CreateCubeMesh(1.0)
'-----------------------------------------
' create a static base
DIM floor AS EntityNode
floor = CreateEntitynode(cubemesh, 0, 0, 0, %NULL)
PositionNode(floor, 0,0,0)
LoadTextureNode(floor, "media/grille1.bmp", 0, 0)
ScaleNode(floor, 20,1,20)
' create body, no dynamique
CreateBody(floor, %BOX_PRIMITIVE, %False, 1.0, 0, 0, 0)
' link all joint with the plateform base static
DIM downNode1 AS EntityNode
downNode1 = CreateRope( -7,-2.0,-7)
CreateBallJoint( cylT, floor, -7, -0.5 , -7)
DIM downNode2 AS DWORD
downNode2 = CreateRope( -7,-2.0,7)
CreateBallJoint(cylT, floor, -7, -0.5 , 7)
DIM downNode3 AS DWORD
downNode3 = CreateRope( 7,-2.0,0)
CreateBallJoint(cylT, floor, 7, -0.5 , 0)
'-----------------------------------------
' create plateforme
DIM cube AS EntityNode
cube = CreateEntitynode(cubemesh, 0, 0, 0, BYVAL %NULL)
PositionNode(cube, 0,-14,0)
LoadTextureNode(cube, "media/metal13.jpg", 0, 0)
ScaleNode(cube, 20,1,20)
' create body
CreateBody(cube, %BOX_PRIMITIVE, %True, 1.0, 0, 0, 0)
' create 3 link for the plateform
CreateBallJoint(cube, downNode1, -7, -13.5 , -7)
CreateBallJoint(cube, downNode2, -7, -13.5 , 7)
DIM joint AS NJoint
joint = CreateBallJoint(cube, downNode3, 7, -13.5 , 0)
' juste for one link.
UserCallbackBallJoint(joint, BYVAL CODEPTR(JointCallBack()))
'-----------------------------------------
' create first camera
DIM cam AS GLOBAL CameraNode
cam = CreateCameraFPS(70,0.1, 1.0, BYVAL %NULL, 0, %False, %False, BYVAL %NULL)
PositionNode(cam, 0,-5,-30)
RotateNode(cam, -10,0,0)
'-----------------------------------
' load font png
LoadFont("media/courriernew.png", %FONT_TYPE.EGDF_DEFAULT)
DIM pbfont AS IGUIFont
pbfont = GetFont()
DIM camPos AS GLOBAL iVECTOR3
DIM camDir AS GLOBAL iVECTOR3
' ---------------------------------------
' main loop
' ---------------------------------------
WHILE Quit = 0
'set a timer, a bit slower for the physics engine.
'_TimerUpdatePhysic(100.0)
' shoot with cube
IF GetKeyUp(%KEY_CODE.KEY_KEY_O) THEN
NodePosition(cam, camPos.x)
NodeDirection(cam, camDir.x)
' create mesh to shoot
'dim cube as EntityNode
cube = CreateEntitynode(cubemesh, 0, 0, 0, BYVAL %NULL)
ScaleNode(cube, 2,2,2)
LoadTextureNode(cube, "media/wcrate.bmp", 0, 0)
PositionNode(cube, camPos.x, camPos.y, camPos.z)
RotateNode(cube, RND(0, 180), RND(0, 180), RND(0, 180))
CreateBody(cube, %BOX_PRIMITIVE, %True, 10.0, 0, 0, 0)
VelocityBody(cube, camDir.x * 20, camDir.y *20, camDir.z * 20)
END IF
' shoot with cube
IF GetKeyUp(%KEY_CODE.KEY_KEY_P) THEN
NodePosition(cam, camPos.x)
NodeDirection(cam, camDir.x)
' create mesh to shoot
'dim cube as EntityNode
cube = CreateEntitynode(cubemesh, 0, 0, 0, BYVAL %NULL)
ScaleNode(cube, 2,2,2)
LoadTextureNode(cube, "media/wcrate.bmp", 0, 0)
PositionNode(cube, camPos.x,camPos.y,camPos.z)
RotateNode(cube, RND(0, 180), RND(0, 180), RND(0, 180))
' create body
CreateBody(cube, %BOX_PRIMITIVE, %True, 1.0, 0, 0, 0)
VelocityBody(cube, camDir.x*20, camDir.y*20, camDir.z*20)
END IF
' if Escape Key, exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit = 1
END IF
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
NX3_DrawText(pbfont, "Use P Key for shoot light Cube", 10,10,0,0, &h0ff9999ff)
NX3_DrawText(pbfont, "Use O Key for shoot heavy Cube", 10,25,0,0, &h0ff9999ff)
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
'--------------------------------------------------------------------
' create a rope with 4 Ball Joint
FUNCTION CreateRope (BYVAL posx AS SINGLE, BYVAL posy AS SINGLE, BYVAL posz AS SINGLE) AS LONG
LOCAL i AS LONG
DIM cylindermesh AS Mesh
cylindermesh = CreateCylinderMesh(0.3, 3.0, &h0ffffffff, 8, %True, 0)
' create first joint
DIM cyl1 AS EntityNode
cyl1 = CreateEntityNode(cylindermesh, 0, 0, 0, BYVAL %NULL)
PositionNode(cyl1, posx, posy, posz)
LoadTextureNode(cyl1, "media/water.jpg", 0, 0)
' create body
CreateBody(cyl1, %CAPSULE_PRIMITIVE, %True, 1.0, 0, 0, 0)
cylT= cyl1
' link 3 other joint
FOR i = 0 TO 2
DIM cyl2 AS EntityNode
cyl2 = CreateEntityNode(cylindermesh, 0, 0, 0, BYVAL %NULL)
PositionNode(cyl2, posx, posy - (i+1)*3.2, posz)
LoadTextureNode(cyl2, "media/water.jpg", 0, 0)
' create body
CreateBody(cyl2, %CAPSULE_PRIMITIVE, %True, 1.0, 0, 0, 0)
CreateBallJoint(cyl2, cylT, posx, posy - (i+1)*2.6, posz)
cylT = cyl2
NEXT
cylT = cyl1
FUNCTION = cyl2
END FUNCTION
';------------------------------------------------------------------------------------------------
'; CallBack Joint. This function call when either of the two bodies linked by the joint is active.
SUB JointCallBack CDECL(BYVAL joint AS NJoint, BYVAL desc AS NewtonHingeSliderUpdateDesc)
DIM force(2) AS LOCAL SINGLE
BallJointForce(joint, force(0))
IF force(1) > 650 THEN
' debug vertical joint force
'Debug force(1)
FreeJoint(joint)
END IF
END SUB
New Include
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 080 : first test with physic engine
' 23/05/09 19:16 TMyke
'
' ------------------------------------------------------------
#INCLUDE "n3xtD.bi"
FUNCTION PBMAIN
' Globales
DIM app AS DWORD PTR
DIM Quit AS LONG
DIM i 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 light and set position
AmbientLight(&Hffffff)
' -----------------------------------------
' create and init some physicmaterial
' -----------------------------------------
DIM pbmat(1 TO 3) AS LONG
pbmat(1) = CreatePhysicMaterial()
pbmat(2) = CreatePhysicMaterial()
DIM pair1 AS DWORD PTR
pair1 = CreatePhysicMaterialPair( pbmat(1), pbmat(1), 0.1, 0.3, 0.25, 0)
DIM pair2 AS DWORD PTR
pair2 = CreatePhysicMaterialPair( pbmat(1), pbmat(2), 0.3, 1.1, 0.82, 0)
DIM pair3 AS DWORD PTR
pair3 = CreatePhysicMaterialPair( pbmat(2), pbmat(2), 0.6, 1.0, 0.82, 0)
'===========================================================
' set specific parameters for Bouyancy setting
BouyancyParameter(5.0, 0, -9.8, 5)
'-----------------------------------------
DIM cubemesh AS Mesh
cubemesh = CreateCubeMesh(1.0)
DIM cylindermesh AS Mesh
cylindermesh = CreateCylinderMesh(0.5, 2, &h0ffffffff, 8, %True, 0)
'-----------------------------------------
' create water floor
'----------------------------------------
DIM floor1 AS EntityNode
floor1 = CreateEntityNode(cubemesh, 0, 0, 0, BYVAL %NULL)
PositionNode(floor1, 0,-10,0)
LoadTextureNode(floor1, "media/water1.jpg", 0, 0)
ScaleNode(floor1, 20, 1, 20)
' create body, no dynamique
CreateBody(floor1, %BOX_PRIMITIVE, %False, 0, 0, 0, 0)
GroupPhysicMaterialBody(floor1, pbmat(1))
BouyancyMaterial(floor1, pair1)
' set translucide material
DIM material AS NMaterial
material = NodeMaterial(floor1, 0)
ColorMaterial(material, 0)
TypeMaterial(material, %EMT_ONETEXTURE_BLEND )
TypeBlendMaterial(material, 6, 7, %EMFN_MODULATE_1X, %EAS_TEXTURE OR %EAS_VERTEX_COLOR)
DiffuseColorNode(floor1, &H088ffffff)
'-----------------------------------------
' create solid floor
DIM floor2 AS EntityNode
floor2 = CreateEntityNode(cubemesh, 0, 0, 0, BYVAL %NULL)
PositionNode(floor2, 0, -20, -20)
LoadTextureNode(floor2, "media/grille1.bmp", 0, 0)
' Attention. Even if we wish to define a shape identical to the second base,
' it is necessary to provide data sizes slightly different, because otherwise
' the physics engine treats the two as the same platform, which creates a bug
' in the handling of material in our case. _ScaleNode( *floor2, 20.1,1,20.1)
ScaleNode( floor2, 21,1,21)
' create body, no dynamique
CreateBody(floor2, %BOX_PRIMITIVE, %False, 0, 0, 0, 0)
GroupPhysicMaterialBody(floor2, pbmat(2))
'-----------------------------------------
' create a cube
DIM cube AS EntityNode
cube = CreateEntityNode(cubemesh, 0, 0, 0, BYVAL %NULL)
PositionNode(cube, 0,-5,-25)
LoadTextureNode(cube, "media/body.bmp", 0, 0)
' create body, dynamique
CreateBody(cube, %BOX_PRIMITIVE, %True, 1.0, 0, 0, 0)
GroupPhysicMaterialBody(cube, pbmat(3))
'-----------------------------------------
' create cubes
FOR i = 0 TO 10
cube = CreateEntityNode(cubemesh, 0, 0, 0, BYVAL %NULL)
PositionNode(cube, -9+RND(0, 18),-RND(0, 8),-9+RND(0, 18))
LoadTextureNode(cube, "media/wcrate.bmp", 0, 0)
' create body, dynamique
CreateBody(cube, %BOX_PRIMITIVE, %True, 2.0, 0, 0, 0)
GroupPhysicMaterialBody(cube, pbmat(1))
NEXT
'-----------------------------------------
' create barrel
FOR i = 0 TO 10
DIM barrel AS EntityNode
barrel = CreateEntityNode(cylindermesh, 0, 0, 0, BYVAL %NULL)
PositionNode(barrel, -9+RND(0, 18),-RND(0, 8),-9+RND(0, 18))
LoadTextureNode(barrel, "media/wall0.jpg", 0, 0)
' create body, dynamique
CreateBody(barrel, %CYLINDER_PRIMITIVE, %True, 4.0, 0, 0, 0)
GroupPhysicMaterialBody(barrel, pbmat(1))
NEXT
'-----------------------------------------
' create first camera
DIM cam AS GLOBAL CameraNode
cam = CreateCameraFPS(70, 0.1, 1.0, BYVAL %NULL, 0, %False, %False, BYVAL %NULL)
PositionNode(cam, 20,-0,-20)
RotateNode(cam, 25,-60,0)
' ---------------------------------------
' main loop
' ---------------------------------------
WHILE Quit = 0
' if Escape Key, exit
IF GetKeyDown(%KEY_CODE.KEY_ESCAPE) THEN
Quit=1
END IF
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
' ------------------------------------------------------------
' n3xt-D exemples
'
' Sample 006 as Load a simple 3D Object And set multiple mesh
' Historique as
' 29/03/09 19 as 16 TMyke
'
' ------------------------------------------------------------
#IF %DEF(%PB_CC32)
#CONSOLE OFF
#ENDIF
' Includes libraries
#INCLUDE "windows.inc"
#INCLUDE "N3xtD.bi"
GLOBAL Close_n3xtd AS DWORD
GLOBAL Callback AS DWORD
' Dimes
FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInst AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG
DIM app AS DWORD
DIM Quit AS LONG
DIM hWnd AS DWORD
'----------------------------------------------------------
' open n3xt-D screen
app = CreateGraphics3D(800,600, 32, 0, %TRUE, %DEVICE_TYPES.EDT_DIRECT3D9, %TRUE)
IF app=%NULL THEN
END
END IF
' Load an 3D Object
DIM obj AS Mesh
obj = LoadMesh("media/earth.x", %HARDMAPPING.EHM_STATIC)
' Create several mesh
DIM i AS INTEGER
DIM sphere AS EntityNode
FOR i = 0 TO 3
'; Create a mesh with one of the 3D Object loaded
sphere = CreateEntityNode(obj, 0, 0, 0, %NULL)
' set position
PositionNode(sphere, 3*i,0,0)
NEXT
' create a camera
DIM cam AS CameraNode
cam = CreateCamera(%NULL)
PositionNode(cam, 6,0,-10)
hwnd = GetCallingHwnd()
Callback = SetWindowLong(hWnd, %GWL_WNDPROC, CODEPTR(PBCallback()))
' ---------------------------------------
' Main loop
' ---------------------------------------
WHILE Quit=0
' If Escape Key, Exit
IF (GetKeyDown(%KEY_CODE.KEY_ESCAPE) OR Close_n3xtd) THEN
Quit=1
END IF
IF GetMouseEvent(%MOUSE_EVENT.MOUSE_BUTTON_LEFT) THEN
END IF
IF getKeyDown(%KEY_CODE.KEY_MENU) THEN
END IF
' just turn our sphere
TurnNode(sphere, 0,0.5,0, 0)
' ---------------
' Render
' ---------------
BeginScene(0, 0, 0, 255, 1, 1)
DrawScene()
EndScene()
WEND
' end
FreeEngine()
END FUNCTION
FUNCTION EnumProc(BYVAL hWnd AS LONG, BYVAL lParam AS LONG) AS LONG
LOCAL ptrlParam AS LONG PTR
ptrlParam = lParam
POKE LONG, ptrlParam, hWnd
FUNCTION = 0
END FUNCTION
FUNCTION GetCallingHwnd() AS LONG
LOCAL hWnd AS LONG
LOCAL ptrhWnd AS LONG PTR
ptrhWnd = VARPTR(hWnd)
EnumThreadWindows(GetCurrentThreadId(), CODEPTR(EnumProc), ptrhWnd)
FUNCTION = hWnd
END FUNCTION
FUNCTION pbCallback(BYVAL pbWindow AS DWORD , BYVAL Message AS DWORD , BYVAL wParam AS DWORD, BYVAL lParam AS DWORD) AS DWORD
LOCAL Result AS DWORD
Result = CallWindowProc(CallBack, pbWindow, Message, wParam, lParam)
SELECT CASE Message
CASE %WM_CLOSE
Close_n3xtd = %True
END SELECT
FUNCTION = Result
END FUNCTION
New Include
Hi,
Link to N3xtD doesn't go to N3xTD. Nice header files no engine :o
Later...
G.C.
Hello,
I found what!
Here can you download the DLL!
http://users.freebasic-portal.de/vanya/N3xtD/
greetings Peter
Hello,
Hello,
Here the project with all the examples.
regards Peter
And here are all the media files to
regards Peter
Hi Peter,
Thanks for the links. Downloading now.
G.C.
What has happened with N3xtD? Yet another abandoned project? All the official links are dead.
[Translation/Theo]
Hallo Jose, it looks like N3xTD is not continued. I have therefore published all Sources i have here in the forum.
As i see it, "Irrlicht 3D" is similiar to N3xTD. When i am ready with my actual project and i get time I'll take a closer look.
------------------
Hallo Jose,
N3xTd scheint Tod zu sein deswegen habe ich auch alles veröffentlicht was ich von N3xTd habe. Wen ich mit Unicode Wide Files fertig bin werde ich mir mal irrlicht-1.7.3 anschauen und dafür vielleicht Inlude schreiben! Irrlicht ist fast wie N3xTd
Grüße Peter