Jump to content

fw.Main.camera and Pivots


Marleys Ghost
 Share

Recommended Posts

Is it ok to parent fw.Main.camera to a pivot? I am about to try a simple 3rd person camera and thought the simplest way would be to have a pivot that is moved to the controllers position and have the fw.Main.camera parented to it. Any pitfalls with this approach?

 

something like:

 

Global campiv:TPivot = CreatePivot()
playerpos.Y = playerpos.Y + 0.80
PositionEntity(campiv,playerpos)	
PositionEntity(fw.Main.camera, Vec3(playerpos.X,playerpos.Y+1,playerpos.Z-3))
EntityParent(fw.Main.camera,campiv)

 

Then use the pivot to steer the controller with the camera back and up following the pivot.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Sounds like a perfectly fine approach. I see no reason why you couldn't parent the Framework camera to a pivot. I have previously done so myself when I created an RTS camera.

 

 

Thanks Laurens, thought I'd check first for a change incase I had missed something obvious with this method, its just going to be a simple 3rd person cam for test purposes.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Well .. attempt #1 was kind of a success, seem to have an issue with reflections in the waterplane. :)

 

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

You need to rotate all 3 cameras, not just the main camera.

 

 

 

well thats something I have been trying (still no luck yet) but why would that be the case? as the pivot is just another way to positon the main camera and I don't normally have to rotate/position the others in relation to the main camera.

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Each world is completely independant of eachother, so the cameras in each are also.

When you rotate only the main camera, the reflection camera and skybox camera doesn't rotate.

I don't know why your skybox camera rotates, maybe Framework rotates it with the main camera.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

You need to rotate all 3 cameras, not just the main camera.

 

When you rotate only the main camera, the reflection camera and skybox camera doesn't rotate. I don't know why your skybox camera rotates,

 

 

So which is it then .. rotate the cameras or stop them rotating? :)

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Rotate them all always, but also zoom them all.

 

 

ok, but am still not sure why the cameras in the other worlds require rotation because of the addition of a pivot? zoom too when zoom has not been changed in Main?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

When you rotate the main camera, you need always to rotate the background and transparency camera too. Actually I remember now faintly that Framework does that automatically, as well as the zooming, but if not, then you need to do it. If Framework indeed rotates the cameras, the your parenting might be messing up Framework's camera rotations, and then you need to manually rotate the other cameras, since when the main camera is parented to a pivot, it might look for Framework that the camera is not rotated at all, but only the pivot is rotated.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Well this is the code I am using, the additions to the Simple Scene Loader code are enclosed in dashed lines.

 

I think it may well be the parenting. as removal of the parenting line clears up the reflection issue (of course the main cam then no longer functions as required lol)

 

SuperStrict

Framework leadwerks.engine

Import "PATH TO YOUR 2.3 SDK FOLDER\BMX\Framework\framework.bmx"
Include "lua-gluefunctions.bmx"


AppTitle:String = "3rd Person cam test"
GCSetMode(2)

'Register the directory under which the abstract file system will search.
RegisterAbstractPath("PATH TO YOUR 2.3 SDK FOLDER")

'Create a Graphics window
Graphics(800, 600)


AFilter(1) 'Set the anisotropic filter. Range 1-16

'Using AFilter(MaxAFilter()) will use the maximum supported anisotropic filter on your PC
'Adding the line "DrawText ("MaxAFilter = " + MaxAFilter(), 0, 80)"
'after "fw.Render()" will display on screen the maximum supported anisotropic filter.

TFilter(1) 'Set trilinear filtering : 0 = off : 1 = on.


'Create a new Framework object.
Global fw:TFramework = TFramework.Create()
If Not fw RuntimeError "Failed to initialize engine."

       SetScriptObject("fw", fw)'Setup the global script objects.
       SetPostFX()'Setup the post processing FX
       SetVegetationShadowMode(0)'Setup vegetation layer shadows : 0 = off : 1 = on.

'Load the scene. 
       Global scene:TEntity = LoadScene("abstract::YOUR_SCENE.sbx")


'Setup the player controller.
       Global player:TController = CreateController(2.0)
       PositionEntity(player, StringToVec3(scene.getkey("cameraposition")))
       EntityType(player, 3) 
       SetBodyMass(player, 50.0)
       SetBodyBuoyancyMode(player,0)
       Collisions(1, 3, 3)

'Setup the player movement variables.
       Global move:Float = 0.0
       Global strafe:Float = 0.0
       Global camrotation:TVec3 = Vec3(0)
       Global mx:Float = 0.0
       Global my:Float = 0.0
       Global jump:Float = 0.0
       Global playerpos:TVec3 = Vec3(0)


'--------------------------------------------------------------------------------
'Setup the player character model
Global player_body:TEntity = CreateCube()
playerpos = EntityPosition(player)
PositionEntity(player_body,playerpos)
EntityParent(player_body,player)

Global campiv:TPivot = CreatePivot()
playerpos.Y = playerpos.Y + 0.80
PositionEntity(campiv,playerpos)	
PositionEntity(fw.Main.camera, Vec3(playerpos.X,playerpos.Y+1,playerpos.Z-3))
EntityParent(fw.Main.camera,campiv)
'--------------------------------------------------------------------------------

       HideMouse()

'Set stats level : 0 = No statistics : 1 = Show frame rate : 2 = Full statistics. 
       fw.SetStats(2)

'Main program loop.
Repeat
       If KeyHit(KEY_ESCAPE) Exit
       If AppTerminate() Exit

       UpdateAppTime()
       UpdateWorld(AppSpeed())

       PlayerController()

       fw.Update()
       fw.Render()

       Flip(0)
Forever
fw.renderer.gbuffer = Null
GCCollect()
End

'Functions.

Function SetPostFX()'0 = off : 1 = on.
       fw.renderer.SetAntialias(1)
       fw.renderer.SetBloom(1) 
       fw.renderer.SetGodRays(1)
       fw.renderer.SetHDR(1)
       fw.renderer.SetSSAO(0)
       fw.renderer.SetWireFrame(0)     
End Function

Function PlayerController()
       mx = Curve(MouseX() - GraphicsWidth() / 2, mx, 6)
       my = Curve(MouseY() - GraphicsHeight() / 2, my, 6)
       MoveMouse(GraphicsWidth() / 2, GraphicsHeight() / 2)
       camrotation.X = camrotation.X + my / 10.0
       camrotation.Y = camrotation.Y - mx / 10.0

'--------------------------------------------------------------------------------
RotateEntity(campiv, camrotation)
'--------------------------------------------------------------------------------

       move = KeyDown(KEY_W) - KeyDown(KEY_S)
       strafe = KeyDown(KEY_D) - KeyDown(KEY_A)
       jump:Float = 0.0
       If KeyHit(KEY_SPACE) & Not ControllerAirborne(player)
               jump = 4.0
       End If
       If KeyDown(KEY_LSHIFT) | KeyDown(KEY_RSHIFT)
               move = move * 3.0
               strafe = strafe * 3.0
       End If

'--------------------------------------------------------------------------------
playerpos = EntityPosition(player)
  	playerpos.Y = playerpos.Y + 0.80
  	PositionEntity(campiv, playerpos)
'--------------------------------------------------------------------------------

       UpdateController(player, camrotation.Y, move * 3, strafe * 3, jump, 500, 10)
End Function

Function StringToVec2:TVec2(text:String, scale:Float = 1.0)
       Local t:TVec2 = Vec2(1)
       Local sarr:String[]
       sarr = text.split(",")
       If sarr
               If sarr.length > 0 t.x = Float(sarr[0]) * scale
               If sarr.length > 1 t.y = Float(sarr[1]) * scale
       EndIf
       Return t
EndFunction

Function StringToVec3:TVec3(text:String, scale:Float = 1.0)
       Local t:TVec3 = Vec3(1)
       Local sarr:String[]
       sarr = text.split(",")
       If sarr
               If sarr.length > 0 t.x = Float(sarr[0]) * scale
               If sarr.length > 1 t.y = Float(sarr[1]) * scale
               If sarr.length > 2 t.z = Float(sarr[2]) * scale
       EndIf
       Return t
EndFunction

Function StringToVec4:TVec4(text:String, scale:Float = 1.0)
       Local t:TVec4 = Vec4(1)
       Local sarr:String[]
       sarr = text.split(",")
       If sarr
               If sarr.length > 0 t.x = Float(sarr[0]) * scale
               If sarr.length > 1 t.y = Float(sarr[1]) * scale
               If sarr.length > 2 t.z = Float(sarr[2]) * scale
               If sarr.length > 3 t.w = Float(sarr[3]) * scale
       EndIf
       Return t
EndFunction

Function SetScriptObject(name:String, o:Object)
       Local size:Int=GetStackSize()
       lua_pushbmaxobject(luastate.L,o)
       lua_setglobal(luastate.L,name)
       SetStackSize(size)
EndFunction

Function GetStackSize:Int()
       Return lua_gettop(luastate.L)
EndFunction

Function SetStackSize(size:Int)
       Local currentsize:Int=GetStackSize()
       If size<currentsize
       lua_pop(luastate.L,currentsize-size)
       EndIf
EndFunction

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Instead of parenting you can do just first positioning, then rotating and then moving. It works in many cases better than parenting.

 

 

I think maybe you are right, seems there were pitfalls with this approach. shame really it worked so well .. up to a point that is :)

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

[solved] Thanks for the above suggestion Lumooja :)
  • Upvote 1

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...