Code: Select all
is there a way to rotate the light
hello
all orge issues makes me frustrated , there is an example StaticGeometry.pb in the 3D folder examples wich show a moving sun and a moving shadow, i haven't studied it yet, i need to read some ogre tutorials first. but here a simpler example i have posted here
http://www.purebasic.fr/english/viewtop ... 37#p368537
download the fish mesh + skeleton and textures from
http://www.mediafire.com/?rn4qquww12d8wj1
in the example the position of light are static at -100,40,30 :
CreateLight(#LIGHT,RGB(255,255,255),-100,40,30)
to move it , i have stolen a formula from Michael library MP3D:
count.f + 0.03
LightLocate(#LIGHT, Sin(count+#PI/2) * 30, 20, Cos(count+#PI/2) * 30)
put the Data folder from the downloaded file in the same place as the following modified code, press stop button to watch a moving shadow around a static fish, change the y coordinate from 20 to 10 and the shadow will be more elongated.
you may add a moving sun , as in the StaticGeometry.pb official example.
i havn't tested
LightLookAt() yet.
Code: Select all
Enumeration
#MESH
#TEX
#TEX_plane
#MAT
#MAT_plane
#plane
#ENTITY_FISH
#LIGHT
#CAMERA_ONE
#BUTTON
#mainwin
EndEnumeration
Global Quit.b = #False
If OpenWindow(#mainwin, 0, 0, 500, 480, "press ESC to exit...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#BUTTON, 0, 405, 50, 30, "stop")
;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, 500, 400, 0, 0, 0)
WorldShadows(#PB_Shadow_Additive)
EnableWorldPhysics(#True)
EnableWorldCollisions(#True)
InitKeyboard()
SetFrameRate(60)
Add3DArchive("Data\", #PB_3DArchive_FileSystem)
CreateMaterial(#MAT_plane, LoadTexture(#TEX_plane, "mosaic.png"))
CreatePlane(#plane, 10, 10, 1, 1, 1, 1)
CreateEntity (#plane, MeshID(#plane), MaterialID(#MAT_plane))
LoadMesh(#MESH, "fish.mesh")
LoadTexture(#TEX, "steelhead.png")
CreateMaterial(#MAT, TextureID(#TEX))
CreateNode(#ENTITY_FISH)
CreateEntity(#ENTITY_FISH, MeshID(#MESH), MaterialID(#MAT))
ScaleEntity(#ENTITY_FISH,0.5,0.5,0.5)
AnimateEntity(#ENTITY_FISH, "swim")
AttachNodeObject(#ENTITY_FISH,EntityID(#ENTITY_FISH),#PB_Node_Entity)
MoveNode(#ENTITY_FISH,0,1.5,1)
CreateLight(#LIGHT,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))
CreateCamera(#CAMERA_ONE, 0, 0, 400, 400)
CameraLocate(#CAMERA_ONE, 0, 4, 9)
CameraLookAt(#CAMERA_ONE, 0, 2, 0)
RotateCamera(#CAMERA_ONE, -15, 0, 0)
EndIf
rot.l=1
;Main loop
Repeat
Event = WindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case #BUTTON
If rot = 0
rot = 1
SetGadgetText(#BUTTON,"stop")
Else
rot = 0
SetGadgetText(#BUTTON,"rotate")
EndIf
EndSelect
EndIf
y.l + rot
x.l + rot
z.l + rot
RotateEntity(#ENTITY_FISH, 0, y, 0)
count.f + 0.03
LightLocate(#LIGHT, Sin(count+#PI/2) * 30, 20, Cos(count+#PI/2) * 30)
;LightLookAt(#LIGHT, 30, 0, 30)
RenderWorld()
FlipBuffers()
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Escape)
Quit = #True
EndIf
Until Quit = #True Or Event = #PB_Event_CloseWindow