#INCLUDE "%APP_SOURCEPATH%\xors3d.inc"
#INCLUDE Once "%APP_SOURCEPATH%\key.inc" 'to disable the popup intoductory window
Global light, mesh, surf, cam, i, v1, v2, v3, brush, tri1, tot As Long
Global x,y,z,r,g,b As Single
xGraphics3D(800, 600, 32, 0, 1)
xAppTitle("Example Xors3D: adding more vertices and triangles to the mesh in real time")
light = xCreateLight(1)
mesh = xCreateMesh ()
xMeshPrimitiveType (mesh, 4)
surf = xCreateSurface(mesh, brush)
xSurfacePrimitiveType (surf, 4)
For i=0 To 10
x = Rnd(0,200)-100:y = Rnd(0,200)-100:z = Rnd(0,200)-100
If (x^2 + y^2 + z^2) <= 4900 Then
tot+1
r=Rnd(0,255):g=Rnd(0,255):b=Rnd(0,255)
v1 = xAddVertex(surf, x, y, z, 0, 1)
xVertexColor(surf, v1, r, g, b, 1)
v2 = xAddVertex(surf, x+Rnd(-1,1)*10, y+Rnd(-1,1)*10, z+Rnd(-1,1)*10, 0, 1)
'xVertexColor(surf, v2, r, g, b, 1)
v3 = xAddVertex(surf, x-3, y+3, z-2, 0, 1)
'xVertexColor(surf, v3, r, g, b, 1)
tri1 = xAddTriangle(surf, v1, v2, v3)
'xFlipMesh(mesh)
End If
Next
xUpdateNormals(mesh)
'creating the camera
cam = xCreateCamera()
'xMoveEntity(cam, 0, 100, -500)
xPositionEntity(mesh, 0,0,300)
xPositionEntity(cam, 0, 0, 0)
xFlipMesh(mesh)
xEntityFX(mesh, 18)
xUpdateNormals(mesh)
While xKeyHit(%xKEY_ESCAPE) = 0
x = Rnd(0,200)-100:y = Rnd(0,200)-100:z = Rnd(0,200)-100
If (x^2 + y^2 + z^2) <= 4900 Then
tot+1
r=Rnd(0,255):g=Rnd(0,255):b=Rnd(0,255)
v1 = xAddVertex(surf, x, y, z, 0, 1)
xVertexColor(surf, v1, r, g, b, 1)
v2 = xAddVertex(surf, x+Rnd(-1,1)*10, y+Rnd(-1,1)*10, z+Rnd(-1,1)*10, 0, 1)
xVertexColor(surf, v2, r, g, b, 1)
v3 = xAddVertex(surf, x+Rnd(-1,1)*10, y+Rnd(-1,1)*10, z+Rnd(-1,1)*10, 0, 1)
xVertexColor(surf, v3, r, g, b, 1)
tri1 = xAddTriangle(surf, v1, v2, v3)
End If
xTurnEntity(mesh, 0,0.5, 0)
xUpdateNormals(mesh)
'xUpdateWorld_()
xRenderWorld()
xText(10, 10, "Hello 3D World!")
xText(10, 30, "FPS: " + Str$(xGetFPS()))
xText(10, 50, "Tri: " + Str$(tot))
xFlip()
If xWinMessage("WM_CLOSE") Then Exit While
Wend
xReleaseGraphics()
Stop
Bookmarks