Aha! The problem is with CameraRoll().. I don't know how to fix it, but maybe you do.
For some reason, the CameraRoll() is changing from 0 to another number, it should ALWAYS be at 0.. Idk why it is doing this.
Code: Select all
;PRESS Escape to exit
#CameraSpeed = 1
Define.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
ExamineDesktops()
Width=DesktopWidth(0)
Height=DesktopHeight(0)
OpenWindow(0, 0, 0, Width, Height, "Camera")
OpenWindowedScreen(WindowID(0), 0, 0, Width, Height, 0, 0, 0)
BoxTexture=CreateTexture(#PB_Any,256,256)
StartDrawing(TextureOutput(BoxTexture))
Box(0,0,256,256,RGB(255,255,0))
StopDrawing()
BoxMaterial=CreateMaterial(#PB_Any, TextureID(BoxTexture))
SetMaterialColor(BoxMaterial, #PB_Material_SpecularColor, RGB(255,255,255))
MaterialShininess(BoxMaterial,32)
PlaneTexture=CreateTexture(#PB_Any,256,256)
StartDrawing(TextureOutput(PlaneTexture))
Box(0,0,256,256,RGB(0,255,255))
StopDrawing()
PlaneMaterial=CreateMaterial(#PB_Any, TextureID(PlaneTexture))
SetMaterialColor(PlaneMaterial, #PB_Material_SpecularColor, RGB(255,255,255))
MaterialShininess(PlaneMaterial,32)
Box=CreateCube(#PB_Any,0.5)
BoxEntity=CreateEntity(#PB_Any,MeshID(Box),MaterialID(BoxMaterial))
Plane=CreatePlane(#PB_Any,10,10,10,10,10,10)
PlaneEntity=CreateEntity(#PB_Any,MeshID(Plane),MaterialID(PlaneMaterial),0,-1,0)
Light=CreateLight(#PB_Any, RGB(130,130,130), 1, 4, 4)
SetLightColor(Light, #PB_Light_DiffuseColor, RGB(200,200,200))
SetLightColor(Light, #PB_Light_SpecularColor, RGB(255,255,255))
Camera=CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(Camera, 0, 0, 5, #PB_Absolute)
CameraBackColor(Camera,RGB(50,50,50))
Node=CreateNode(#PB_Any,0,0,0)
AttachNodeObject(Node,CameraID(Camera))
NodeFixedYawAxis(Node, #True, 0, 1, 0)
XLine=CreateLine3D(#PB_Any,0,0,0,RGB(255,0,0),5,0,0,RGB(255,0,0))
YLine=CreateLine3D(#PB_Any,0,0,0,RGB(0,255,0),0,5,0,RGB(0,255,0))
ZLine=CreateLine3D(#PB_Any,0,0,0,RGB(0,0,255),0,0,5,RGB(0,0,255))
TextObj1 = TextGadget(#PB_Any, 10, 10, WindowWidth(wnd), 25, "")
TextObj2 = TextGadget(#PB_Any, 10, 30, WindowWidth(wnd), 25, "")
TextObj3 = TextGadget(#PB_Any, 10, 50, WindowWidth(wnd), 25, "")
TextObj4 = TextGadget(#PB_Any, 10, 70, WindowWidth(wnd), 25, "")
TextObj5 = TextGadget(#PB_Any, 10, 90, WindowWidth(wnd), 25, "")
TextObj6 = TextGadget(#PB_Any, 10, 110, WindowWidth(wnd), 25, "")
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow
Quit = 1
EndIf
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
EndIf
If ExamineKeyboard()
EndIf
npitch = NodePitch(Node, 1)
nyaw = NodeYaw(Node, 1)
nroll = NodeRoll(Node, 1)
If npitch < 90: npitch = 90: EndIf
If npitch > -90: npitch = -90: EndIf
RotateNode(Node, MouseY, MouseX, 0, #PB_Relative)
RotateEntity(Boxentity, 0, MouseX, 0, #PB_Relative)
CameraLookAt(Camera, EntityX(BoxEntity), EntityY(BoxEntity), EntityZ(BoxEntity))
NodeLookAt(Node, CameraX(Camera), CameraY(Camera), CameraZ(Camera), 0, 0, 0)
RenderWorld()
SetGadgetText(TextObj1, "MouseX: "+MouseX)
SetGadgetText(TextObj2, "MouseY: "+MouseY)
SetGadgetText(TextObj3, "----------------")
SetGadgetText(TextObj4, "Node Pitch/Yaw/Roll: "+npitch+", "+nyaw+", "+nroll)
SetGadgetText(TextObj5, "----------------")
SetGadgetText(TextObj6, "Cam Pitch/Yaw/Roll: "+CameraPitch(Camera, 1)+", "+CameraYaw(Camera, 1)+", "+CameraRoll(Camera, 1))
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End