Page 1 of 1

EntityDirection and NodeDirection

Posted: Wed Mar 25, 2015 5:52 pm
by Henry00
Is it just me or is there no EntityDirection and NodeDirection like seen with the camera and light? It would be great to have the DirectionX, DirectionY, DirectionZ normals for physics calculations.

x.d = CameraDirectionX(#cam)
y.d = CameraDirectionY(#cam)
z.d = CameraDirectionZ(#cam)
EntityVelocity(#entball, x * 10, y * 10, z * 10) ; launch ball!

Thank you very much!

Re: EntityDirection and NodeDirection

Posted: Wed Mar 25, 2015 9:02 pm
by Comtois
http://ogre3d.org/forums/viewtopic.php?f=2&t=52125

And here an example adapted from FetchOrientation.pb

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Orientation
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;
#CameraSpeed = 1

IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"

Structure Vector3
  x.f
  y.f
  z.f
EndStructure

Structure Quaternion
  x.f
  y.f
  z.f
  w.f
EndStructure 


Define.f KeyX, KeyY, MouseX, MouseY, RollZ, sens = -1
Define Pos.Vector3, Orientation.Quaternion
Define.Vector3 Resultat, XDirection, YDirection, ZDirection 

Declare ConvertLocalToWorld(*N.Vector3, *P.Vector3, *Orientation.Quaternion, *Position.Vector3)

XDirection\x = 100 : XDirection\y =   0 : XDirection\z =   0
YDirection\x =   0 : YDirection\y = 100 : YDirection\z =   0
ZDirection\x =   0 : ZDirection\y =   0 : ZDirection\z = 100


If InitEngine3D()
  
  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/Packs/skybox.zip", #PB_3DArchive_Zip)
  Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    CreateCube(0, 50)
    
    CreateMaterial(0, LoadTexture(0, "Dirt.jpg"))
    
    CreateEntity(0, MeshID(0), MaterialID(0))  


    SkyBox("stevecube.jpg")
    
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 90, 80, 150, #PB_Absolute)
        
    Repeat
      Screen3DEvents()
      
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
      
      If ExamineKeyboard()
        
      EndIf
      
      RotateEntity(0, 0, 0.4, 0, #PB_Relative)
      MoveEntity(0, 0, 0, -1, #PB_Local)
      
      Pos\x = EntityX(0) : Pos\y = EntityY(0) :Pos\z = EntityZ(0)  
      
      FetchOrientation(EntityID(0))
      Orientation\x = GetX()
      Orientation\y = GetY()
      Orientation\z = GetZ()
      Orientation\w = GetW()
      
      ConvertLocalToWorld(@Resultat, @XDirection, @Orientation, @Pos)
      CreateLine3D(1, Pos\x, Pos\y, Pos\z, RGB(255,0,0), Resultat\x * 1, Resultat\y *1, Resultat\z *1, RGB(255, 0, 0))
      ConvertLocalToWorld(@Resultat, @YDirection, @Orientation, @Pos)
      CreateLine3D(2, Pos\x, Pos\y, Pos\z, RGB(0,255,0), Resultat\x * 1, Resultat\y *1, Resultat\z *1, RGB(0, 255, 0))
      ConvertLocalToWorld(@Resultat, @ZDirection, @Orientation, @Pos)
      CreateLine3D(3, Pos\x, Pos\y, Pos\z, RGB(0,0,255), Resultat\x * 1, Resultat\y *1, Resultat\z *1, RGB(0, 0, 255))
            
      CameraLookAt(0, Pos\x, Pos\y, Pos\z)
      RenderWorld()

      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf

End 

Macro 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

Procedure QuaternionVector3(*R.Vector3, *Q.Quaternion, *P.Vector3) 
  ; nVidia SDK implementation
  Protected.Vector3 uv, uuv 
  CROSS_PRODUCT(uv, *Q, *P)
  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 = *P\x + uv\x + uuv\x 
  *R\y = *P\y + uv\y + uuv\y 
  *R\z = *P\z + uv\z + uuv\z 
EndProcedure


		
Procedure ConvertLocalToWorld(*N.Vector3, *P.Vector3, *Orientation.Quaternion, *Position.Vector3)
  Protected.Vector3 R
  QuaternionVector3(@R, *Orientation, *P)
  *N\x = R\x + *Position\x
  *N\y = R\y + *Position\y
  *N\z = R\z + *Position\z
EndProcedure
 

Re: EntityDirection and NodeDirection

Posted: Wed Mar 25, 2015 9:10 pm
by Henry00
Thanks that's perfect! I presume future Google users will end up here next time =)