Code : Tout sélectionner
InitEngine3D()
InitKeyboard()
InitSprite()
window = OpenWindow(#PB_Any,0,0,1024,768,"")
OpenWindowedScreen(WindowID(window),0,0,1024,768)
;
; On créer une texture
;
texture = CreateTexture(#PB_Any,512,512)
StartDrawing(TextureOutput(texture))
Box(0,0,512,512,$FFFFFF)
Ellipse(256,256,25,50,0)
Ellipse(256,256,12,24,$0000FF)
StopDrawing()
;
; Un material basic pour la texture
;
material = CreateMaterial(#PB_Any,TextureID(texture))
;
; La lumière , on change la couleur ambiente ( très important )
; On ajoute une lumiere de base omnidirectionel
;
AmbientColor($101010)
CreateLight(#PB_Any,$FFFFFF,0,-30,-50)
;
; une camera basic
;
camera = CreateCamera(#PB_Any,0,0,100,100)
MoveCamera(camera,0,10,-20)
CameraLookAt(camera,0,0,0)
;
; un mesh sphere qui servira de base pour nos yeux
;
sphere_mesh = CreateSphere(#PB_Any,2,64,64)
TransformMesh(sphere_mesh,0,0,0,1,1,1,0,0,0)
left_eye = CreateEntity(#PB_Any,MeshID(sphere_mesh),MaterialID(material),-2,0,0,$0010)
right_eye = CreateEntity(#PB_Any,MeshID(sphere_mesh),MaterialID(material), 2,0,0,$0010)
;
; une texture "invisible"
;
texture = CreateTexture(#PB_Any,1,1)
material = CreateMaterial(#PB_Any,TextureID(texture))
MaterialBlendingMode(material, #PB_Material_AlphaBlend)
;
; un plan orienté face à la camera avec le material invisible
; & un pick mask différent
;
plane_mesh = CreatePlane(#PB_Any,100,100,1,1,1,1)
TransformMesh(plane_mesh,0,0,-15,1,1,1,-CameraPitch(camera),0,0)
UpdateMeshBoundingBox(plane_mesh)
plane_entity = CreateEntity(#PB_Any,MeshID(plane_mesh),MaterialID(material),0,0,0,$0001)
While #True
event = WindowEvent()
If event = #PB_Event_CloseWindow
Break
EndIf
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
Break
EndIf
;
; On pick sur notre plan invisible & on récupère les coordonées
; du point de picking & on oriente nos yeux , plus le plan est près
; plus les yeux "louche" quand la souris est entre les 2.
;
If MouseRayCast(camera,WindowMouseX(window),WindowMouseY(window),$0001)
lookAtX.f = PickX()
lookAtY.f = PickY()
lookAtZ.f = PickZ()
EntityLookAt(left_eye, lookAtX, lookAtY, lookAtZ)
EntityLookAt(right_eye, lookAtX, lookAtY, lookAtZ)
EndIf
ClearScreen(0)
RenderWorld()
FlipBuffers()
Delay(1)
Wend