PureBasic Forumhttps://www.purebasic.fr/english/ [Solved]: Get X or Y reference from camera frontal viewhttps://www.purebasic.fr/english/viewtopic.php?f=36&t=72394 Page 1 of 1

 Author: Psychophanta [ Mon Mar 04, 2019 1:43 pm ] Post subject: [Solved]: Get X or Y reference from camera frontal view Hi,we can access to a front view vector via:CameraDirectionX(), CameraDirectionY() and CameraDirectionZ()So, we can get the front (Z) vector.Is there any native function, trick or workaround to get also its 'X' and/or its 'Y' vector?Thanks in advance !

 Author: Psychophanta [ Fri Mar 08, 2019 7:14 pm ] Post subject: Re: Question: Get X or Y reference from camera frontal view @Comtois, you again retrieve the 'Z' vector.Question is:Quote:Is there any native function, trick or workaround to get also its 'X' and/or its 'Y' vector?

 Author: Comtois [ Fri Mar 08, 2019 8:07 pm ] Post subject: Re: Question: Get X or Y reference from camera frontal view and answer is :AxisX = orientation * UnitXAxisY = orientation * UnitYAxisZ = orientation * -UnitZMay be i should writeVector X = orientation * UnitXVector Y = orientation * UnitYVector Z = orientation * -UnitZ

 Author: Psychophanta [ Sat Mar 09, 2019 9:55 am ] Post subject: Re: Question: Get X or Y reference from camera frontal view Question is not that.Is not about front vector, nor back vector, but "up" and "right" vectors of the object.

 Author: Comtois [ Sat Mar 09, 2019 11:18 am ] Post subject: Re: Question: Get X or Y reference from camera frontal view you are disturbed by the debug, it was to control the result of the Qmv() Procedure.Either, I modified my code to highlight the 3 axes.Code:#CameraSpeed = 2IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"Define.f KeyX, KeyY, MouseX, MouseYStructure Vector3  x.f  y.f  z.fEndStructureStructure quaternion Extends Vector3  w.fEndStructure  Declare QmV(*R.Vector3, *Q.Quaternion, *V.Vector3) Define.Vector3 UnitX, UnitY, UnitZ,AxisX, AxisY, AxisZDefine.quaternion qUnitX\x=1 : UnitX\y=0 : UnitX\z=0UnitY\x=0 : UnitY\y=1 : UnitY\z=0UnitZ\x=0 : UnitZ\y=0 : UnitZ\z=-1If InitEngine3D()    InitSprite()  InitKeyboard()  InitMouse()    If Screen3DRequester()        Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models", #PB_3DArchive_FileSystem)    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/skybox.zip", #PB_3DArchive_Zip)    Parse3DScripts()        ; First create materials    ;        GrassMaterial = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any,"grass1.png")))    MaterialBlendingMode(GrassMaterial, #PB_Material_AlphaBlend)    DirtMaterial = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any,"Dirt.jpg")))            ; Then create the billboard group and use the previous material    ;    ;-Billboard        Billboard = CreateBillboardGroup(#PB_Any, MaterialID(GrassMaterial), 96, 96, 0, 0, 0, -1, 1)    BillboardGroupCommonDirection(Billboard, 0, 1, 0)        For i = 0 To 600      AddBillboard(Billboard, Random(2000)-1000, Random(18) + 30, Random(2000) - 1000)    Next i        ; create ground        MeshPlane = CreatePlane(#PB_Any, 2000, 2000, 40, 40, 4, 4)    CreateEntity(#PB_Any, MeshID(MeshPlane), MaterialID(DirtMaterial))        ; Add house    MeshHouse = LoadMesh(#PB_Any, "tudorhouse.mesh")    House = CreateEntity(#PB_Any, MeshID(MeshHouse), #PB_Material_None, 0, 280, 0)    ScaleEntity(House, 0.5, 0.5, 0.5)        ; SkyBox    SkyBox("stevecube.jpg")        ; create camera    Camera = CreateCamera(#PB_Any, 0, 0, 100, 100)    MoveCamera(Camera, 200, 400, 900, #PB_Absolute)    CameraLookAt(Camera, 0, 100, 0)        ; create camera    Camera2 = CreateCamera(#PB_Any, 0, 0, 20, 20)    MoveCamera(Camera2, 280, 240, 90, #PB_Absolute)    CameraLookAt(Camera2, 0, 100, 0)        d=100    Repeat      Screen3DEvents()            If ExamineMouse()        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05      EndIf            If ExamineKeyboard()                If KeyboardPushed(#PB_Key_Left)          KeyX = -#CameraSpeed         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            RotateCamera(Camera, MouseY, MouseX, 0, #PB_Relative)      MoveCamera  (Camera, KeyX, 0, KeyY)            FetchOrientation(CameraID(Camera2))      q\x = GetX()      q\y = GetY()      q\z = GetZ()      q\w = GetW()            Qmv(@AxisX, @q, @UnitX)      Qmv(@AxisY, @q, @UnitY)      Qmv(@AxisZ, @q, @UnitZ)            CreateLine3D(0, CameraX(Camera2), CameraY(Camera2), CameraZ(Camera2), RGB(255,0,0), CameraX(Camera2) + AxisX\x*d, CameraY(Camera2) + AxisX\y*d, CameraZ(Camera2) + AxisX\z*d, RGB(255,0,0))      CreateLine3D(1, CameraX(Camera2), CameraY(Camera2), CameraZ(Camera2), RGB(0,255,0), CameraX(Camera2) + AxisY\x*d, CameraY(Camera2) + AxisY\y*d, CameraZ(Camera2) + AxisY\z*d, RGB(0,255,0))      CreateLine3D(2, CameraX(Camera2), CameraY(Camera2), CameraZ(Camera2), RGB(0,0,255), CameraX(Camera2) + AxisZ\x*d, CameraY(Camera2) + AxisZ\y*d, CameraZ(Camera2) + AxisZ\z*d, RGB(0,0,255))                        RenderWorld()      Screen3DStats()      FlipBuffers()    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1  EndIf  Else  MessageRequester("Error", "The 3D Engine can't be initialized",0)EndIfEndMacro CROSS_PRODUCT(N, V1, V2)  N\x = ((V1\y * V2\z) - (V1\z * V2\y))  N\y = ((V1\z * V2\x) - (V1\x * V2\z))  N\z = ((V1\x * V2\y) - (V1\y * V2\x))EndMacro; Vector3 = Quaternion * Vector3Procedure QmV(*R.Vector3, *Q.Quaternion, *V.Vector3)   ; nVidia SDK implementation  Protected.Vector3 uv, uuv   CROSS_PRODUCT(uv, *Q, *V)  CROSS_PRODUCT(uuv, *Q, uv)  uv\x * (2.0 * *Q\w)  uv\y * (2.0 * *Q\w)  uv\z * (2.0 * *Q\w)  uuv\x * 2.0  uuv\y * 2.0   uuv\z * 2.0    *R\x = *V\x + uv\x + uuv\x   *R\y = *V\y + uv\y + uuv\y   *R\z = *V\z + uv\z + uuv\z EndProcedure