Page 1 sur 1

Rotation de la Camera (Confusion des axes)

Publié : jeu. 17/avr./2014 11:53
par falsam
Cette extrait de code m'intrigue !

Code : Tout sélectionner

  If ExamineMouse()
    CamX = -MouseDeltaY() * 0.05
    CamY = -MouseDeltaX() * 0.05
    RotateCamera(Camera, CamX, CamY, 0, #PB_Relative) 
  EndIf
MouseDeltaY() et MouseDeltaX() Renvoient le déplacement vertical ou horizontal (en pixels) de la souris depuis le dernier appel de cette fonction.

Pourquoi je suis obligé de tester la rotation sur l'axe des x (Axe horizontal) avec MouseDeltaY() ? Meme question pour l'axe vertical.

Code exemple

Code : Tout sélectionner

EnableExplicit

Enumeration
  #Mainform
EndEnumeration

Global WWIdth, WHeight
Global Event
Global CamX.f, CamY.f
Global Camera, MEsh

InitEngine3D()
InitKeyboard()
InitSprite()
InitMouse()

OpenWindow(#Mainform,0,0, 0, 0, "", #PB_Window_SystemMenu | #PB_Window_Maximize)
WWidth = WindowWidth(#Mainform, #PB_Window_InnerCoordinate)
WHeight = WindowHeight(#Mainform, #PB_Window_InnerCoordinate)
OpenWindowedScreen(WindowID(#Mainform),0,0,WWIdth,WHeight,0, 0, 0)

KeyboardMode(#PB_Keyboard_International)
 
;Lumiere et ombre
AmbientColor(RGB(127, 127, 127))
CreateLight(#PB_Any,RGB(151, 251, 151), -1.8, 10, 5)
WorldShadows(#PB_Shadow_Additive)

;Camera 
Camera = CreateCamera(#PB_Any,0,0,100,100)
CameraBackColor(Camera, RGB(145, 182, 201))

MoveCamera(Camera, 0, 5, 15, #PB_Absolute)  
CameraLookAt(Camera, 0,0,0)   

;Sol
Mesh = CreatePlane(#PB_Any, 20, 20, 1, 1, 1, 1)
CreateEntity(#PB_Any, MeshID(Mesh), #PB_Material_None)

;Deux Objets
Mesh = CreateCube(#PB_Any, 1)
CreateEntity(#PB_Any, MeshID(Mesh), #PB_Material_None, -2, 0.5, 0)
CreateEntity(#PB_Any, MeshID(Mesh), #PB_Material_None, 2, 0.5, 0)

Repeat
  Repeat
    Event  = WindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        End
        
    EndSelect
  Until Event = 0
  
  If ExamineMouse()
    CamX = -MouseDeltaY() * 0.05
    CamY = -MouseDeltaX() * 0.05
    RotateCamera(Camera, CamX, CamY, 0, #PB_Relative) 
  EndIf

  If ExamineKeyboard()
    If KeyboardPushed (#PB_Key_Escape)
      Break
    EndIf
  EndIf
    
  ; Affiche le rendu de la scène
  ClearScreen(RGB(0, 0, 0))
  RenderWorld(80)
  FlipBuffers()    
ForEver

Re: Rotation de la Camera (Confusion des axes)

Publié : jeu. 17/avr./2014 18:22
par comtois
petit rappel

Image

Comme le montre le dessin, pour tourner sur l'axe Y, il faut bien tester un mouvement de la souris sur l'axe x.