MeshVertexPosition(x, y, z)
MeshVertexColor(RGB(255,0,0))
instead of Plot(x,y, RGB(255,0,0))
this is demonstrated in the official example MeshManual2.pb in Examples\3D folder. it can be used to plot galaxies in 3D and the stars clusters inside it .
i will use this sort of plotting to plot the Biomorph 2D in 3D (a fractal creature) so we can rotate it and looking to it from different angles, the algorithm used from the http://www.madteddy.com/biomorph.htm , the site may be closed so look at its copy at WebArchive... to see more variations.
for the keys usage look the title bar, to manual or automatic rotation, scaling, up, down, near, far movements.
i have used also the ogre mesh viewer posted recently...
save the program to Examples\3D folder
More ideas are welcome
Code: Select all
Enumeration
#MESH
#TEX_plane
#MAT
#MAT_plane
#plane
#LIGHT
#CAMERA_ONE
#BUTTON
#mainwin
EndEnumeration
;constants for the biomorph function
#constreal = 0.5
#constimag = 0
#screenheight = 500
#screenwidth = 500
Quit.b = #False
rot.l=1 :stopFlag = 1
xs.f = 0.3:ys.f = 0.3:zs.f = 0.3
x.f: y.f :z.f: x0.f: y0.f=1 :z0.f
rotx.f:roty.f=1:rotz.f :rotx0.f: roty0.f: rotz0.f
up.f = 2.2: depth.f=0
ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "PgUp PgD scale mesh..Arrows for rotation, space: stop/rotate, QA Up/Down, WS far/near", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#BUTTON, 0, DesktopHeight(0)-60, 60, 30, "rotate/stop")
;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-70, 0, 0, 0)
;WorldShadows(#PB_Shadow_Additive)
InitKeyboard()
SetFrameRate(60)
Add3DArchive("Data/", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Models", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Textures\", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
CreateMaterial(#MAT_plane, LoadTexture(#TEX_plane, "snow_1024.jpg"))
CreatePlane(#plane, 10, 10, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(#MAT_plane))
CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))
CreateCamera(#CAMERA_ONE, 0, 0, 400, 400)
MoveCamera(#CAMERA_ONE, 0, 4, 9)
CameraLookAt(#CAMERA_ONE, 0, 2, 0)
RotateCamera(#CAMERA_ONE, -15, 0, 0)
EndIf
SetActiveGadget(#BUTTON)
SkyDome("clouds.jpg", 100) ;for blue color background
;- Mesh Stars
CreateMaterial(0, LoadTexture(0, "White.jpg"))
DisableMaterialLighting(0, #True)
CreateMesh(1, #PB_Mesh_PointList, #False)
SetMeshMaterial(1, MaterialID(0))
Global Stars = CreateNode(#PB_Any)
AttachNodeObject(Stars, MeshID(1))
Procedure Biomorph()
aspectratio.f = #screenwidth / #screenheight
ymax.f = 10
ymin.f = -ymax
xmax.f = ymax * aspectratio
xmin.f = -xmax
ilimit.l = #screenheight - 1
jlimit.l = #screenwidth - 1
x.f: y.f: x0.f: y0.f: xx.f: yy.f
xmax.f = ymax * aspectratio
For i = 0 To ilimit
For j = 0 To jlimit
x0 = xmin + (xmax - xmin) * j / jlimit
y0 = -ymin - (ymax - ymin) * i / ilimit
x = x0
y = y0
For n = 1 To 100
xx = x * (x * x - 3 * y * y) + #constreal: ; THIS Line And the Next give the cube
yy = y * (3 * x * x - y * y) + #constimag: ; of the Number, plus a constant
x = xx
y = yy
If Abs(x) > 10 Or Abs(y) > 10 Or x * x + y + y > Pow(10,2)
n = 100
EndIf
Next n
If Abs(x) < 10 Or Abs(y) < 10
;Plot(j,i, RGB(0,0,0))
MeshVertexPosition(x0, y0, 0)
MeshVertexColor(RGB(0,0,0))
Else
;Plot(j,i, RGB(255, 255, 255 ))
MeshVertexPosition(x0, y0, 0)
MeshVertexColor(RGB(255,255,0))
EndIf
Next j
Next i
FinishMesh(#False)
EndProcedure
Biomorph() ; calling the biomorph generator function
;Main loop
Repeat
Event = WindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case #BUTTON
If rot = 0
rot = 1
rotx= rotx0:roty=roty0:rotz=rotz0 ; restore rotation status
stopFlag = 1
Else
rot = 0
rotx0= rotx:roty0=roty:rotz0=rotz ;back up rotation status
rotx=0:roty=0:rotz=0
stopFlag = 0
EndIf
EndSelect
EndIf
If stopFlag=1
x + rotx
y + roty
z + rotz
EndIf
RotateNode(Stars, x, y, z)
RenderWorld()
FlipBuffers()
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up) ; rotate left
rotx=1:roty=0:rotz=0
rotx0 = rotx: roty0 = roty :rotz0 = rotz
x + rotx
y + roty
z + rotz
stopFlag=0
rot = 0
ElseIf KeyboardPushed(#PB_Key_Down) ; rotate right
rotx=-1:roty=0:rotz=0
rotx0 = rotx: roty0 = roty :rotz0 = rotz
x + rotx
y + roty
z + rotz
stopFlag=0
rot = 0
ElseIf KeyboardPushed(#PB_Key_Right) ; rotate up
rotx=0:roty=1:rotz=0
rotx0 = rotx: roty0 = roty :rotz0 = rotz
x + rotx
y + roty
z + rotz
stopFlag=0
rot = 0
ElseIf KeyboardPushed(#PB_Key_Left) ; rotate down
rotx=0:roty=-1:rotz=0
rotx0 = rotx: roty0 = roty :rotz0 = rotz
x + rotx
y + roty
z + rotz
stopFlag=0
rot = 0
EndIf
If KeyboardPushed(#PB_Key_PageUp) ; scale up model
xs.f = 1.1:ys.f = 1.1:zs.f = 1.1
ScaleNode(Stars,xs,ys,zs)
ElseIf KeyboardPushed(#PB_Key_PageDown) ; scale down model
xs = 0.9:ys = 0.9:zs= 0.9
ScaleNode(Stars,xs,ys,zs)
EndIf
If KeyboardPushed(#PB_Key_Q) ; up move
up + 0.1
MoveNode(Stars,0,up,depth,#PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_A) ; down move
up - 0.1
MoveNode(Stars,0,up,depth,#PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_W) ; forward move
depth - 0.1
MoveNode(Stars,0,up,depth,#PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_S) ; inward move
depth + 0.1
MoveNode(Stars,0,up,depth,#PB_Absolute)
EndIf
If KeyboardPushed(#PB_Key_Escape)
Quit = #True
EndIf
Until Quit = #True Or Event = #PB_Event_CloseWindow
MeshVertexPosition(x0, y0, 0)
MeshVertexColor(RGB(255,255,0))
so comment it to see the following figure: