Page 1 of 1

How is NodeFixedYawAxis() working?

Posted: Wed Oct 02, 2013 5:15 pm
by Bananenfreak
Hello friends,

I tried many variants with the code below, all variants of vectors. But it´s not working at all.

Code: Select all

NodeFixedYawAxis(Node, #True, 0, 0, 0)
This is a code of a user from the german PB-Forum:
EnableExplicit

If InitEngine3D()
InitSprite()
InitMouse()
InitKeyboard()
Else
MessageRequester("Error", "Can Not init 3D engine !")
End
EndIf

Define.i TexFloor, MatFloor, MshFloor, EntFloor, MshCube, EntCube, Camera, Node, MouseX, MouseY, nodemode, quit, DebugFont, DebugSprite

If OpenWindow(0, 0, 0, 1024, 768, "3D Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If Not OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0))
MessageRequester("Error", "Can not open windowed screen !")
End
EndIf
Else
MessageRequester("Error", "Can not open window !")
End
EndIf

TexFloor = CreateTexture(#PB_Any, 128, 128)
StartDrawing(TextureOutput(TexFloor))
Box( 0, 0, 128, 128, RGB(225,225,225))
Box(63, 0, 64, 64, RGB( 0, 0,128))
Box( 0,63, 64, 64, RGB( 0, 0,128))
StopDrawing()

MatFloor = CreateMaterial(#PB_Any, TextureID(TexFloor))
SetMaterialColor(MatFloor, #PB_Material_AmbientColor, RGB(175, 238, 238))

MshFloor = CreatePlane(#PB_Any, 1000, 1000, 1, 1, 10, 10)
MshCube = CreateCube(#PB_Any, 100)

EntFloor = CreateEntity(#PB_Any, MeshID(MshFloor), MaterialID(MatFloor), 0, 0, 0)
EntCube = CreateEntity(#PB_Any, MeshID(MshCube), MaterialID(MatFloor), 0, 100, -750)
RotateEntity(EntCube, 45, 45, 0)

Node = CreateNode(#PB_Any, 0, 64, 0)
;NodeFixedYawAxis(Node, #True, 0, 0, 0)

Camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(Camera, 0, 64, 0)

AmbientColor(RGB(0,0,128))

DebugSprite = CreateSprite(#PB_Any, 500, 100)
DebugFont = LoadFont(#PB_Any, "Courier New", 11)

Repeat

If ExamineKeyboard()
If KeyboardReleased(#PB_Key_F1)
If nodemode
nodemode = #False
DetachNodeObject(Node, CameraID(Camera))
Else
nodemode = #True
AttachNodeObject(Node, CameraID(Camera))
EndIf
ElseIf KeyboardReleased(#PB_Key_Escape)
quit = 1
EndIf
EndIf

If ExamineMouse()
MouseX = -MouseDeltaX() / 10
MouseY = -MouseDeltaY() / 10
EndIf

If nodemode
RotateNode(Node, MouseY, MouseX, 0, #PB_Relative)
Else
RotateCamera(Camera, MouseY, MouseX, 0, #PB_Relative)
EndIf

RenderWorld()

StartDrawing(SpriteOutput(DebugSprite))
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(DebugFont))
FrontColor(RGB(255,255,0))
Box(0, 0, SpriteWidth(DebugSprite), SpriteHeight(DebugSprite), 0)
DrawText( 5, 5, "Direction/Node : x=" + StrF(NodePitch(Node),1) + ", y=" + StrF(NodeYaw(Node),1) + ", z=" + StrF(NodeRoll(Node),1))
DrawText( 5,25, "Direction/Camera: x=" + StrF(CameraPitch(Camera),1) + ", y=" + StrF(CameraYaw(Camera),1) + ", z=" + StrF(CameraRoll(Camera),1))
If nodemode
DrawText(5,45, "Node Mode - hit F1 to switch")
Else
DrawText(5,45, "Camera Mode - hit F1 to switch")
EndIf
StopDrawing()

DisplayTransparentSprite(DebugSprite, 0, 0)

FlipBuffers()

Until quit = 1

End
Please try it and help me :)

Re: How is NodeFixedYawAxis() working?

Posted: Wed Oct 02, 2013 6:33 pm
by Comtois
In this example i choose

Code: Select all

NodeFixedYawAxis(Node, #True, 1, 0, 0)
so node will rotate around axis X even if i ask it to rotate around y

Code: Select all

  RotateNode(Node, 0, 1, 0, #PB_Relative)

Code: Select all

EnableExplicit

If InitEngine3D()
  InitSprite()
  InitMouse()
  InitKeyboard()
Else
  MessageRequester("Error", "Can Not init 3D engine !")
  End
EndIf

Define.i TexFloor, MatFloor, MshFloor, EntFloor, MshCube, EntCube, Camera, Node, MouseX, MouseY, nodemode, quit, DebugFont, DebugSprite

If OpenWindow(0, 0, 0, 1024, 768, "3D Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  If Not OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0))
    MessageRequester("Error", "Can not open windowed screen !")
    End
  EndIf
Else
  MessageRequester("Error", "Can not open window !")
  End
EndIf

TexFloor = CreateTexture(#PB_Any, 128, 128)
StartDrawing(TextureOutput(TexFloor))
Box( 0, 0, 128, 128, RGB(225,225,225))
Box(63, 0, 64, 64, RGB( 0, 0,128))
Box( 0,63, 64, 64, RGB( 0, 0,128))
StopDrawing()

MatFloor = CreateMaterial(#PB_Any, TextureID(TexFloor))
SetMaterialColor(MatFloor, #PB_Material_AmbientColor, RGB(175, 238, 238))

MshFloor = CreatePlane(#PB_Any, 1000, 1000, 1, 1, 10, 10)
MshCube = CreateCube(#PB_Any, 100)

EntFloor = CreateEntity(#PB_Any, MeshID(MshFloor), MaterialID(MatFloor), 0, 0, 0)
EntCube = CreateEntity(#PB_Any, MeshID(MshCube), MaterialID(MatFloor))
;RotateEntity(EntCube, 45, 45, 0)

Node = CreateNode(#PB_Any, 0, 100, -750)
 AttachNodeObject(Node, EntityID(EntCube))
NodeFixedYawAxis(Node, #True, 1, 0, 0)

Camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(Camera, 0, 64, 0)

AmbientColor(RGB(0,0,128))

DebugSprite = CreateSprite(#PB_Any, 500, 100)
DebugFont = LoadFont(#PB_Any, "Courier New", 11)

Repeat
  While WindowEvent()
  Wend  
  If ExamineKeyboard()
    If KeyboardReleased(#PB_Key_Escape)
      quit = 1
    EndIf
  EndIf
  
  If ExamineMouse()
    MouseX = -MouseDeltaX() / 10
    MouseY = -MouseDeltaY() / 10
  EndIf
  
  RotateNode(Node, 0, 1, 0, #PB_Relative)

  
  RenderWorld()
  
  StartDrawing(SpriteOutput(DebugSprite))
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawingFont(FontID(DebugFont))
  FrontColor(RGB(255,255,0))
  Box(0, 0, SpriteWidth(DebugSprite), SpriteHeight(DebugSprite), 0)
  DrawText( 5, 5, "Direction/Node : x=" + StrF(NodePitch(Node),1) + ", y=" + StrF(NodeYaw(Node),1) + ", z=" + StrF(NodeRoll(Node),1))
  DrawText( 5,25, "Direction/Camera: x=" + StrF(CameraPitch(Camera),1) + ", y=" + StrF(CameraYaw(Camera),1) + ", z=" + StrF(CameraRoll(Camera),1))
  If nodemode
    DrawText(5,45, "Node Mode - hit F1 to switch")
  Else
    DrawText(5,45, "Camera Mode - hit F1 to switch")
  EndIf
  StopDrawing()
  
  DisplayTransparentSprite(DebugSprite, 0, 0)
  
  FlipBuffers()
  
Until quit = 1

End

Re: How is NodeFixedYawAxis() working?

Posted: Thu Oct 03, 2013 6:24 am
by Comtois
more info here
Tells the node whether to yaw around it's own local Y axis or a fixed axis of choice.

Remarks:
This method allows you to change the yaw behaviour of the node - by default, it yaws around it's own local Y axis when told to yaw with TS_LOCAL, this makes it yaw around a fixed axis. You only really need this when you're using auto tracking (see setAutoTracking, because when you're manually rotating a node you can specify the TransformSpace in which you wish to work anyway.

Parameters:
useFixed If true, the axis passed in the second parameter will always be the yaw axis no matter what the node orientation. If false, the node returns to it's default behaviour.
fixedAxis The axis to use if the first parameter is true.

more info about CameraFixedYaw()
Tells the camera whether to yaw around it's own local Y axis or a fixed axis of choice.

Remarks:
This method allows you to change the yaw behaviour of the camera

by default, the camera yaws around a fixed Y axis. This is often what you want - for example if you're making a first-person shooter, you really don't want the yaw axis to reflect the local camera Y, because this would mean a different yaw axis if the player is looking upwards rather than when they are looking straight ahead. You can change this behaviour by calling this method, which you will want to do if you are making a completely free camera like the kind used in a flight simulator.

Parameters:
useFixed If true, the axis passed in the second parameter will always be the yaw axis no matter what the camera orientation. If false, the camera yaws around the local Y.
fixedAxis The axis to use if the first parameter is true

Re: How is NodeFixedYawAxis() working?

Posted: Thu Oct 03, 2013 8:18 am
by Bananenfreak
Thanks Comtois.

I forgot to say that this Node should be a Cameranode. If I rotate the Node (Camera) in normal mode, the node (cam) will rotate with the Z-Axis, too.
I don´t want this, I only want a Rotation with the X- and Y-Axis.

I mean this one:
by default, the camera yaws around a fixed Y axis. This is often what you want - for example if you're making a first-person shooter, you really don't want the yaw axis to reflect the local camera Y, because this would mean a different yaw axis if the player is looking upwards rather than when they are looking straight ahead. You can change this behaviour by calling this method, which you will want to do if you are making a completely free camera like the kind used in a flight simulator.
So, where I have to place NodeFixedYawAxis() and which Flags I have to set (Which Vectors)?