Page 1 of 1

Question moving camera and its node

Posted: Sat Aug 25, 2018 3:22 pm
by Psychophanta
Please play a little bit with this and look the comments to get the questions:

Code: Select all

InitEngine3D()
InitSprite():InitKeyboard():InitMouse()
OpenWindow(0,0,0,800,600,"cam",#PB_Window_BorderLess)
OpenWindowedScreen(WindowID(0),0,0,800,600,0,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(#PB_Compiler_Home+"examples/3d/Data/Textures",#PB_3DArchive_FileSystem)
Parse3DScripts()
#mascarapick=32
#mascaravisivilidad=32
; Luz, suelo, cielo y camara
luz.i=CreateLight(#PB_Any,RGB(160,160,254),4,4,-2,#PB_Light_Point)
camara.i=CreateCamera(#PB_Any,0,0,100,100,#mascaravisivilidad):pivotcamara.i=CreateNode(#PB_Any,0,0,0):CameraRange(camara.i,0.1,1000):CameraBackColor(camara.i,$181111)
AttachNodeObject(pivotcamara.i,CameraID(camara.i)):MoveCamera(camara.i,0,0,4,#PB_Absolute):RotateNode(pivotcamara.i,0,0,0,#PB_Relative)
; Texturas
varillatextura.i=LoadTexture(#PB_Any,"soil_wall.jpg")
; Materiales
varillamaterial.i=CreateMaterial(#PB_Any,TextureID(varillatextura.i))
; Entidades
varillamalla.i=CreateCube(#PB_Any,0.8)
; TransformMesh(varillamalla.i,0,0,0,1,1,1,0,0,0,0)
varilla.i=CreateEntity(#PB_Any,MeshID(varillamalla.i),MaterialID(varillamaterial.i),0,0,0,#mascarapick,#mascaravisivilidad)
Repeat
  ExamineMouse():ExamineKeyboard()
  CursorX.f=WindowMouseX(0):CursorY.f=WindowMouseY(0)
  mdx.f=MouseDeltaX()/200:mdy.f=MouseDeltaY()/200:mdz.f=MouseWheel()/10
  If KeyboardPushed(#PB_Key_LeftControl); <- move eye point
    If mdx Or mdy Or mdz
      If MouseButton(#PB_MouseButton_Right)
        MoveNode(pivotcamara,mdx,-mdy,0,#PB_Relative|#PB_Local); <- How to use to displace the node relatively to its current orientation?. I find no way for it!
      Else
        RotateNode(pivotcamara,-mdy*60,-mdx*60,0,#PB_Relative)
        If mdz
          MoveCamera(camara,0,0,-mdz,#PB_Relative)
        EndIf
      EndIf
    EndIf
  ElseIf KeyboardPushed(#PB_Key_1)
    MoveCamera(camara.i,0,0,4,#PB_Absolute); <- correct
  ElseIf KeyboardPushed(#PB_Key_2)
    MoveCamera(camara.i,0,0,4,#PB_Parent|#PB_Absolute); <- don't understand the behaviour of this one, looks like a non absolute movement
  ElseIf KeyboardPushed(#PB_Key_3)
    MoveCamera(camara.i,0,0,4,#PB_Local|#PB_Absolute); <- same here
  ElseIf KeyboardPushed(#PB_Key_4)
    MoveCamera(camara.i,0,0,4,#PB_World|#PB_Absolute); <- same here
  ElseIf KeyboardPushed(#PB_Key_F3); <- restart
    MoveNode(pivotcamara,0,0,0,#PB_Absolute); <- again!, with #PB_World|#PB_Absolute it does not work!!
    RotateNode(pivotcamara.i,0,0,0,#PB_Absolute)
    MoveCamera(camara.i,0,0,4,#PB_Absolute)
  EndIf
  TimeSinceLastFrame.i=RenderWorld(50)
  FlipBuffers():Delay(9)
Until KeyboardPushed(#PB_Key_Escape)
CloseWindow(0)
Besides of it, as another issue, when dealing with collisions with CreateEntityBody() , I have noticed there is not the same to do this:

Code: Select all

bolamalla.i=CreateSphere(#PB_Any,1,5,10)
TransformMesh(bolamalla.i,0.0,0.0,0.0,0.1,0.1,0.1,0,0,0,0)
or this:

Code: Select all

bolamalla.i=CreateSphere(#PB_Any,0.1,5,10)
because in the first case the volume of the entity appears as 0.1 for its radius, but thats is only appearance because for collisions it is radius=1

Re: Question moving camera and its node

Posted: Sun Aug 26, 2018 8:41 am
by Comtois
doc is wrong

https://www.purebasic.com/documentation ... enode.html

Should be (to be confirmed by Fred) :
The move mode. It can be one of the following values:

#PB_Absolute: absolute move to the specified position.
#PB_Local : move relative to the local space.
#PB_Parent: move relative to the parent space. (default)
#PB_World : move relative to the world.
Idem for Entity

Re: Question moving camera and its node

Posted: Sun Aug 26, 2018 9:07 am
by Comtois
idem for camera, doc is wrong

https://www.purebasic.com/documentation ... amera.html

Should be :
The move mode. It can be one of the following values:

#PB_Absolute: absolute move to the specified position.
#PB_Local : move relative to the local space. (Default)
#PB_World : move relative to the world.

Re: Question moving camera and its node

Posted: Sun Aug 26, 2018 11:04 am
by Psychophanta
I see, thanks.
But in my opinion, should be added the Relative movement for all.
Also should be added Parent option for camera when it is attached to a node.

Re: Question moving camera and its node

Posted: Sun Aug 26, 2018 11:23 am
by Comtois
Psychophanta wrote:But in my opinion, should be added the Relative movement for all.
What do you mean ? It's already done

Also should be added Parent option for camera when it is attached to a node.
Then use MoveNode()

Re: Question moving camera and its node

Posted: Sun Aug 26, 2018 11:41 am
by Psychophanta
Comtois wrote:
Psychophanta wrote:But in my opinion, should be added the Relative movement for all.
What do you mean ? It's already done
Relative movement is relative to its previous position and orientation. Absolute movement is relative to the position (0,0,0) of the world and also relative of the world orientation.
for example, i fyou have a cube rotated respecte the world axis, a relative movement like (-3,0,0) should displace the cube -3 units from its current position, NOT to the world X axis, but in the direction of its LEFT face.
Comtois wrote:Also should be added Parent option for camera when it is attached to a node.
Then use MoveNode()[/quote]
Sometimes is interesting to move the camera respect its node parent. This is nothing to do with Absolute or Relative moving of the camera, because Absolute or Relative refers to the world or to the item itself respectively, never to other item.
Parent refers to other item.

Re: Question moving camera and its node

Posted: Sun Aug 26, 2018 12:04 pm
by DK_PETER
Is this what you want it to do? I've attached varilla to a node instead.

Code: Select all

InitEngine3D() : InitSprite() : InitKeyboard() : InitMouse()
OpenWindow(0,0,0,800,600,"cam",#PB_Window_BorderLess)
OpenWindowedScreen(WindowID(0),0,0,800,600,0,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(#PB_Compiler_Home+"examples/3d/Data/Textures",#PB_3DArchive_FileSystem)
Parse3DScripts()
#mascarapick=32
#mascaravisivilidad=32
; Luz, suelo, cielo y camara
luz.i=CreateLight(#PB_Any,RGB(160,160,254),4,4,-2,#PB_Light_Point)
camara.i=CreateCamera(#PB_Any,0,0,100,100,#mascaravisivilidad):pivotcamara.i=CreateNode(#PB_Any,0,0,0):CameraRange(camara.i,0.1,1000):CameraBackColor(camara.i,$181111)
AttachNodeObject(pivotcamara.i,CameraID(camara.i)):MoveCamera(camara.i,0,0,4,#PB_Absolute):RotateNode(pivotcamara.i,0,0,0,#PB_Relative)
; Texturas
varillatextura.i=LoadTexture(#PB_Any,"soil_wall.jpg")
; Materiales
varillamaterial.i=CreateMaterial(#PB_Any,TextureID(varillatextura.i))
; Entidades
varillamalla.i=CreateCube(#PB_Any,0.8)
; TransformMesh(varillamalla.i,0,0,0,1,1,1,0,0,0,0)
varilla.i=CreateEntity(#PB_Any,MeshID(varillamalla.i),MaterialID(varillamaterial.i),0,0,0,#mascarapick,#mascaravisivilidad)
entityNode.i = CreateNode(#PB_Any, 0, 0, 0)
AttachNodeObject(entityNode, EntityID(varilla))

Repeat
  Repeat : Until WindowEvent() = 0
  ExamineMouse():ExamineKeyboard()
  CursorX.f=MouseX():CursorY.f=MouseY()
  mdx.f=MouseDeltaX()/200:mdy.f=MouseDeltaY()/200:mdz.f=MouseWheel()/10
  If KeyboardPushed(#PB_Key_LeftControl); <- move eye point
    If mdx Or mdy Or mdz
      If MouseButton(#PB_MouseButton_Right)
        MoveNode(entityNode,mdx,-mdy,0,#PB_Relative)
      Else
        RotateNode(entityNode,-mdy*60,-mdx*60,0,#PB_Relative)
        If mdz
          MoveNode(entityNode,0,0,-mdz,#PB_Relative)
        EndIf
      EndIf
    EndIf
  EndIf
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)

Re: Question moving camera and its node

Posted: Sun Aug 26, 2018 1:05 pm
by Psychophanta
That is the visual effect I want DK_PETER, but I want to move just the camera (or its node), not the entity.
Psychophanta wrote:
Comtois wrote:
Psychophanta wrote:But in my opinion, should be added the Relative movement for all.
What do you mean ? It's already done
Relative movement is relative to its previous position and orientation. Absolute movement is relative to the position (0,0,0) of the world and also relative of the world orientation.
for example, i fyou have a cube rotated respecte the world axis, a relative movement like (-3,0,0) should displace the cube -3 units from its current position, NOT to the world X axis, but in the direction of its LEFT face.
Comtois wrote:
Psychophanta wrote:Also should be added Parent option for camera when it is attached to a node.
Then use MoveNode()
Sometimes is interesting to move the camera respect its node parent. This is nothing to do with Absolute or Relative moving of the camera, because Absolute or Relative refers to the world or to the item itself respectively, never to other item.
Parent refers to other item.

It is all ok.
This is just what I wanted to do: NOTICE that the entities in the world are not touched for movements nor rotations, i.e. only camera must move an orbitate.

Code: Select all

InitEngine3D() : InitSprite() : InitKeyboard() : InitMouse()
OpenWindow(0,0,0,800,600,"cam",#PB_Window_BorderLess)
OpenWindowedScreen(WindowID(0),0,0,800,600,0,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(#PB_Compiler_Home+"examples/3d/Data/Textures",#PB_3DArchive_FileSystem)
Parse3DScripts()
#mascarapick=32
#mascaravisivilidad=32
; Luz, suelo, cielo y camara
luz.i=CreateLight(#PB_Any,RGB(160,160,254),4,4,-2,#PB_Light_Point)
camara.i=CreateCamera(#PB_Any,0,0,100,100,#mascaravisivilidad):pivotcamara.i=CreateNode(#PB_Any,0,0,0):CameraRange(camara.i,0.1,1000):CameraBackColor(camara.i,$181111)
AttachNodeObject(pivotcamara.i,CameraID(camara.i)):MoveCamera(camara.i,0,0,4,#PB_Absolute):RotateNode(pivotcamara.i,0,0,0,#PB_Relative)
; Texturas
varillatextura.i=LoadTexture(#PB_Any,"soil_wall.jpg")
; Materiales
varillamaterial.i=CreateMaterial(#PB_Any,TextureID(varillatextura.i))
; Entidades
varillamalla.i=CreateCube(#PB_Any,0.8)
; TransformMesh(varillamalla.i,0,0,0,1,1,1,0,0,0,0)
varilla.i=CreateEntity(#PB_Any,MeshID(varillamalla.i),MaterialID(varillamaterial.i),0,0,0,#mascarapick,#mascaravisivilidad)
Repeat
  ExamineMouse():ExamineKeyboard()
  CursorX.f=MouseX():CursorY.f=MouseY()
  mdx.f=MouseDeltaX()/200:mdy.f=MouseDeltaY()/200:mdz.f=MouseWheel()/20
  If KeyboardPushed(#PB_Key_LeftControl); <- move eye point
    If mdx Or mdy Or mdz
      If MouseButton(#PB_MouseButton_Right)
        MoveNode(pivotcamara,-mdx,mdy,0,#PB_Local):Beep_(333,6)
      Else
        RotateNode(pivotcamara,-mdy*60,-mdx*60,0,#PB_Relative)
        If mdz:Beep_(777,6)
          MoveCamera(camara,0,0,-mdz,#PB_Relative)
        EndIf
      EndIf
    EndIf
  EndIf
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
In my observations, the problem is when merge constants with the or '|' operator; if you don't do that almost everything can be done.

Thanks!

Re: Question moving camera and its node

Posted: Sun Aug 26, 2018 4:22 pm
by DK_PETER

Code: Select all

;In This example I've attached the camera to mainnode
Structure Vector3D : x.f : y.f : z.f : EndStructure
InitEngine3D() : InitSprite() : InitKeyboard() : InitMouse()
OpenWindow(0, 0, 0, 800, 600, "Movement around cube", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 0, 4)
CreateCube(0, 1)
CreateTexture(0, 100, 100, "CubeTex")
StartDrawing(TextureOutput(0))
DrawingMode(#PB_2DDrawing_Outlined)
RoundBox(0, 0, 100, 100, 5, 5, $20EE61)
DrawingMode(#PB_2DDrawing_Gradient)
BackColor($00FF61) : FrontColor($075700)
CircularGradient(50, 50, 40)
Circle(50, 50, 40)
StopDrawing()
CreateMaterial(0, TextureID(0))
MaterialBlendingMode(0, #PB_Material_Add)
MaterialCullingMode(0, #PB_Material_NoCulling)
MaterialFilteringMode(0, #PB_Material_Anisotropic, 8)
CreateEntity(0, MeshID(0), MaterialID(0), 0, 0, 0)
mainnode = CreateNode(#PB_Any, 0, 0, 0)
AttachNodeObject(mainnode, CameraID(0))
p.Vector3D
Repeat
  
  Repeat : Until WindowEvent() = 0
  ExamineKeyboard() : ExamineMouse()
  If KeyboardPushed(#PB_Key_LeftControl)
    p\x = (MouseDeltaX()) / 200
    p\y = (MouseDeltaY()) / 200
    p\z = MouseWheel() / 10
    If p\x Or p\y Or p\z
      If MouseButton(#PB_MouseButton_Right)
        MoveCamera(0, -p\x, p\y, 0, #PB_Relative)
      Else
        RotateNode(mainnode, -p\y*60,-p\x*60,0, #PB_Relative)
      EndIf
        If p\z
          MoveCamera(0, 0, 0,-p\z,#PB_Relative)
        EndIf
    EndIf
    If p\z
      MoveCamera(0, 0, p\z, 0, #PB_Relative)
    EndIf
  EndIf

  RenderWorld()
  
  FlipBuffers()
  
Until KeyboardPushed(#PB_Key_Escape)