T4r4ntul4 wrote:I wanted to use WSAD keys to move the camera, i now use this piece of code: (but cant do that in SB BBjs) Maybe add a function that can do this with any key you specify?
This feature exists with the current version :
■
CameraMapKey(Camera, Key, Value = #PB_Ignore)
Example
Code: Select all
;Camera movement : Redefine the camera keys
InitKey()
CameraMapKey(Camera, #PB_Key_Left, #PB_Key_A)
CameraMapKey(Camera, #PB_Key_Right, #PB_Key_D)
CameraMapKey(Camera, #PB_Key_Up, #PB_Key_W)
CameraMapKey(Camera, #PB_Key_Down, #PB_Key_S)
T4r4ntul4 wrote:I have a few requests: ....
Yes No problem and useful ^-^
■
For the moment I do not publish the modifications. I put the features in an example.
Get Meshes Rotation
- Value.f = GetMeshRotX(Mesh, Mode = #PB_Absolute)
- Value.f = GetMeshRotY(Mesh, Mode = #PB_Absolute)
- Value.f = GetMeshRotZ(Mesh, Mode = #PB_Absolute)
Get Camera Rotation
- Value.f = GetCameraRotX(Camera, Mode = #PB_Absolute)
- Value.f = GetCameraRotY(Camera, Mode = #PB_Absolute)
- Value.f = GetCameraRotZ(Camera, Mode = #PB_Absolute)
Mode :
- #PB_Absolute returns an angle in 0 and 359°
- #PB_Relative returns an infinite angle. Example : 720 (two 360 on himself)
Misc
- onMouseRelease(CallBack)
■ Test code with these features.
<- and -> keys for left and right rotation of the cube.
A D W S button for camera movement.
Click and move the mouse to rotate the camera.
Code: Select all
EnableExplicit
IncludeFile "babylon/babylon.sbi"
Global MouseDown, Scene, Camera, Material, Ground, Box
Declare LoadGame()
Declare MouseDown()
Declare MouseRelease()
Declare MouseMove()
Declare RenderGame()
;-Include
;Private
Procedure.f AngleRotation(Angle.f, Mode)
Protected n
If Mode = #PB_Absolute
n = Angle / 360
ProcedureReturn Angle - (360 * n)
ElseIf Mode = #PB_Relative
ProcedureReturn Angle
Else
ProcedureReturn -1
EndIf
EndProcedure
;Public
Procedure.f GetMeshRotX(Mesh, Mode = #PB_Absolute)
Protected Angle.f, n
!v_angle = v_mesh.rotation.x * 180 / Math.PI
n = Angle / 360
ProcedureReturn Angle - (360 * n)
EndProcedure
Procedure.f GetMeshRotY(Mesh, Mode = #PB_Absolute)
Protected Angle.f
!v_angle = v_mesh.rotation.y * 180 / Math.PI
ProcedureReturn AngleRotation(Angle, Mode)
EndProcedure
Procedure.f GetMeshRotZ(Mesh, Mode = #PB_Absolute)
Protected Angle.f
!v_angle = v_mesh.rotation.z * 180 / Math.PI
ProcedureReturn AngleRotation(Angle, Mode)
EndProcedure
Procedure.f GetCameraRotX(Camera, Mode = #PB_Absolute)
Protected Angle.f
!v_angle = v_camera.rotation.x * 180 / Math.PI
ProcedureReturn AngleRotation(Angle, Mode)
EndProcedure
Procedure.f GetCameraRotY(Camera, Mode = #PB_Absolute)
Protected Angle.f
!v_angle = v_camera.rotation.y * 180 / Math.PI
ProcedureReturn AngleRotation(Angle, Mode)
EndProcedure
Procedure.f GetCameraRotZ(Camera, Mode = #PB_Absolute)
Protected Angle.f
!v_angle = v_camera.rotation.z * 180 / Math.PI
ProcedureReturn AngleRotation(Angle, Mode)
EndProcedure
Procedure onMouseRelease(CallBack)
!v_bjscurrentscene.onPointerUp = function (evt) {
! v_callback(evt)
!}
EndProcedure
;-End Include
;-
UseModule BJS
InitEngine(@LoadGame())
Procedure LoadGame()
Scene = CreateScene()
If Scene
;Light and camera
CreateLight("Ambience", 0, 200, 0)
Camera = CreateCamera("camera", 0, 10, -20, #BJS_Free)
CameraLookAt(Camera, 0, 0, 0)
CameraBodySize(Camera, 1, 5, 1)
;Camera movement : Redefine the camera keys
InitKey()
CameraMapKey(Camera, #PB_Key_Left, #PB_Key_A)
CameraMapKey(Camera, #PB_Key_Right, #PB_Key_D)
CameraMapKey(Camera, #PB_Key_Up, #PB_Key_W)
CameraMapKey(Camera, #PB_Key_Down, #PB_Key_S)
;Ground
Ground = CreateGround("ground", 100, 100)
Material = CreateMaterial("Grass")
SetMaterialTexture(Material, #BJS_Diffuse, LoadTexture("data/textures/grass.png"))
ScaleMaterial(Material, 5, 5)
SetMeshMaterial(Ground, Material)
;Box
Box = CreateBox("My box", 4, 4, 4)
Material = CreateMaterial("crate")
SetMaterialTexture(Material, #BJS_Diffuse, LoadTexture("data/textures/crate.png"))
SetMeshMaterial(Box, Material)
MoveMesh(Box, 0, 2, 0)
onMouseDown(@MouseDown())
onMouseRelease(@MouseRelease())
onMouseMove(@MouseMove())
RenderLoop(@RenderGame())
EndIf
EndProcedure
Procedure MouseDown()
MouseDown = #True
EndProcedure
Procedure MouseRelease()
MouseDown = #False
EndProcedure
Procedure MouseMove()
If MouseDown
Debug "Camera Rotation (x / y) " + StrF(GetCameraRotX(Camera), 2) + " / " + StrF(GetCameraRotY(Camera), 2)
EndIf
EndProcedure
Procedure RenderGame()
If KeyPushed(#PB_Key_Left)
RotateMesh(Box, 0, -2.5, 0, #PB_Relative)
Debug "Mesh Rotation (Y) " + StrF(GetMeshRotY(Box), 2)
EndIf
If KeyPushed(#PB_Key_Right)
RotateMesh(Box, 0, 2.5, 0, #PB_Relative)
Debug "Mesh Rotation (Y) " + StrF(GetMeshRotY(Box), 2)
EndIf
RenderWorld()
EndProcedure
If you agree with this test, I modify babylon.sbi and release the new version.