the second code is for me for a future reference to enable myself to visualize the sequence of vertices when we draw something using a plane ,it is a plane only 4X4 and it has 25 vertices just press v to add 0.3 to the specified vertex ,look line 72 to 75
at last is a classic example: just deforming a sphere created by CreateSphere.
but in the first example why we don't use CreatePlane instead of a plane generator code i am still studying this since from the first impression it does not animate but can be deformed at first and then can't be deformed again.
use as a meterial this script save it as cubemap.material neccessary for the mirror working
Code: Select all
material CubeMapMaterial
{
technique
{
pass
{
texture_unit
{
cubic_texture CubeMapTexture combinedUVW
tex_address_mode clamp
env_map cubic_reflection
}
}
}
}
snake.png

silver.jpg



Code: Select all
Enumeration
#mainwin = 10
#mat
#sphere
#sphereMat
#mirror
EndEnumeration
Structure Vector3
x.f
y.f
z.f
EndStructure
Define.Vector3 Normal, v1, v2, v3
#CameraSpeed = 1
#NbX=30
#NbZ=30
Define.f KeyX, KeyY, MouseX, MouseY
Global Dim MeshData.PB_MeshVertex(0)
Global Dim MeshDataInd.PB_MeshFace(0)
Declare UpdateMatrix()
Declare CreateMatrix()
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
ExamineDesktops()
OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "press W for wire frame, press S for Solid ,____ zoom by keyboard ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-60, 0, 0, 0)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/skybox.zip", #PB_3DArchive_Zip)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Parse3DScripts()
;-Material
;GetScriptMaterial(1, "Scene/GroundBlend")
CreateMaterial(1, LoadTexture(0, "snake.png"))
DisableMaterialLighting(1, 1)
MaterialCullingMode(1, 1)
;MaterialShadingMode(1, #PB_Material_Wireframe)
SetMaterialColor(1, #PB_Material_SelfIlluminationColor, RGB(255, 255, 255))
;-Mesh
CreateMatrix()
;-Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0,0,70,120, #PB_Absolute)
CameraLookAt(0, 0, 0, 0)
CameraBackColor(0, RGB(90, 0, 0))
;-Light
CreateLight(0, RGB(255, 255, 255), 5, 15, 5)
AmbientColor(RGB(255, 255, 255))
CameraBackColor(0, RGB(0,100,100))
CreateSphere(#sphere, 4)
GetScriptMaterial(#sphereMat, "Color/Red")
DisableMaterialLighting(#spheremat, 0)
CreateEntity(#sphere, MeshID(#sphere), MaterialID(#spheremat))
MyCubeMap = CreateCubeMapTexture(#PB_Any, 256, 256, "CubeMapTexture")
GetScriptMaterial(2,"CubeMapMaterial")
SetMaterialColor(2, #PB_Material_SelfIlluminationColor, $FFFFFF)
Mirror = CreateSphere(#PB_Any, 20)
Entity = CreateEntity(#PB_Any,MeshID(Mirror),MaterialID(2))
ScaleEntity(Entity,1,2,0.2)
RotateEntity(Entity, 0,-210,0)
EntityCubeMapTexture(MyCubeMap, Entity)
MoveEntity(Entity, 70,20,-50)
CreateMaterial(4, LoadTexture(4, "silver.jpg"))
AddMaterialLayer(2, TextureID(4) , #PB_Material_Modulate)
Repeat
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_W)
MaterialShadingMode(1, #PB_Material_Wireframe)
ElseIf KeyboardReleased(#PB_Key_S)
MaterialShadingMode(1, #PB_Material_Solid)
ElseIf KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed
;Debug(MeshVertexCount(0, 0))
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed
Else
KeyY = 0
EndIf
EndIf
If ExamineMouse()
MouseX = -(MouseDeltaX()/10)
MouseY = -(MouseDeltaY()/10)
EndIf
MoveCamera (0, KeyX, 0, KeyY)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
; Waves
UpdateMatrix()
AngleVague = AngleVague+WaveFrequency
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
Procedure DrawMatrix()
Protected.l a, b, c, Nb
Protected.w P1, P2, P3, P4
For b=0 To #Nbz
For a=0 To #NbX
dtime.f=ElapsedMilliseconds()/600
MeshVertexPosition(a - #NbX/2, y, b - #Nbz/2)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(a/#NbX, b/#Nbz)
Next a
Next b
Nb=#NbX+1
For b=0 To #NbZ-1
For a=0 To #NbX-1
P1=a+(b*Nb)
P2=P1+1
P3=a+(b+1)*Nb
P4=P3+1
MeshFace(P3, P2, P1)
MeshFace(P2, P3, P4)
Next
Next
EndProcedure
Procedure CreateMatrix()
CreateMesh(0, #PB_Mesh_TriangleList, #True)
DrawMatrix()
FinishMesh(#True)
SetMeshMaterial(0, MaterialID(1))
CreateNode(0)
CreateEntity(0, MeshID(0), #PB_Material_None)
ScaleEntity(0, 3, 3, 3)
GetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0, 0)-1)
GetMeshData(0,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(0, 0)-1)
EndProcedure
Procedure UpdateMatrix()
Protected a, b, c, i, j
Protected N.Vector3, V1.Vector3, V2.Vector3, V3.Vector3
Protected.f magSq, oneOverMag
dtime.f=ElapsedMilliseconds()/600 ; reduce 600 to get speedier animation
For b=0 To #Nbz
For a=0 To #NbX
xa.f=MeshData(c)\x
zb.f=MeshData(c)\z
;yy.f= MeshData(c)\y
;new y vertex coordinates
MeshData(c)\y=Cos(dtime + (Sqr(Pow(0.5*xa,2)+Pow(0.5*zb,2))))*2
c + 1 ; vertex number
;xa.f=MeshData(481)\x
;zb.f=MeshData(481)\z
;yy.f = Cos(dtime + (Sqr(Pow(0.5*xa,2)+Pow(0.5*zb,2))))*2
yy.f=Cos(dtime)*8
MoveEntity(#sphere, 0 , yy, 0 ,#PB_Absolute)
Next a
Next b
SetMeshData(0,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Normal, 0, MeshVertexCount(0, 0)-1)
EndProcedure

Code: Select all
Enumeration
#mainwin = 10
EndEnumeration
Structure Vector3
x.f
y.f
z.f
EndStructure
Define.Vector3 Normal, v1, v2, v3
#CameraSpeed = 3
#NbX=4
#NbZ=4
Define.f KeyX, KeyY, MouseX, MouseY
Global Dim MeshData.PB_MeshVertex(0)
Global Dim MeshDataInd.PB_MeshFace(0)
Global ind.l
Declare UpdateMatrix()
Declare CreateMatrix()
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
ExamineDesktops()
OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "press V to displace a vertex , press W for wire frame, press S for Solid ,____ zoom by keyboard ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-60, 0, 0, 0)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/skybox.zip", #PB_3DArchive_Zip)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Parse3DScripts()
;-Material
;GetScriptMaterial(1, "Scene/GroundBlend")
CreateMaterial(1, LoadTexture(0, "grass.jpg"))
DisableMaterialLighting(1, 1)
MaterialCullingMode(1, 1)
MaterialShadingMode(1, #PB_Material_Wireframe)
SetMaterialColor(1, #PB_Material_SelfIlluminationColor, RGB(255, 255, 255))
;-Mesh
CreateMatrix()
;-Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0,0,10,10, #PB_Absolute)
CameraLookAt(0, 0, 0, 0)
CameraBackColor(0, RGB(255,244,255))
;-Light
CreateLight(0, RGB(255, 255, 255), 5, 15, 5)
AmbientColor(RGB(255, 255, 255))
Repeat
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_W)
MaterialShadingMode(1, #PB_Material_Wireframe)
ElseIf KeyboardReleased(#PB_Key_S)
MaterialShadingMode(1, #PB_Material_Solid)
ElseIf KeyboardReleased(#PB_Key_V)
MeshData(ind)\y = 0.3:ind+1
If ind=MeshVertexCount(0, 0):ind=0:EndIf
SetMeshData(0,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Normal, 0, MeshVertexCount(0, 0)-1)
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed
Else
KeyY = 0
EndIf
EndIf
If ExamineMouse()
MouseX = -(MouseDeltaX()/10)
MouseY = -(MouseDeltaY()/10)
EndIf
MoveCamera (0, KeyX, 0, KeyY)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
Procedure DrawMatrix()
Protected.l a, b, c, Nb
Protected.w P1, P2, P3, P4
For b=0 To #Nbz
For a=0 To #NbX
dtime.f=ElapsedMilliseconds()/600
MeshVertexPosition(a - #NbX/2, y, b - #Nbz/2)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(a/#NbX, b/#Nbz)
Next a
Next b
Nb=#NbX+1
For b=0 To #NbZ-1
For a=0 To #NbX-1
P1=a+(b*Nb)
P2=P1+1
P3=a+(b+1)*Nb
P4=P3+1
MeshFace(P3, P2, P1)
MeshFace(P2, P3, P4)
Next
Next
EndProcedure
Procedure CreateMatrix()
CreateMesh(0, #PB_Mesh_TriangleList, #True)
DrawMatrix()
FinishMesh(#True)
SetMeshMaterial(0, MaterialID(1))
CreateNode(0)
CreateEntity(0, MeshID(0), #PB_Material_None)
ScaleEntity(0, 3, 3, 3)
GetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0, 0)-1)
GetMeshData(0,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(0, 0)-1)
EndProcedure
Code: Select all
Enumeration
#MESH
#LIGHT
#CAMERA
#mainwin
#tex
#sp
EndEnumeration
Structure Vector3
x.f
y.f
z.f
EndStructure
Define.Vector3 v1, v2, v3
Global x.f = 0
Global y.f = 10
Global z.f = -30
Global Dim MeshData.PB_MeshVertex(0)
Global amplitude.f = 0.01
Global frequency.f = 3.0
;Global offset.f
ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "press W for wireframw, press S for Solid ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Define.f KeyX, KeyY
Declare Deform()
If InitEngine3D()
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Parse3DScripts()
InitSprite()
InitKeyboard()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-60, 0, 0, 0)
CreateMaterial(0, LoadTexture(0, "Geebee2.bmp"))
DisableMaterialLighting(0, 1)
SetMaterialColor(0, #PB_Material_DiffuseColor, RGB(255,255,255))
MaterialShadingMode(0, #PB_Material_Wireframe )
MaterialCullingMode(0, #PB_Material_NoCulling)
CreateSphere(#sp,4,64,64)
CreateEntity(#sp, MeshID(#sp), MaterialID(0))
;;wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 0, 8, #PB_Absolute)
CameraFOV(0, 70)
CameraBackColor(0, $330000)
CameraLookAt(0,0,0,0)
CreateLight(0, RGB(255,255,255), 5, 0, 10)
AmbientColor(RGB(90, 90, 90))
GetMeshData(#sp,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(#sp)-1)
Repeat
Event = WindowEvent()
Deform()
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_W)
MaterialShadingMode(0, #PB_Material_Wireframe)
ElseIf KeyboardReleased(#PB_Key_S)
MaterialShadingMode(0, #PB_Material_Solid)
EndIf
EndIf
rot.f+0.6
RotateEntity(#sp,0,rot,0)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
Procedure Deform()
;warping a sphere
dtime.f=ElapsedMilliseconds()/1000
offset.f
countvertices = MeshVertexCount(#sp)
For i=0 To countvertices-1
;--------------------------------
vx.f = MeshData(i)\x
vy.f = MeshData(i)\y
vz.f = MeshData(i)\z
;--------------------------------
offset = amplitude * Sin((dtime + vx)*frequency)
;vx + offset
vy + offset
vz + offset
MeshData(i)\y = vy
MeshData(i)\z = vz
Next
SetMeshData(#sp,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(#sp)-1)
EndProcedure