Jump to content

Basic 3rd Person Camera


Marleys Ghost
 Share

Recommended Posts

Basic 3rd Person Camera

 

If you have used the Simple Scene Loader with Player Controller in Blitzmax, this is a small addition to it that will change the camera view to 3rd person.

 

The additions to the Simple Scene Loader code are enclosed in dashed lines.

 

I hope this will be of some use to someone.

 

 

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()
ScaleEntity(player_body,Vec3(0.5,1.8,0.5))
playerpos = EntityPosition(player)
PositionEntity(player_body,playerpos)
EntityParent(player_body,player)

'Setup the camera pivot
Global campiv:TPivot = CreatePivot()
playerpos.Y = playerpos.Y + 0.80
PositionEntity(campiv,playerpos)
'--------------------------------------------------------------------------------

       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)

RotateEntity(fw.Main.camera,camrotation)
PositionEntity(fw.Main.camera,playerpos)
MoveEntity(fw.Main.camera, Vec3(0,0.5,-3))
'--------------------------------------------------------------------------------

       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

 

 

 

The above video is a screen capture of a small app that used together the following:

 

Simple Scene Loader

Basic Gamepad Control

Basic 3rd Person 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

This is something i have tried long time ago without great succes. Thank you so much. :)

 

[Edit]: Where can i get this Include from: "lua-gluefunctions.bmx" ? Thank`s

[Edit]: Aah, found it, sorry. :)

Athlon Phenom 2 X4 965 BE / Windows 7 64bit SP1 / 8G Ram / GForce GTX 460

Link to comment
Share on other sites

Thanks Marley. This is the sort of stuff thats really a big help.

 

 

No problems cassius :) glad it might be of use. Just about to update it... shortly ... well .. in a while :angry:

 

 

This is something i have tried long time ago without great succes. Thank you so much. ;)

 

[Edit]: Where can i get this Include from: "lua-gluefunctions.bmx" ? Thank`s

[Edit]: Aah, found it, sorry. ;)

 

 

No probs :)

 

If anyone else has trouble finding the "Lua-gluefunctions.bmx" the code to generate one is Here.

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

  • 2 weeks later...

When you say "I have the deserthighway map tested" do you mean it works or not and was it tested using the code above?

 

 

Also check your road_node.lua script has this at line 13

 

class.roadoffset=0.055

 

If it does try increasing this to:

 

class.roadoffset=0.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

I think its now changed Mack, to 0.055 as I have not adjusted mine since the fresh install.

 

 

 

 

I have tested that 0.05 is not enough, but 0.055 is enough. 0.1 is way too much and makes the road levitate at 10cm height.

 

 

 

oddly just checked and seems fine at 0.1 on the deserthighway map .. but then the rumour is you exaggerate in matters of length .. :lol::o

 

seriously though looks fine to me. B)

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

hmmm... well i literally had just updated before i posted that and 0.005 was the value that was written in the lua script. And 0.05 worked fine for me using the above script and the desert highway map... but perhaps its something that will need to be tested on various systems or maps to confirm... dunno

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Well I don't remember altering it as I have done no road work :lol: but then I don't remember lots of things B) but thats my age .. :o

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 I don't remember altering it as I have done no road work B) but then I don't remember lots of things :o but thats my age .. :P

 

well, we found the same issue about a month ago if i remember and we talked about this in a PM... i assume you changed it then :lol:

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

well, we found the same issue about a month ago if i remember and we talked about this in a PM... i assume you changed it then :lol:

 

 

Yeah then, but since have dont a full HDD wipe and reinstall.

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

i can only assume that you are scripting in your sleep now... :lol:

 

 

 

hmm possibly but considering I dont DO scripting when awake ... maybe it was one of the other "me's" ? B)

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

No problems, glad its all working for you now :lol:

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...