SyntaxBomb - Indie Coders

Languages & Coding => AGK => Topic started by: Rick Nasher on September 24, 2017, 07:26:37 PM

Title: Universal 1st/3rd pers. AGK Framework( - physics) WIP
Post by: Rick Nasher on September 24, 2017, 07:26:37 PM
Decided to give this little fellow his's own thread..


ORIGINAL POST
(Initial release and comments in this thread, left in for reference )

Hmm, 'fixed' the bug were player can climb straight high walls by moving forward and continuously pushing forward, not enirely happy with all the results yet, but.. it works.
(http://i67.tinypic.com/27xm3nq.jpg)

Code: [Select]
// Project: Universal 1st/3rd person framework.
// Created: 2017-09-17
// Objective:  flexible controller for 3d games without physics.
// Features:
// -switch between 1st / 3rd person cam
// -player to obstacles collisions
// -plater to ground(either plane, other objects or terrain)
// -jumping

//  Thanks to:
//  -Janbo for initial ObstacleAvoidingCam routine.
// -Sphinx  for fixing cam turnbug using A and D keys.
//
// History/To do:
// Bug: Jumping +forward made player sliding upwards to the obstacle as if climing.
// idea: if too close to a wall then unable to jump(use raycast distance)
// conclusion: no need, was fixed by placing jumping routine above movement
// Next:
// ladder.
// terrain.
// jumping pods (if collided with then jumpheight =2x)
// moving platforms (if going up/down and player on top then incr/decr y of player too)
// shooting
// NPC
// Peer2Peer

// Setup..
WindowAndDisplaySetup()


// Initialization..
AssignKeys()

#constant version#=4.4
#constant MaxCameraDistance#= 7.0
Global NewCameraDistance
NewCameraDistance#=MaxCameraDistance#
Global UserCameraDistance#
UserCameraDistance#=MaxCameraDistance#
Global CameraDistance#

Global CameraAngleX#,CameraAngleY#
Global GetPointerMoveX#, GetPointerMoveY#
Global adjustfactor#=0
Global FrameTime#
Global PointerX#, PointerZ#

Global mouselocked=0
Global cammode=0
Global endgame=0
Global infodisplay=1
Global helpdisplay=0

Global playerheight#=2
Global playerwidth#=1

Global hspeed#= 2
Global vspeed#=.5
Global speed#=2
Global gravity#=0.4
Global jump=0
Global upy#=0
Global maxjump#=5
Global falling=0
Global climbing=0
Global hitobjectatx, hitobjectaty, hitobjectatz

Global PlayerObjectID, gunID, unaBrow, nose, tail

Global PlayerX#,PlayerY#,PlayerZ#
Global oldPlayerX#,oldPlayerY#,oldPlayerZ#
Global newPlayerX#,newPlayerY#,newPlayerZ#
Global newestPlayerX#, newestPlayerY#, newestPlayerZ#


CreateWorld()

CreatePlayer()


// main loop..
do

FrameTime#=GetFrameTime()

UpdatePlayer()

CheckAdditiionalKeys()
DisplayInfo()
DisplayHelp()
If  endgame=1 then exit
sync()

loop
end // exit  game..

//  Functions..
function CurveValue(Destination#,Current#,Steps#)
Current#=Current#+((Destination#-Current#)/Steps#)
endfunction Current#


Function CreateWorld()

// create a plane, turn its collision off, rotate it and position it under the middle box to act as a ground
// this is purely cosmetic
Global planeID
planeID=CreateObjectPlane(1000,1000)
SetObjectCollisionMode(planeID,0) // this is to stop it interfering with the collision with the map
// ensure everything is at correct starting point an orientation at creation.
SetObjectPosition(planeID,0,0,0) : SetObjectRotation(planeID,0,0,0)
// put where we want it..
SetObjectRotation(planeID,90,0,0) // put it flat
SetObjectPosition(planeID,0,0,0) //realign with origin
SetObjectColor(planeID,50,200,100,255) // color it lawn style

Global centerpoleID // mark center of our world..
centerpoleID=CreateObjectCylinder(6,.2,12)
SetObjectPosition(centerpoleID,0,3,0) :  SetObjectRotation(centerpoleID,0,0,0) // ensure is at correct starting point.
SetObjectColor( centerpoleID ,0,0,0,255)
SetObjectCastShadow(centerpoleID,1)

// Create some random static scenery objects to test with..
Global Dim obstacle[20]
For i=2 To 20
r=Random(1,4)
if r=1
obstacle[i]=CreateObjectBox( random(1,20), random(1,20) , random(1,20) )
SetObjectPosition(obstacle[i],0,0,0) :  SetObjectRotation(obstacle[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition(  obstacle[i], Random(-50,50),0,Random(-50,50))
SetObjectRotation (obstacle[i],0.0,Random(0,360),0.0)
elseif r=2
obstacle[i]=CreateObjectCone(random(1,20),random(25,50),random(1,30))
SetObjectPosition(obstacle[i],0,0,0) :  SetObjectRotation(obstacle[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition(  obstacle[i], Random(-50,50),0,Random(-50,50))
SetObjectRotation (obstacle[i],0.0,Random(0,360),0.0)
elseif r=3
obstacle[i]=CreateObjectCylinder(random(1,7),random(1,15),random(1,30))
SetObjectPosition(obstacle[i],0,0,0) :  SetObjectRotation(obstacle[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition( obstacle[i], Random(-50,50),0,Random(-50,50))
SetObjectRotation (obstacle[i],Random(0,360),Random(0,360),0.0)
//SetObjectScale (obstacle[i],-Random(.2,1),-Random(.2,1),-Random(.2,1))

else
//( diameter, rows, columns )
diameter#= random(.5,25)
rows#=random(.1,25)
colums#=random(5,32)
obstacle[i]=CreateObjectsphere(diameter#,rows# ,colums# )
SetObjectPosition(obstacle[i],0,0,0) :  SetObjectRotation(obstacle[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition(  obstacle[i], Random(-50,50),-diameter#/5+random(0,1),Random(-50,50))
// SetObjectScale (obstacle[i],Random(.2,1),Random(.2,1),Random(.2,1))
SetObjectRotation (obstacle[i],0.0,Random(0,360),0.0)
endif

//SetObjectScale (obstacle[i],Random(.2,2),Random(.2,2),Random(.2,2))
SetObjectRotation (obstacle[i],0.0,Random(0,360),0.0)
SetObjectColor (obstacle[i],Random(0,255),Random(0,255),Random(0,255),Random(0,255))
SetObjectCollisionMode(obstacle[i],1)
SetObjectCastShadow(obstacle[i],1)

Next


// create building with ladder..
building=CreateObjectBox( 20,1 ,10 )
SetObjectPosition(building,0,0,0) :  SetObjectRotation(building,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  building, -10,5,-10+70)
SetObjectColor (building,200,200,200,255)
SetObjectCastShadow(building,1)

bx#=GetObjectX(building)
by#=GetObjectY(building)-15
bz#=GetObjectZ(building)

leftwall=CreateObjectBox( 1, 5 ,10 )
SetObjectPosition(leftwall,0,0,0) :  SetObjectRotation(leftwall,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  leftwall, -19.5,2.5,-10+70)
SetObjectColor (leftwall,200,200,200,255)
SetObjectCastShadow(leftwall,1)

leftwall1=CreateObjectBox( 1, 19,10 )
SetObjectPosition(leftwall1,0,0,0) :  SetObjectRotation(leftwall1,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  leftwall1, -19.5,15,-10+70)
SetObjectColor (leftwall1,200,200,200,255)
SetObjectCastShadow(leftwall1,1)

floor1=CreateObjectBox( 20,1 ,10 )
SetObjectPosition(floor1,0,0,0) :  SetObjectRotation(floor1,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  floor1, -10,11,-10+70)
SetObjectColor (floor1,200,200,200,255)
SetObjectCastShadow(floor1,1)

floor2=CreateObjectBox( 20,1 ,10 )
SetObjectPosition(floor2,0,0,0) :  SetObjectRotation(floor2,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  floor2, -10,17,-10+70)
SetObjectColor (floor2,200,200,200,255)
SetObjectCastShadow(floor2,1)

floor3=CreateObjectBox( 20,1 ,10 )
SetObjectPosition(floor3,0,0,0) :  SetObjectRotation(floor3,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  floor3, -10,24,-10+70)
SetObjectColor (floor3,200,200,200,255)
SetObjectCastShadow(floor3,1)

rightwall=CreateObjectBox( 1, 20 ,10 )
SetObjectPosition(rightwall,0,0,0) :  SetObjectRotation(rightwall,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  rightwall, -.5,10,-10+70)
SetObjectColor (rightwall,200,200,200,255)
SetObjectCastShadow(rightwall,1)

midwall=CreateObjectBox( 1, 5 ,10 )
SetObjectPosition(midwall,0,0,0) :  SetObjectRotation(midwall,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  midwall, -10,2.5,-10+70)
SetObjectColor (midwall,200,200,200,255)
SetObjectCastShadow(midwall,1)

midwall2=CreateObjectBox( 1, 5 ,10 )
SetObjectPosition(midwall2,0,0,0) :  SetObjectRotation(midwall,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  midwall2, -10,14,-10+70)
SetObjectColor (midwall2,200,200,200,255)
SetObjectCastShadow(midwall2,1)

midwall3=CreateObjectBox( 1, 5 ,10 )
SetObjectPosition(midwall3,0,0,0) :  SetObjectRotation(midwall3,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  midwall3, -7,20,-10+70)
SetObjectColor (midwall3,200,200,200,255)
SetObjectCastShadow(midwall3,1)

window=CreateObjectBox( 8.5, 5 ,.5 )
SetObjectPosition(window,0,0,0) :  SetObjectRotation(window,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  window, -5.25,2.5,-14.5+70)
SetObjectColor (window,50,50,255,100)
SetObjectCastShadow(window,1)
SetObjectTransparency(window,1)

window2=CreateObjectBox( 8.5, 5 ,.5 )
SetObjectPosition(window2,0,0,0) :  SetObjectRotation(window2,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  window2, -14.75,14,-14.5+70)
SetObjectColor (window2,50,50,255,100)
SetObjectCastShadow(window2,1)
SetObjectTransparency(window2,1)


//ladder..
Global Dim spurt[19]
For i=0 To 17

spurt[i]=CreateObjectBox( .4,0.1, 1.5)
SetObjectPosition(spurt[i],0,0,0) :  SetObjectRotation(spurt[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition(  spurt[i],bx#-10.5,(by#+10.5)+i*1.4, bz#)

SetObjectColor (spurt[i],255,255,150,255)
SetObjectCollisionMode(spurt[i],1)
SetObjectCastShadow(spurt[i],1)

next i

//bars..
leftbar=CreateObjectBox( .6, 51 ,.2 )
SetObjectPosition(leftbar,0,0,0) :  SetObjectRotation(leftbar,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  leftbar, -20.4,0,-10.8+70)
SetObjectColor (leftbar,255,255,150,255)
SetObjectCollisionMode(leftbar,1)
SetObjectCastShadow(leftbar,1)

rightbar=CreateObjectBox( .6, 51 ,.2 )
SetObjectPosition(rightbar,0,0,0) :  SetObjectRotation(rightbar,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  rightbar, -20.4,0,-9.2+70)
SetObjectColor (rightbar,255,255,150,255)
SetObjectCollisionMode(rightbar,1)
SetObjectCastShadow(rightbar,1)
       



EndFunction

Function CreatePlayer()

//Global PlayerObjectID
PlayerObjectID=CreateObjectCapsule(playerwidth#,playerheight#,1) // ( diameter, height, axis )
SetObjectPosition(PlayerObjectID,0,1,-10)
SetObjectCastShadow(PlayerObjectID,1)
SetObjectCollisionMode(PlayerObjectID,0)  //prevent self hiting

// add some detail so orientation of player is more clear..
gunID= CreateObjectCylinder(1.2,.2,10)
SetObjectPosition(gunID,0,0,0) :  SetObjectRotation(gunID,0,0,0) // ensure is at correct starting point.
SetObjectPosition(gunID,.5,0,.4)
SetObjectRotation(gunID,0,90,90)
FixObjectToObject(gunID,PlayerObjectID)
SetObjectColor(gunID,0,0,0,255) //
SetObjectCollisionMode(gunID,0)  //prevent self hiting
SetObjectCastShadow(gunID,1)

unaBrow = CreateObjectCone(.4,.8,12):SetObjectColor( unaBrow ,0,0,0,255)
SetObjectPosition(unaBrow,0,0,0) :  SetObjectRotation(unaBrow,0,0,0) // ensure is at correct starting point.
SetObjectPosition( unaBrow ,0,.4,.3)
SetObjectRotation( unaBrow ,-180,0,0)
SetObjectCastShadow(unaBrow,1)
SetObjectCollisionMode(unaBrow,0)  //prevent self hiting
FixObjectToObject(unaBrow,PlayerObjectID)

nose = CreateObjectSphere(.2,1.2,12):SetObjectColor( nose,255,0,0,255)
SetObjectPosition(nose,0,0,0) :  SetObjectRotation(nose,0,0,0) // ensure is at correct starting point.
SetObjectPosition( nose,0,.2,.5)
SetObjectCastShadow(nose,1)
SetObjectCollisionMode(nose,0)  //prevent self hiting
FixObjectToObject(nose,PlayerObjectID)

tail = CreateObjectcone(.2,.3,12):SetObjectColor( tail,255,255,255,255)
SetObjectPosition(tail,0,0,0) :  SetObjectRotation(tail,0,0,0) // ensure is at correct starting point.
SetObjectPosition( tail,0,-.9,-.4)
SetObjectRotation(tail,-130,0,0)
SetObjectCastShadow(tail,1)
SetObjectCollisionMode(tail,0)  //prevent self hiting
FixObjectToObject(tail,PlayerObjectID)

EndFunction


Function UpdatePlayer()

//store players x,y,z and angles before any movement..
oldPlayerX#=GetObjectX(PlayerObjectID)
oldPlayerY#=GetObjectY(PlayerObjectID)
oldPlayerZ#=GetObjectZ(PlayerObjectID)

If  GetRawKeyState(KEY_SHIFT)  // Shift = speedup
speed#=2
else
speed#=1
Endif

//object_hit_infront=ObjectRayCast(0,oldPlayerX#,oldPlayerY#,oldPlayerZ#,oldPlayerX#,oldPlayerY#,oldPlayerZ#+5)
//If object_hit_infront<> 0 // we've hit something then adjust the x,y,z's ..
//zdist#=GetObjectRayCastDistance( 0 )
//endif

If  GetRawKeyState(KEY_SPACE)  and falling=0  // Space = jump
If  jump=0  //  inair=0 // if not juming/inair  already..
jump=1  // intitiate new jump
Endif
Endif
if jump=1 //and climbing=0 // if jump has been initiated ..
upy#=upy#+1 // increase y
if  upy#>=maxjump# // if maxheight reached then  reset y to 0 and no end jump..
upy#=0
jump=0
else
MoveObjectLocalY(PlayerObjectID,1)
endif
endif

// get input from mouse pointer..
PointerX#=GetPointerX()
PointerY#=GetPointerY()

If mouseLocked=0
setrawmouseposition(GetVirtualWidth()*0.5,GetVirtualHeight()*0.5) // recenter mouseon screen
EndIf

GetPointerMoveX#=(PointerX#-GetPointerX()) // calculate distance moved
GetPointerMoveY#=(PointerY#-GetPointerY())

// for turning left/right..
If  GetRawKeyState(KEY_LEFT)  OR GetRawKeyState(KEY_A) // Left/A = turn player left
GetPointerMoveX# = 40 * -hspeed#
Endif
If GetRawKeyState(KEY_RIGHT) OR GetRawKeyState(KEY_D) // Right/D = turn player right
GetPointerMoveX# = 40 * hspeed#
Endif

CameraAngleX#=CameraAngleX#+GetPointerMoveY#*FrameTime#
CameraAngleY#=CameraAngleY#+GetPointerMoveX#*FrameTime# // calc camera angle
UserCameraDistance#=UserCameraDistance#-GetRawMouseWheelDelta()*0.1  // zoom in/out when used mousewheel
if UserCameraDistance#>MaxCameraDistance# then UserCameraDistance#=MaxCameraDistance# //limit max dist from cam
if UserCameraDistance#<MaxCameraDistance#*0.5 then UserCameraDistance#=MaxCameraDistance#*0.5 // limit minimum dist from cam


// get player virtual joystick input..
joystick_x# = GetJoyStickX()*hspeed#
joystick_y# = GetJoyStickY()*-vspeed#

// get keybpard input (PC only)..
// for moving forward/backward..
If GetRawKeyState(KEY_UP) = 1  or GetRawMouseRightState() // Up/W/RBM = move player forward
joystick_y#=1*vspeed#  *speed# //addjust z
endif
If   GetRawKeyState(KEY_DOWN) = 1 // Down/S = move player backward
joystick_y#=1*-vspeed# *speed#
Endif

// move player based on the input  of  joystick and  mouse..
RotateObjectLocalY(PlayerObjectID,joystick_x#) // seems redundant,but somehow makes cam movement more fluid?
MoveObjectLocalZ(PlayerObjectID,joystick_y#)
SetObjectRotation(PlayerObjectID,0,CameraAngleY#,0) // set player at  Y angle calculated according to mousemovement, don't move X angle for player will then tilt up/down


// for strafe.. ( if not put here then doesn''t work )
If GetRawKeyState(KEY_Q) // Q = move (strafe) player left
joystick_y# = .1*-hspeed#
MoveObjectLocalX(PlayerObjectID,joystick_y#)
Endif
If GetRawKeyState(KEY_E) // E = move (strafe) player right
joystick_y# = .1*hspeed#
MoveObjectLocalX(PlayerObjectID,joystick_y#)
Endif


// apply gravity..
MoveObjectLocalY(PlayerObjectID,-gravity#) // gravity ""always on''..
falling=1


// ################### manage collision checking for the player  #######################
// get players new x,y,z's for usage with collisions..
newPlayerX#=GetObjectX(PlayerObjectID)
newPlayerY#=GetObjectY(PlayerObjectID)
newPlayerZ#=GetObjectZ(PlayerObjectID)

// sphere cast between the old and new positions of the player to see if we hit something while moving to new location..
object_hit = ObjectSphereSlide(0,oldPlayerX#,oldPlayerY#,oldPlayerZ#,newPlayerX#,newPlayerY#,newPlayerZ#,playerwidth#)
// if the sphere has collided with an object then calculate sphere new position to give sliding collision
If object_hit <> 0 // we've hit something then adjust the x,y,z's ..
newestPlayerX#=GetObjectRayCastSlideX(0)
if newestPlayerX#<>newPlayerX#
hitobjectatx=1
endif
newestPlayerY#=GetObjectRayCastSlideY(0)
if newestPlayerY#<>newPlayerY#
hitobjectaty=1
falling=0
endif
newestPlayerZ#=GetObjectRayCastSlideZ(0)
if newestPlayerZ#<>newPlayerZ#
hitobjectatz=1
endif
climbing=0
if (newestPlayerZ#<>newPlayerZ#  or newestPlayerX#<>newPlayerX#) and newestPlayerY#>newPlayerY# then climbing=1

else
climbing=0
newestPlayerX#=newPlayerX#
newestPlayerY#=newPlayerY#
newestPlayerZ#=newPlayerZ#
EndIf

// prevent falling through floor due to gravity update..
If newestPlayerY# <=playerheight#/2 //1 // so if gravity aplied but now ending up below the btm floor..
newestPlayerY#=playerheight#/2 //1  // limit/reset y to minimm y so don't fall through floor
falling=0
endif

// posiition onto new location
SetObjectPosition(PlayerObjectID, newestPlayerX#, newestPlayerY#, newestPlayerZ# ) //process all modifications made above.






// #################### manage camera avoiding geometry inbetween player and cam #########
// get players new x,y,z's for usage with cam..
PlayerX#=GetObjectX(PlayerObjectID)
PlayerY#=GetObjectY(PlayerObjectID)
PlayerZ#=GetObjectZ(PlayerObjectID)

If cammode=0 //  3rd person mode(default)..
SetCameraPosition(1,PlayerX#,PlayerY#,PlayerZ#)   // place camera at player position
//SetCameraRotation(1,GetObjectAngleX(PlayerObjectID), GetObjectAngleY(PlayerObjectID) ,GetObjectAngleZ(PlayerObjectID)   ) //

// limit cam x angle otherwise may tiltl too far..
If CameraAngleX#<0
adjustfactor#=CameraAngleX#/5+.3
//CameraAngleX#=0
if CameraAngleX#<= -20
CameraAngleX#=-20
endif
//adjustfactor#=CameraAngleX#/4

else
adjustfactor#=0
endif
If CameraAngleX#>90 then CameraAngleX#=90

SetCameraRotation(1,CameraAngleX#,CameraAngleY#,0) // set camera at angle calculated according to mousemovent
MoveCameraLocalZ(1,-MaxCameraDistance#) // move cam behind player

// obstacle avoiding cam..
RayObjectID=ObjectRayCast(0,PlayerX#,PlayerY#,PlayerZ#,GetCameraX(1),GetCameraY(1),GetCameraZ(1)) // sent a ray from players pos to cam behind player.
if RayObjectID<>0 // if an object was hit, this means there's an object between player and cam, obstructing the view'
NewCameraDistance#=GetObjectRayCastDistance(0) // set distance to where has been hit.
else
NewCameraDistance#=UserCameraDistance# // nothing's wrong's so set to user defined zoom distance.
endif
CameraDistance#=CurveValue(NewCameraDistance#,CameraDistance#,10) // calc new camdistance
SetCameraPosition(1,PlayerX#,PlayerY#,PlayerZ#) // redundant?
MoveCameraLocalZ(1,-CameraDistance#) // move cam to new position behind the player.
MoveCameraLocaly(1,-adjustfactor#) // move cam to new position behind the player.

ElseIf cammode =1 // 1st person mode..
SetCameraPosition(1,PlayerX#,PlayerY#,PlayerZ#-1)   // place camera at player position
SetCameraRotation(1,CameraAngleX#,CameraAngleY#,0) // set camera at angle calculated according to mousemovent

///SetObjectVisible(PlayerObjectID,0)
Elseif cammode =2

Endif
EndFunction

Function WindowAndDisplaySetup()

// ------------not really needed for this example -------
// set window properties
SetWindowTitle("Universal 1st/3rd Person Framework V"+str(version#,1) )


// set display properties
//SetWindowSize(1920,1080,0)
SetWindowSize(1024,600,0)
SetWindowAllowResize(1) // allow the user to resize the window

//SetVirtualResolution(1920,1080) // doesn't have to match the window
setvirtualresolution(1024,600)
SetOrientationAllowed(1,1,1,1) // allow both portrait and landscape on mobile devices
SetSyncRate(30,0) // 30fps instead of 60 to save battery
SetScissor(0,0,0,0) // use the maximum available screen space, no black borders
UseNewDefaultFonts(1) // since version 2.0.22 we can use nicer default fonts
SetPrintSize( 20 )
SetPrintColor( 00, 00, 00,255 )

SetClearColor(1,128,198)
SetGlobal3DDepth(10000) // Sets the position of all 3D objects relative to 2D objects.

SetResolutionMode(1)
SetAntialiasMode(1)
SetImmersiveMode(1)
SetRawMouseVisible(0)
SetCameraRange(1,1,1000)
SetAmbientColor(128,128,128)

SetGenerateMipmaps(1)
// -----------------------------------------------------------

fog=1
// add some atmospheric fog
SetFogMode( fog )
SetFogColor( 161,183,209 )
SetFogRange( 50, 700 )
//SetFogRange( 60,95 )
SetFogSunColor( 255,230,179 )

// -----------------------------------------------------------
SetShadowMappingMode(3)
SetShadowSmoothing(1)
SetShadowMapSize(2048,2024)

EndFunction

Function CheckAdditiionalKeys()

// check additional keys..

remstart
if  GetRawKeyState(KEY_SPACE) = 1 //Space(jump)
initJump(grav decrease for while, jump_time)
endif

if GetRawKeyState(KEY_Alt = 1 //C(crouch)
crouchPlayer = 1
endif

if GetRawKeyState(KEY_CONTROL) = 1 //Ctrl/LMB
if item=weapon
launchProjectile
else
useCurrentItem
endif
endif
remend


If GetRawKeyState(KEY_F) = 1 // F= toggle focus (lock mouse to screen).
mouseLocked=1-mouseLocked
SetRawMouseVisible (mouseLocked)
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

Endif

If  GetRawKeyState(KEY_F1) = 1
helpdisplay=1-helpdisplay // F1= help
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

EndIf
If  GetRawKeyState(KEY_F2) = 1
infodisplay=1-infodisplay // F2= info
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

EndIf

If  GetRawKeyState(KEY_F3) = 1
cammode=cammode+1
if cammode=2 then MoveCameraLocalZ(1,-10) // move cam to new position behind the player.
if cammode=2 then MoveCameraLocalY(1,3) // move cam to new position behind the player.

if cammode=3 then cammode=0 // F3= toggle (1st/3rd person)
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

EndIf

If  GetRawKeyState(KEY_F4) = 1
cammode=1-cammode // F3= toggle (1st/3rd person)
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

EndIf




remstart
If GetRawKeyState(KEY_I) = 1 then inventoryMode=1-inventoryMode //toggle inventory/zoom
If Tab/MMBwheel and inventoryMode=True then select weapon/item+ or - 
If Tab/MMBwheel and inventoryMode=False then zoom+ or -

If Enter/MMB and mulitPlayer then chat=1-chat
If M(map) then mapDisplay=1-mapDisplay
If L(light) then torchOn=-torchOn

If P/Pause then pauseGame=1-pauseGame
If F1(help) then helpDisplay=1-helpDisplay

If F4(fog)
If F5
If F5 then audioOn=1-audioOn

If F6
gfxMode=gfxMode+1
if gfxMode=gfxMax
gfxMode=gfxModeMin(PC only)
endif
endif
endif
remend

If GetRawKeyPressed(KEY_ESC) then endgame=1 // Esc = exit(windows only)

EndFunction

Function DisplayInfo()
If infodisplay
// print info on screen..

Print ("FPS: " + str(  ScreenFPS() ))
Print ("FrameTime: " + str(  GetFrameTime() ))
Print ("Seconds: " + str( GetSeconds() ))
Print ("Polygons: " + str(   GetPolygonsDrawn ()  ))
Print("CameraAngleX: "+ str(CameraAngleX#))
if cammode=0 then camdis$="3rd person(default)"
if cammode=1 then camdis$="1st person"
if cammode=2 then camdis$="detached"
Print("Cammode: "+ camdis$)
Print("")
Print ("F1 = Help")

EndIf


EndFunction

Function DisplayHelp()
If helpdisplay
// print info on screen..
Print ("F2 = toggle tech info")
Print ("F3 = toggle 1st/3rd person mode")
Print ("F4 = toggle fly/walk mode")
Print ("F5 = toggle audio on/off")
Print ("F6 = toggle fog on/off")
Print ("F7 = toggle gfxmode")
Print ("F8 = toggle sun on/off")
Print("")
Print ("W, A, S, D, RMB = move")
Print ("Q, E =  strafe")
Print ("Mouse to look round")
Print ("Mousewheel = zoom in/out")
Print ("Shift  + move = run")
Print ("Space =  jump, Alt = crouch")
Print ("-Not implemented yet-")
Print ("Ctrl / LMB = fire/use item")
Print ("Tab / i = cycle inventory items")
Print ("T =  torch, M = map, C = compass ")
Print ("")
Print ("F = toggle Mouse lock")
Print ("Esc = exit, P = pause" )

EndIf


EndFunction

Function AssignKeys()
   
#constant KEY_BACK    8
#constant KEY_TAB    9

#constant KEY_ENTER 13
#constant KEY_SHIFT 16
#constant KEY_CONTROL 17
#constant KEY_ALT 18 // added
#constant KEY_ESC 27

#constant KEY_SPACE 32
#constant KEY_PAGEUP 33
#constant KEY_PAGEDOWN 34
#constant KEY_END 35
#constant KEY_HOME 36
#constant KEY_LEFT 37
#constant KEY_UP 38
#constant KEY_RIGHT 39
#constant KEY_DOWN 40

#constant KEY_INSERT 45
#constant KEY_DELETE 46

#constant KEY_0 48
#constant KEY_1 49
#constant KEY_2 50
#constant KEY_3 51
#constant KEY_4 52
#constant KEY_5 53
#constant KEY_6 54
#constant KEY_7 55
#constant KEY_8 56
#constant KEY_9 57

#constant KEY_A 65
#constant KEY_B 66
#constant KEY_C 67
#constant KEY_D 68
#constant KEY_E 69
#constant KEY_F 70
#constant KEY_G 71
#constant KEY_H 72
#constant KEY_I 73
#constant KEY_J 74
#constant KEY_K 75
#constant KEY_L 76
#constant KEY_M 77
#constant KEY_N 78
#constant KEY_O 79
#constant KEY_P 80
#constant KEY_Q 81
#constant KEY_R 82
#constant KEY_S 83
#constant KEY_T 84
#constant KEY_U 85
#constant KEY_V 86
#constant KEY_W 87
#constant KEY_X 88
#constant KEY_Y 89
#constant KEY_Z 90

#constant KEY_F1 112
#constant KEY_F2 113
#constant KEY_F3 114
#constant KEY_F4 115
#constant KEY_F5 116
#constant KEY_F6 117
#constant KEY_F7 118
#constant KEY_F8 119


#constant KEY_SEMICOL 186   
#constant KEY_EQUALS 187
#constant KEY_COMMA 188
#constant KEY_MINUS 189
#constant KEY_POINT 190
#constant KEY_SLASH 191
#constant KEY_SINGLQUOTE 192

#constant KEY_SQRBRLEFT 219
#constant KEY_BACKSLASH 220
#constant KEY_SQRBRRIGHT 221
#constant KEY_HASH 222
#constant KEY_ACCENT 223 // ' << is called ?

EndFunction





**********************************************
******************* UPDATES *******************
**********************************************


* GENERAL INFO *

(http://i64.tinypic.com/2u4rq5t.jpg)

Objective:  flexible controller for 3d games without physics.
Features:
-switch between 1st / 3rd person cam
-player to obstacles collisions
-player to ground(either plane, other objects or terrain)
-jumping
-networking
-etc, etc ..


Thanks to:
-TGC for proving AGK
-Janbo for initial basics of the ObstacleAvoidingCam routine.
-Sphinx  for fixing cam turnbug using A and D keys.
-blendman  for moving platforms example and bonus pickup(not currently included for keeping oversight while  doing code restructuring for multiplayer - will put back later when all working as desired) and double collider suggestion(still needs implementing).
-puzzler2018  for the procedural  texture function(currently removed- might put back in later if he likes).
-The guys at SyntaxBomb(nearly forgot  :-[ )
-And  many others  of course..

ROADMAP (not necessarily in this order):
Fase1 - Cam/Player handling.
 - Add Android buttons for turning round (currently only forward/backwards and  left/right strafe)
 - CarCam mode ?
 - Put back other routines I took out previously.

Fase2 -  Collectables/ Fire mechanisms.
 - Create  bullets collision detection.
 - Scorch marks for bullet impact.
 - Create item mngr a la jeppe's
 - Ammo boxes/ bullet system/inventory/scorches/bullet holes, grenades righthand?
 - Target image? /zoom mode?
 - Labels /energy levels above players. (decreasing health by movements, jumping costing more..

Fase3 - Environments.
 - Terrain.
 - Teleports/spawn points, moving platforms(removed for overhaul)
 - Clouds, sun, rain, snow?
 - Foliage?

Fase4 - Enemies/bots.
 - NPC(follower/clingers) A*, AI
 - Circeling birds?

Fase5 - Networking.
 x Universal Networking Front End interface/framework (separate from this release, still in alpha stage- looks nice though ;-) )
 - Peer2Peer (networking stack, msgs)
 - Hosting/matchmaking Server?
(https://i.imgur.com/tI25G6Y.jpg)
*Not currently included in the download, still in progress.

Ideas:
 - Level name : "The Green, the  Red and the Bluie"


* Latest release version will always appear here *

Current version: V6.9
http://www.mediafire.com/file/3ubdvphexdvkyx4/U3D13P_FW_V6.9.rar/file (http://www.mediafire.com/file/3ubdvphexdvkyx4/U3D13P_FW_V6.9.rar/file)

NOTES:
1) Do not use IE for download for it can't handle the nasty popups of MediaFire - I use Chrome to avoid.
2) Release is in RAR format as is too large and consists of too many separate files now to update in codebox(es) every time. Will do in the final release.
3) For changes, see history in begin of main.agc.
4) Currently not all geometry and functions included in the download to keep focus on the multiplayer part and basic functionality.

Download an earlier version including exe+source and blendman's mods here to try if you like.
http://www.mediafire.com/file/h7ka0n9nr2u2nd5/Univ_Mod.rar (http://www.mediafire.com/file/h7ka0n9nr2u2nd5/Univ_Mod.rar)


Title: Re: Universal 1st/3rd person AGK framwork(without physics)
Post by: Steve Elliott on September 24, 2017, 07:44:47 PM
Well done, but I don't know why you set the frame-rate to 30FPS.

50FPS is low enough.  You're only going to drain laptop batteries if you're running at thousands of frames per second.   :)
Title: Re: Universal 1st/3rd person AGK framwork(without physics)
Post by: sphinx on September 24, 2017, 09:00:20 PM
Great!
Keep fine tuning :)
Title: Re: Universal 1st/3rd person AGK framwork(without physics)
Post by: Rick Nasher on September 24, 2017, 09:02:56 PM
Thanks guys.

@Steve Elliott:
Good point. Is what I'd seen on the AGK default setups. Their explanation was that it would drain batteries on mobile phones, but didn't have any way to verify this to be true.

@sphinx:
I will, I will. :-)
Title: Re: Universal 1st/3rd person AGK framwork(without physics)
Post by: Qube on September 25, 2017, 12:14:26 AM
Coming along really well, Rick.

But but but your mouse look code does not work on Mac :o - Works on Windows fine though so that's a bit bizarre.
Title: Re: Universal 1st/3rd person AGK framwork(without physics)
Post by: RonTek on September 25, 2017, 12:49:32 AM
Looking good Rick. One thing I noticed is it walks instead when you hold shift.



Title: Re: Universal 1st/3rd person AGK framwork(without physics)
Post by: Rick Nasher on September 25, 2017, 10:45:03 PM
Thanks for testing guys.

@Qube:
Quote
But but but your mouse look code does not work on Mac :o - Works on Windows fine though so that's a bit bizarre.
That's rather odd. Perhaps cause I didn't use all standard virtual controls? I also noticed on Android I need to add some buttons for full control.

@RonTek:
Quote
Looking good Rick. One thing I noticed is it walks instead when you hold shift.
I just checked: indeed doesn't work when using key controls. I personally use RMB + shift and that does work, so I didn't notice before. Guess I'll need to add a separate check such as if key_up and key_shift then..
Title: Re: Universal 1st/3rd person AGK framwork(without physics)
Post by: RonTek on September 26, 2017, 08:49:13 AM
@RonTek:
Quote
Looking good Rick. One thing I noticed is it walks instead when you hold shift.
I just checked: indeed doesn't work when using key controls. I personally use RMB + shift and that does work, so I didn't notice before. Guess I'll need to add a separate check such as if key_up and key_shift then..

keep it up, you are doing great. :)
Title: Re: Universal 1st/3rd person AGK framwork(without physics)
Post by: peteswansen on November 21, 2017, 07:37:35 PM
Very useful!!!!!  Glad I decided to look into AGK, now that BRL is well.......   thanks Rick!
Title: Re: Universal 1st/3rd person AGK framwork(without physics)
Post by: Rick Nasher on November 25, 2017, 12:08:57 AM
Very useful!!!!!  Glad I decided to look into AGK, now that BRL is well.......   thanks Rick!

Your welcome. Still working on it.
I'm upscaling the sizes to be compatible with physics scale, so easier to switch when needed and checked out lights.

Will upload when done.
Title: Re: Universal 1st/3rd person AGK framwork(without physics)
Post by: blendman on January 29, 2018, 08:24:46 AM
Hi Rick

Great Example ! Thanks a lot.


I have added :
- platform
- Bonus (to get)

The code :
Code: [Select]
/* INFOS

Project: Universal 1st/3rd person framework.
Created: 2017-09-17
Objective:  flexible controller for 3d games without physics.


Features:
- switch between 1st / 3rd person cam
- player to obstacles collisions
- plater to ground(either plane, other objects or terrain)
- jumping
- platform
- Get Bonus


Thanks to:
- Janbo for initial ObstacleAvoidingCam routine.
- Sphinx  for fixing cam turnbug using A and D keys.
- Blendman (platform, bonus additions)

*/


/* To do:

Bug:
- Jumping + forward made player sliding upwards to the obstacle as if climing.

idea: if too close to a wall then unable to jump(use raycast distance)
- conclusion: no need, was fixed by placing jumping routine above movement

TODO :
- ladder.
- terrain.
- jumping pods (if collided with then jumpheight = 2x)
ok 4.5 - moving platforms (if going up/down and player on top then incr/decr y of player too)
ok 4.5 - Bonus
- shooting
- NPC
- Enemy
- Peer2Peer
*/

/* CHANGES
[29/01/2018] v4.5
// New
- Add moving platform (X move)
- Add bonus to get
- F6 : toggle fog on/off
// Changes
- Change fog colors
- MaxCameraDistance#= 7 -> 10.0
- jump : increase y by 0.5 (was 1) : we can jump higher

*/



// Setup..
#constant version# = 4.5

WindowAndDisplaySetup()

FoldStart // Type (platform, ennemies...)


type tPlayer

Bonus as integer
Life as integer

endtype

Type tPlatform

ObjId as integer
x as float
y as float
z as float
W as integer
H as integer
L as integer

// platform parameter
StuckPLayer as integer // to know if the player is stucked on platform

// to animate platform (moving)
posX as float
posY as float
posZ as float

Endtype

Type tEnemy

ObjId as integer
x as float
y as float
z as float
W as integer
H as integer
L as integer

Endtype

Type tBonus

ObjId as integer
x as float
y as float
z as float
W as integer
H as integer
L as integer

Endtype


Foldend


// Initialization..
InitGame()



// main loop..
do

FrameTime# = GetFrameTime()

UpdatePlayer()
UpdateEntities()

CheckAdditiionalKeys()

DisplayInfo()
DisplayHelp()
If  endgame=1 then exit

sync()

loop

end // exit  game..





FoldStart //  Functions..


Function InitGame()

// To init the game

AssignKeys()


FoldStart // constants & globals


// Camera

#constant MaxCameraDistance# = 10.0

Global NewCameraDistance
NewCameraDistance# = MaxCameraDistance#
Global UserCameraDistance#
UserCameraDistance# = MaxCameraDistance#
Global CameraDistance#

Global CameraAngleX#,CameraAngleY#
Global GetPointerMoveX#, GetPointerMoveY#
Global adjustfactor# = 0
Global FrameTime#
Global PointerX#, PointerZ#

// Display, help...
Global mouselocked = 0
Global cammode = 0
Global endgame = 0
Global infodisplay = 1
Global helpdisplay = 0


// player parameters
Global playerheight# = 2
Global playerwidth# = 1

Global hspeed# = 2
Global vspeed# =.5
Global speed# = 2
Global gravity#=0.4
Global jump = 0
Global upy# = 0
Global maxjump# = 5
Global falling = 0
Global climbing = 0
Global hitobjectatx, hitobjectaty, hitobjectatz

// PLayer object
Global PlayerObjectID, gunID, unaBrow, nose, tail

Global Player as tplayer
player.bonus = 0
player.Life = 100


// player Position
Global PlayerX#, PlayerY#, PlayerZ#
Global oldPlayerX#, oldPlayerY#, oldPlayerZ#
Global oldPlayerX2#, oldPlayerY2#, oldPlayerZ2# // for collision (platform..)
Global newPlayerX#, newPlayerY#, newPlayerZ#
Global newestPlayerX#, newestPlayerY#, newestPlayerZ#

// Fx
Global fog

Foldend

CreateWorld()

CreatePlayer()

CreatePlatform()




Endfunction



function CurveValue(Destination#,Current#,Steps#)
Current#=Current#+((Destination#-Current#)/Steps#)
endfunction Current#

FoldStart // create

Function CreateWorld()

// create a plane, turn its collision off, rotate it and position it under the middle box to act as a ground
// this is purely cosmetic
Global planeID
planeID = CreateObjectPlane(1000,1000)
SetObjectCollisionMode(planeID,0) // this is to stop it interfering with the collision with the map
// ensure everything is at correct starting point an orientation at creation.
SetObjectPosition(planeID,0,0,0) : SetObjectRotation(planeID,0,0,0)
// put where we want it..
SetObjectRotation(planeID,90,0,0) // put it flat
SetObjectPosition(planeID,0,0,0) //realign with origin
SetObjectColor(planeID,50,200,100,255) // color it lawn style


Global centerpoleID // mark center of our world..
centerpoleID=CreateObjectCylinder(6,.2,12)
SetObjectPosition(centerpoleID,0,3,0) :  SetObjectRotation(centerpoleID,0,0,0) // ensure is at correct starting point.
SetObjectColor( centerpoleID ,0,0,0,255)
SetObjectCastShadow(centerpoleID,1)

// Create some random static scenery objects to test with..
Global Dim obstacle[20]
For i=2 To 20
r=Random(1,4)
if r=1
obstacle[i]=CreateObjectBox( random(1,20), random(1,20) , random(1,20) )
SetObjectPosition(obstacle[i],0,0,0) :  SetObjectRotation(obstacle[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition(  obstacle[i], Random(-50,50),0,Random(-50,50))
SetObjectRotation (obstacle[i],0.0,Random(0,360),0.0)
elseif r=2
obstacle[i]=CreateObjectCone(random(1,20),random(25,50),random(1,30))
SetObjectPosition(obstacle[i],0,0,0) :  SetObjectRotation(obstacle[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition(  obstacle[i], Random(-50,50),0,Random(-50,50))
SetObjectRotation (obstacle[i],0.0,Random(0,360),0.0)
elseif r=3
obstacle[i]=CreateObjectCylinder(random(1,7),random(1,15),random(1,30))
SetObjectPosition(obstacle[i],0,0,0) :  SetObjectRotation(obstacle[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition( obstacle[i], Random(-50,50),0,Random(-50,50))
SetObjectRotation (obstacle[i],Random(0,360),Random(0,360),0.0)
//SetObjectScale (obstacle[i],-Random(.2,1),-Random(.2,1),-Random(.2,1))

else
//( diameter, rows, columns )
diameter#= random(.5,25)
rows#=random(.1,25)
colums#=random(5,32)
obstacle[i]=CreateObjectsphere(diameter#,rows# ,colums# )
SetObjectPosition(obstacle[i],0,0,0) :  SetObjectRotation(obstacle[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition(  obstacle[i], Random(-50,50),-diameter#/5+random(0,1),Random(-50,50))
// SetObjectScale (obstacle[i],Random(.2,1),Random(.2,1),Random(.2,1))
SetObjectRotation (obstacle[i],0.0,Random(0,360),0.0)
endif

//SetObjectScale (obstacle[i],Random(.2,2),Random(.2,2),Random(.2,2))
SetObjectRotation (obstacle[i],0.0,Random(0,360),0.0)
SetObjectColor (obstacle[i],Random(0,255),Random(0,255),Random(0,255),Random(0,255))
SetObjectCollisionMode(obstacle[i],1)
SetObjectCastShadow(obstacle[i],1)

Next


// create building with ladder..
building=CreateObjectBox( 20,1 ,10 )
SetObjectPosition(building,0,0,0) :  SetObjectRotation(building,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  building, -10,5,-10+70)
SetObjectColor (building,200,200,200,255)
SetObjectCastShadow(building,1)

bx#=GetObjectX(building)
by#=GetObjectY(building)-15
bz#=GetObjectZ(building)

leftwall=CreateObjectBox( 1, 5 ,10 )
SetObjectPosition(leftwall,0,0,0) :  SetObjectRotation(leftwall,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  leftwall, -19.5,2.5,-10+70)
SetObjectColor (leftwall,200,200,200,255)
SetObjectCastShadow(leftwall,1)

leftwall1=CreateObjectBox( 1, 19,10 )
SetObjectPosition(leftwall1,0,0,0) :  SetObjectRotation(leftwall1,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  leftwall1, -19.5,15,-10+70)
SetObjectColor (leftwall1,200,200,200,255)
SetObjectCastShadow(leftwall1,1)

floor1=CreateObjectBox( 20,1 ,10 )
SetObjectPosition(floor1,0,0,0) :  SetObjectRotation(floor1,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  floor1, -10,11,-10+70)
SetObjectColor (floor1,200,200,200,255)
SetObjectCastShadow(floor1,1)

floor2=CreateObjectBox( 20,1 ,10 )
SetObjectPosition(floor2,0,0,0) :  SetObjectRotation(floor2,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  floor2, -10,17,-10+70)
SetObjectColor (floor2,200,200,200,255)
SetObjectCastShadow(floor2,1)

floor3=CreateObjectBox( 20,1 ,10 )
SetObjectPosition(floor3,0,0,0) :  SetObjectRotation(floor3,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  floor3, -10,24,-10+70)
SetObjectColor (floor3,200,200,200,255)
SetObjectCastShadow(floor3,1)

rightwall=CreateObjectBox( 1, 20 ,10 )
SetObjectPosition(rightwall,0,0,0) :  SetObjectRotation(rightwall,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  rightwall, -.5,10,-10+70)
SetObjectColor (rightwall,200,200,200,255)
SetObjectCastShadow(rightwall,1)

midwall=CreateObjectBox( 1, 5 ,10 )
SetObjectPosition(midwall,0,0,0) :  SetObjectRotation(midwall,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  midwall, -10,2.5,-10+70)
SetObjectColor (midwall,200,200,200,255)
SetObjectCastShadow(midwall,1)

midwall2=CreateObjectBox( 1, 5 ,10 )
SetObjectPosition(midwall2,0,0,0) :  SetObjectRotation(midwall,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  midwall2, -10,14,-10+70)
SetObjectColor (midwall2,200,200,200,255)
SetObjectCastShadow(midwall2,1)

midwall3=CreateObjectBox( 1, 5 ,10 )
SetObjectPosition(midwall3,0,0,0) :  SetObjectRotation(midwall3,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  midwall3, -7,20,-10+70)
SetObjectColor (midwall3,200,200,200,255)
SetObjectCastShadow(midwall3,1)

window=CreateObjectBox( 8.5, 5 ,.5 )
SetObjectPosition(window,0,0,0) :  SetObjectRotation(window,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  window, -5.25,2.5,-14.5+70)
SetObjectColor (window,50,50,255,100)
SetObjectCastShadow(window,1)
SetObjectTransparency(window,1)

window2=CreateObjectBox( 8.5, 5 ,.5 )
SetObjectPosition(window2,0,0,0) :  SetObjectRotation(window2,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  window2, -14.75,14,-14.5+70)
SetObjectColor (window2,50,50,255,100)
SetObjectCastShadow(window2,1)
SetObjectTransparency(window2,1)


//ladder..
Global Dim spurt[19]
For i=0 To 17

spurt[i]=CreateObjectBox( .4,0.1, 1.5)
SetObjectPosition(spurt[i],0,0,0) :  SetObjectRotation(spurt[i],0,0,0) // ensure is at correct starting point.
SetObjectPosition(  spurt[i],bx#-10.5,(by#+10.5)+i*1.4, bz#)

SetObjectColor (spurt[i],255,255,150,255)
SetObjectCollisionMode(spurt[i],1)
SetObjectCastShadow(spurt[i],1)

next i

//bars..
leftbar=CreateObjectBox( .6, 51 ,.2 )
SetObjectPosition(leftbar,0,0,0) :  SetObjectRotation(leftbar,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  leftbar, -20.4,0,-10.8+70)
SetObjectColor (leftbar,255,255,150,255)
SetObjectCollisionMode(leftbar,1)
SetObjectCastShadow(leftbar,1)

rightbar=CreateObjectBox( .6, 51 ,.2 )
SetObjectPosition(rightbar,0,0,0) :  SetObjectRotation(rightbar,0,0,0) // ensure is at correct starting point.
SetObjectPosition(  rightbar, -20.4,0,-9.2+70)
SetObjectColor (rightbar,255,255,150,255)
SetObjectCollisionMode(rightbar,1)
SetObjectCastShadow(rightbar,1)
   



EndFunction

Function CreatePlayer()

//Global PlayerObjectID
PlayerObjectID=CreateObjectCapsule(playerwidth#,playerheight#,1) // ( diameter, height, axis )
SetObjectPosition(PlayerObjectID,0,1,-10)
SetObjectCastShadow(PlayerObjectID,1)
SetObjectCollisionMode(PlayerObjectID,0)  //prevent self hiting

// add some detail so orientation of player is more clear..
gunID= CreateObjectCylinder(1.2,.2,10)
SetObjectPosition(gunID,0,0,0) :  SetObjectRotation(gunID,0,0,0) // ensure is at correct starting point.
SetObjectPosition(gunID,.5,0,.4)
SetObjectRotation(gunID,0,90,90)
FixObjectToObject(gunID,PlayerObjectID)
SetObjectColor(gunID,0,0,0,255) //
SetObjectCollisionMode(gunID,0)  //prevent self hiting
SetObjectCastShadow(gunID,1)

unaBrow = CreateObjectCone(.4,.8,12):SetObjectColor( unaBrow ,0,0,0,255)
SetObjectPosition(unaBrow,0,0,0) :  SetObjectRotation(unaBrow,0,0,0) // ensure is at correct starting point.
SetObjectPosition( unaBrow ,0,.4,.3)
SetObjectRotation( unaBrow ,-180,0,0)
SetObjectCastShadow(unaBrow,1)
SetObjectCollisionMode(unaBrow,0)  //prevent self hiting
FixObjectToObject(unaBrow,PlayerObjectID)

nose = CreateObjectSphere(.2,1.2,12):SetObjectColor( nose,255,0,0,255)
SetObjectPosition(nose,0,0,0) :  SetObjectRotation(nose,0,0,0) // ensure is at correct starting point.
SetObjectPosition( nose,0,.2,.5)
SetObjectCastShadow(nose,1)
SetObjectCollisionMode(nose,0)  //prevent self hiting
FixObjectToObject(nose,PlayerObjectID)

tail = CreateObjectcone(.2,.3,12):SetObjectColor( tail,255,255,255,255)
SetObjectPosition(tail,0,0,0) :  SetObjectRotation(tail,0,0,0) // ensure is at correct starting point.
SetObjectPosition( tail,0,-.9,-.4)
SetObjectRotation(tail,-130,0,0)
SetObjectCastShadow(tail,1)
SetObjectCollisionMode(tail,0)  //prevent self hiting
FixObjectToObject(tail,PlayerObjectID)

EndFunction

Function CreatePlatform()


// Bonus

Global dim  Bonus[10] as tBonus
for i=0 to Bonus.length

n = CreateObjectBox(w,h,l)

// size
w = 2
h = 2
l = 2
SetObjectCollisionMode(n,1)

// position
x = random(0,50)-random(0,50)
y = 2
z = random(0,50)-random(0,50)
SetObjectPosition(n,x,y,z)
SetObjectCastShadow(n,1)
SetObjectColor(n,255,255,100,255)
Bonus[i].ObjId = n
Bonus[i].x = x
Bonus[i].y = y
Bonus[i].z = y
Bonus[i].w = w
Bonus[i].h = h
Bonus[i].l = l

next


// platforms
Global dim  Platform[3] as tPlatform
for i=0 to platform.length

// size
w = 5
h = 1
l = 5

n = CreateObjectBox(w,h,l)
SetObjectCollisionMode(n,1)

// position
x = random(0,50)-random(0,50)
y = 2
z = random(0,50)-random(0,50)
SetObjectPosition(n,x,y,z)
SetObjectCastShadow(n,1)
SetObjectColor(n,100,100,255,255)
platform[i].ObjId = n
platform[i].x = x
platform[i].y = y
platform[i].z = z
platform[i].w = w
platform[i].h = h
platform[i].l = l
platform[i].StuckPLayer = 1

next



endfunction


Foldend


FoldStart // update

Function UpdatePlayer()

//store players x,y,z and angles before any movement..
oldPlayerX# = GetObjectX(PlayerObjectID)
oldPlayerY# = GetObjectY(PlayerObjectID)
oldPlayerZ# = GetObjectZ(PlayerObjectID)

If GetRawKeyState(KEY_SHIFT)  // Shift = speedup
speed#=2
else
speed#=1
Endif

//object_hit_infront=ObjectRayCast(0,oldPlayerX#,oldPlayerY#,oldPlayerZ#,oldPlayerX#,oldPlayerY#,oldPlayerZ#+5)
//If object_hit_infront<> 0 // we've hit something then adjust the x,y,z's ..
//zdist#=GetObjectRayCastDistance( 0 )
//endif

// for platform contact
keyOn = 0


If GetRawKeyState(KEY_SPACE)  and falling=0  // Space = jump
keyOn = 1
If  jump=0  //  inair=0 // if not juming/inair  already..
jump=1  // intitiate new jump
Endif
Endif

if jump=1 //and climbing=0 // if jump has been initiated ..
upy#=upy#+0.5 // increase y
if  upy#>=maxjump# // if maxheight reached then  reset y to 0 and no end jump..
upy#=0
jump=0
else
MoveObjectLocalY(PlayerObjectID,1)
endif
endif

// get input from mouse pointer..
PointerX# = GetPointerX()
PointerY# = GetPointerY()

If mouseLocked=0
SetRawMousePosition(GetVirtualWidth()*0.5,GetVirtualHeight()*0.5) // recenter mouseon screen
EndIf

GetPointerMoveX# = (PointerX#-GetPointerX()) // calculate distance moved
GetPointerMoveY# = (PointerY#-GetPointerY())




// for turning left/right..
If  GetRawKeyState(KEY_LEFT)  OR GetRawKeyState(KEY_A) // Left/A = turn player left
keyOn = 1
GetPointerMoveX# = 40 * -hspeed#
Endif
If GetRawKeyState(KEY_RIGHT) OR GetRawKeyState(KEY_D) // Right/D = turn player right
keyOn = 1
GetPointerMoveX# = 40 * hspeed#
Endif

CameraAngleX#=CameraAngleX#+GetPointerMoveY#*FrameTime#
CameraAngleY#=CameraAngleY#+GetPointerMoveX#*FrameTime# // calc camera angle
UserCameraDistance#=UserCameraDistance#-GetRawMouseWheelDelta()*0.1  // zoom in/out when used mousewheel
if UserCameraDistance#>MaxCameraDistance# then UserCameraDistance#=MaxCameraDistance# //limit max dist from cam
if UserCameraDistance#<MaxCameraDistance#*0.5 then UserCameraDistance#=MaxCameraDistance#*0.5 // limit minimum dist from cam


// get player virtual joystick input..
joystick_x# = GetJoyStickX()* hspeed#
joystick_y# = GetJoyStickY()*-vspeed#

// get keybpard input (PC only)..
// for moving forward/backward..
If GetRawKeyState(KEY_UP) = 1  or GetRawMouseRightState() // Up/W/RBM = move player forward
keyOn = 1
joystick_y#=1*vspeed#  *speed# //addjust z
endif
If  GetRawKeyState(KEY_DOWN) = 1 // Down/S = move player backward
keyOn = 1
joystick_y#=1*-vspeed# *speed#
Endif

// move player based on the input  of  joystick and  mouse..
RotateObjectLocalY(PlayerObjectID,joystick_x#) // seems redundant,but somehow makes cam movement more fluid?
MoveObjectLocalZ(PlayerObjectID,joystick_y#)
SetObjectRotation(PlayerObjectID,0,CameraAngleY#,0) // set player at  Y angle calculated according to mousemovement, don't move X angle for player will then tilt up/down


// for strafe.. ( if not put here then doesn''t work )
If GetRawKeyState(KEY_Q) // Q = move (strafe) player left
joystick_y# = .1*-hspeed#
MoveObjectLocalX(PlayerObjectID,joystick_y#)
Endif
If GetRawKeyState(KEY_E) // E = move (strafe) player right
joystick_y# = .1*hspeed#
MoveObjectLocalX(PlayerObjectID,joystick_y#)
Endif


// apply gravity..
MoveObjectLocalY(PlayerObjectID,-gravity#) // gravity ""always on''..
falling=1


// ################### manage collision checking for the player  #######################
// get players new x,y,z's for usage with collisions..
newPlayerX# = GetObjectX(PlayerObjectID)
newPlayerY# = GetObjectY(PlayerObjectID)
newPlayerZ# = GetObjectZ(PlayerObjectID)

// sphere cast between the old and new positions of the player to see if we hit something while moving to new location..
object_hit = ObjectSphereSlide(0,oldPlayerX#,oldPlayerY#,oldPlayerZ#,newPlayerX#,newPlayerY#,newPlayerZ#,playerwidth#)
// if the sphere has collided with an object then calculate sphere new position to give sliding collision
If object_hit <> 0 // we've hit something then adjust the x,y,z's ..

newestPlayerX# = GetObjectRayCastSlideX(0)
if newestPlayerX# <> newPlayerX#
hitobjectatx=1
endif
newestPlayerY# = GetObjectRayCastSlideY(0)
if newestPlayerY# <> newPlayerY#
hitobjectaty=1
falling=0
endif
newestPlayerZ# = GetObjectRayCastSlideZ(0)
if newestPlayerZ# <> newPlayerZ#
hitobjectatz=1
endif

climbing=0
if (newestPlayerZ#<>newPlayerZ#  or newestPlayerX#<>newPlayerX#) and newestPlayerY#>newPlayerY# then climbing=1


for i=0 to Bonus.length
n = Bonus[i].ObjId
if object_hit = n
DeleteObject(n)
inc Player.Bonus
exit
endif
next


// check platform colision
for i=0 to platform.length
n = Platform[i].ObjId
if object_hit = n
// print("Hit platform !!!!!!!!!")
if keyOn = 0
newestPlayerX# = GetObjectX(n) + oldPlayerX2#
newestPlayerZ# = GetObjectZ(n) + oldPlayerZ2#
else
oldPlayerX2# =  GetObjectX(PlayerObjectID) - GetObjectX(n)
oldPlayerZ2# =  GetObjectZ(PlayerObjectID) - GetObjectZ(n)
endif
exit
endif
Next





else
climbing=0
newestPlayerX# = newPlayerX#
newestPlayerY# = newPlayerY#
newestPlayerZ# = newPlayerZ#
EndIf

// prevent falling through floor due to gravity update..
If newestPlayerY# <= playerheight#/2 //1 // so if gravity aplied but now ending up below the btm floor..
newestPlayerY# = playerheight#/2 //1  // limit/reset y to minimm y so don't fall through floor
falling = 0
endif

// posiition onto new location
SetObjectPosition(PlayerObjectID, newestPlayerX#, newestPlayerY#, newestPlayerZ# ) //process all modifications made above.






// #################### manage camera avoiding geometry inbetween player and cam #########
// get players new x,y,z's for usage with cam..
PlayerX# = GetObjectX(PlayerObjectID)
PlayerY# = GetObjectY(PlayerObjectID)
PlayerZ# = GetObjectZ(PlayerObjectID)

If cammode=0 //  3rd person mode(default)..
SetCameraPosition(1,PlayerX#,PlayerY#,PlayerZ#)   // place camera at player position
//SetCameraRotation(1,GetObjectAngleX(PlayerObjectID), GetObjectAngleY(PlayerObjectID) ,GetObjectAngleZ(PlayerObjectID)   ) //

// limit cam x angle otherwise may tiltl too far..
If CameraAngleX#<0
adjustfactor#=CameraAngleX#/5+.3
//CameraAngleX#=0
if CameraAngleX#<= -20
CameraAngleX#=-20
endif
//adjustfactor#=CameraAngleX#/4

else
adjustfactor#=0
endif
If CameraAngleX#>90 then CameraAngleX#=90

SetCameraRotation(1,CameraAngleX#,CameraAngleY#,0) // set camera at angle calculated according to mousemovent
MoveCameraLocalZ(1,-MaxCameraDistance#) // move cam behind player

// obstacle avoiding cam..
RayObjectID = ObjectRayCast(0,PlayerX#,PlayerY#,PlayerZ#,GetCameraX(1),GetCameraY(1),GetCameraZ(1)) // sent a ray from players pos to cam behind player.
if RayObjectID<>0 // if an object was hit, this means there's an object between player and cam, obstructing the view'
NewCameraDistance# = GetObjectRayCastDistance(0) // set distance to where has been hit.
else
NewCameraDistance# = UserCameraDistance# // nothing's wrong's so set to user defined zoom distance.
endif
CameraDistance# = CurveValue(NewCameraDistance#,CameraDistance#,10) // calc new camdistance
SetCameraPosition(1,PlayerX#,PlayerY#,PlayerZ#) // redundant?
MoveCameraLocalZ(1,-CameraDistance#) // move cam to new position behind the player.
MoveCameraLocaly(1,-adjustfactor#) // move cam to new position behind the player.

ElseIf cammode =1 // 1st person mode..
SetCameraPosition(1,PlayerX#,PlayerY#,PlayerZ#-1)   // place camera at player position
SetCameraRotation(1,CameraAngleX#,CameraAngleY#,0) // set camera at angle calculated according to mousemovent

///SetObjectVisible(PlayerObjectID,0)
Elseif cammode =2

Endif

EndFunction


Function UpdateEntities()


// moving platform
for i=0 to platform.length

// move platform
inc platform[i].posX
if platform[i].posX> 180
platform[i].posX =0
endif
n = Platform[i].ObjId
SetObjectPosition(n, Platform[i].x + sin(platform[i].posX)*2,Platform[i].y, Platform[i].z)

next


endFunction


Function WindowAndDisplaySetup()

// ------------not really needed for this example -------
// set window properties
SetWindowTitle("Universal 1st/3rd Person Framework V"+str(version#,1) )


// set display properties
//SetWindowSize(1920,1080,0)
SetWindowSize(1024,600,0)
SetWindowAllowResize(1) // allow the user to resize the window

//SetVirtualResolution(1920,1080) // doesn't have to match the window
setvirtualresolution(1024,600)
SetOrientationAllowed(1,1,1,1) // allow both portrait and landscape on mobile devices
SetSyncRate(30,0) // 30fps instead of 60 to save battery
SetScissor(0,0,0,0) // use the maximum available screen space, no black borders
UseNewDefaultFonts(1) // since version 2.0.22 we can use nicer default fonts
SetPrintSize( 20 )
SetPrintColor( 00, 00, 00,255 )

SetClearColor(1,128,198)
SetGlobal3DDepth(10000) // Sets the position of all 3D objects relative to 2D objects.

SetResolutionMode(1)
SetAntialiasMode(1)
SetImmersiveMode(1)
SetRawMouseVisible(0)
SetCameraRange(1,1,1000)
SetAmbientColor(128,128,128)

SetGenerateMipmaps(1)
// -----------------------------------------------------------

fog=1
// add some atmospheric fog
SetFogMode( fog )
// SetFogColor( 161,183,209 )
SetFogColor( 51,178,248 )
SetFogRange( 20, 200 )
//SetFogRange( 60,95 )
SetFogSunColor( 255,230,179 )

// -----------------------------------------------------------
SetShadowMappingMode(3)
SetShadowSmoothing(1)
SetShadowMapSize(2048,2048)

EndFunction


Foldend


// display, keys
Function CheckAdditiionalKeys()

// check additional keys..

remstart
if  GetRawKeyState(KEY_SPACE) = 1 //Space(jump)
initJump(grav decrease for while, jump_time)
endif

if GetRawKeyState(KEY_Alt = 1 //C(crouch)
crouchPlayer = 1
endif

if GetRawKeyState(KEY_CONTROL) = 1 //Ctrl/LMB
if item=weapon
launchProjectile
else
useCurrentItem
endif
endif
remend


If GetRawKeyPressed(KEY_F) = 1 // F= toggle focus (lock mouse to screen).
mouseLocked=1-mouseLocked
SetRawMouseVisible (mouseLocked)
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

Endif

If  GetRawKeyPressed(KEY_F1) = 1
helpdisplay=1-helpdisplay // F1= help
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

EndIf
If  GetRawKeyPressed(KEY_F2) = 1
infodisplay=1-infodisplay // F2= info
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

EndIf

If  GetRawKeyPressed(KEY_F3) = 1 // F3= toggle (1st/3rd person)
cammode = cammode + 1
if cammode = 2 then MoveCameraLocalZ(1,-10) // move cam to new position behind the player.
if cammode = 2 then MoveCameraLocalY(1,3) // move cam to new position behind the player.

if cammode = 3 then cammode=0 // F3= toggle (1st/3rd person)
period#=Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

EndIf


If  GetRawKeyPressed(KEY_F4) = 1
cammode = 1 - cammode // F3= toggle (1st/3rd person)
period# = Timer()+1000000
For delay#=0 to period#
Next delay# // make sure doesn't  get  pressed right after again.

EndIf

If  GetRawKeyState(KEY_F5) = 1
endif

If  GetRawKeyPressed(KEY_F6) = 1
Fog = 1 - fog
SetFogMode( fog )
endif

remstart

If GetRawKeyState(KEY_I) = 1 then inventoryMode=1-inventoryMode //toggle inventory/zoom
If Tab/MMBwheel and inventoryMode=True then select weapon/item+ or -
If Tab/MMBwheel and inventoryMode=False then zoom+ or -

If Enter/MMB and mulitPlayer then chat=1-chat
If M(map) then mapDisplay=1-mapDisplay
If L(light) then torchOn=-torchOn

If P/Pause then pauseGame=1-pauseGame
If F1(help) then helpDisplay=1-helpDisplay

If F4
If F5 (fog)
If F5 then audioOn=1-audioOn

If F6
gfxMode=gfxMode+1
if gfxMode=gfxMax
gfxMode=gfxModeMin(PC only)
endif
endif
endif

remend

If GetRawKeyPressed(KEY_ESC) then endgame=1 // Esc = exit(windows only)

EndFunction

Function DisplayInfo()

If infodisplay
// print info on screen..

Print ("Player Life " + str(player.Life)+" | Bonus : "+Str(player.Bonus))

Print ("--------------------------")
Print ("FPS: " + str(  ScreenFPS() ))
Print ("FrameTime: " + str(  GetFrameTime() ))
Print ("Seconds: " + str( GetSeconds() ))
Print ("Polygons: " + str(   GetPolygonsDrawn ()  ))
Print("CameraAngleX: "+ str(CameraAngleX#))
if cammode=0 then camdis$="3rd person(default)"
if cammode=1 then camdis$="1st person"
if cammode=2 then camdis$="detached"
Print("Cammode: "+ camdis$)
Print("")
Print ("F1 = Help")

EndIf


EndFunction

Function DisplayHelp()

If helpdisplay
// print info on screen..
Print ("F2 = toggle tech info")
Print ("F3 = toggle 1st/3rd person mode")
Print ("F4 = toggle fly/walk mode")
Print ("F5 = toggle audio on/off")
Print ("F6 = toggle fog on/off")
Print ("F7 = toggle gfxmode")
Print ("F8 = toggle sun on/off")
Print("")
Print ("W, A, S, D, RMB = move")
Print ("Q, E =  strafe")
Print ("Mouse to look round")
Print ("Mousewheel = zoom in/out")
Print ("Shift  + move = run")
Print ("Space =  jump, Alt = crouch")
Print ("-Not implemented yet-")
Print ("Ctrl / LMB = fire/use item")
Print ("Tab / i = cycle inventory items")
Print ("T =  torch, M = map, C = compass ")
Print ("")
Print ("F = toggle Mouse lock")
Print ("Esc = exit, P = pause" )

EndIf


EndFunction

Function AssignKeys()
   
#constant KEY_BACK 8
#constant KEY_TAB 9

#constant KEY_ENTER 13
#constant KEY_SHIFT 16
#constant KEY_CONTROL 17
#constant KEY_ALT 18 // added
#constant KEY_ESC 27

#constant KEY_SPACE 32
#constant KEY_PAGEUP 33
#constant KEY_PAGEDOWN 34
#constant KEY_END 35
#constant KEY_HOME 36
#constant KEY_LEFT 37
#constant KEY_UP 38
#constant KEY_RIGHT 39
#constant KEY_DOWN 40

#constant KEY_INSERT 45
#constant KEY_DELETE 46

#constant KEY_0 48
#constant KEY_1 49
#constant KEY_2 50
#constant KEY_3 51
#constant KEY_4 52
#constant KEY_5 53
#constant KEY_6 54
#constant KEY_7 55
#constant KEY_8 56
#constant KEY_9 57

#constant KEY_A 65
#constant KEY_B 66
#constant KEY_C 67
#constant KEY_D 68
#constant KEY_E 69
#constant KEY_F 70
#constant KEY_G 71
#constant KEY_H 72
#constant KEY_I 73
#constant KEY_J 74
#constant KEY_K 75
#constant KEY_L 76
#constant KEY_M 77
#constant KEY_N 78
#constant KEY_O 79
#constant KEY_P 80
#constant KEY_Q 81
#constant KEY_R 82
#constant KEY_S 83
#constant KEY_T 84
#constant KEY_U 85
#constant KEY_V 86
#constant KEY_W 87
#constant KEY_X 88
#constant KEY_Y 89
#constant KEY_Z 90

#constant KEY_F1 112
#constant KEY_F2 113
#constant KEY_F3 114
#constant KEY_F4 115
#constant KEY_F5 116
#constant KEY_F6 117
#constant KEY_F7 118
#constant KEY_F8 119


#constant KEY_SEMICOL 186   
#constant KEY_EQUALS 187
#constant KEY_COMMA 188
#constant KEY_MINUS 189
#constant KEY_POINT 190
#constant KEY_SLASH 191
#constant KEY_SINGLQUOTE 192

#constant KEY_SQRBRLEFT 219
#constant KEY_BACKSLASH 220
#constant KEY_SQRBRRIGHT 221
#constant KEY_HASH 222
#constant KEY_ACCENT 223 // ' << is called ?

EndFunction

FoldEnd

Title: Re: Universal 1st/3rd person AGK framwork(without physics)
Post by: RemiD on January 29, 2018, 05:54:28 PM
@Rick>>can you post a link to a playable demo (an executable for Windows OS) so that i can try ?
I am curious...
Thanks
Title: Re: Universal 1st/3rd person AGK framwork(without physics)
Post by: Rick Nasher on January 29, 2018, 09:02:47 PM
@Blendman
Hehehe, that's pretty cool: moving platforms demo here we come..  8)
Like those collectable cubes too.

I'm still working on it, of and on. Added stuff to try out..
So far added: an elevator, stairs, ladders, jumping pad, glass, lights + day/night switch, procedural textures, shooting, player type array preparation for multiple player objects and converted the scale to match the bullet physics scale so that it's easier to convert code later on when desired.

Not fit for publishing though, need to tidy up first, but still busy for wasn't completely satisfied with the camera handling(original works fine, but not flexible enough for it to be perfect) so decided to introduce a cam pivot, which is currently giving me bit of a headache.  ::)




@RemiD
Sorry, didn't respond to your message sooner. They literally took off half my roof here to have an "upgraded" version installed, which has given me and my gf lot's of hassle and work. While we were just finished with fixing up the place last year- thank the landlord..  >:(

I like your submission to the coding competition and should really be 'easy' to implement in AGK. Easy of course as in that it will take a little time(which I do not have, way too busy sorry to say). But AGK has a lot of similar commands as Blitz3d only named differently and not always working exactly the same of course. Lot's are almost exact copies though. E.g.  EntityInView in AGK is GetObjectInScreen.
Bare in mind that 'entities' are called 'objects'.  :P

Anyway, sure I can generate an exe for you. I myself do not usually feel confident in running other peoples exe's no matter who (bit paranoid, but better safe than sorry..  :-[) . I'd recommend any time just to download and install the AGK demo version, which is only 300MB's. But I've posted an exe+source with blendman's mods for you down here to try if you like:

http://www.mediafire.com/file/h7ka0n9nr2u2nd5/Univ_Mod.rar (http://www.mediafire.com/file/h7ka0n9nr2u2nd5/Univ_Mod.rar)


Title: Re: Universal 1st/3rd person AGK framwork(without physics)
Post by: RemiD on January 29, 2018, 11:09:14 PM
@Rick>>Thanks for the demo

It is a good start.

I have noticed something :
The gravity seems to not be and "increasing force". (it seems a "fixed force")
Even if you are not looking to use realistic physics, it is easy to add a gravity which increases (pull the player towards the ground faster and faster)
example :
gravity = gravity + 0.01 (if you want to have realistic force you need to increment/decrement it depending on the FPS)
translateentity(Player,0,-gravity,0)

Anyway, good luck for the next steps (nice shadows)
Title: Re: Universal 1st/3rd person AGK framwork(without physics)
Post by: Rick Nasher on January 30, 2018, 06:53:10 PM
@RemiD
True, gravity is very, very basic.
Wasn't ready for that, was saving it for the physics version, but will indeed modify this.
Good point- easy to implement.

Shadows are very easy to implement in AGK on any object: SetObjectCastShadow(objectname,1)
So I cannot take any coding achievement claim for that at all, hehehe.

Title: Re: Universal 1st/3rd person AGK framwork(without physics)
Post by: GaborD on January 30, 2018, 08:27:04 PM
But.. but.. noone would have noticed! :D
Title: Re: Universal 1st/3rd person AGK framwork(without physics)
Post by: Rick Nasher on February 01, 2018, 10:08:49 AM
I can't lie..  ;D

(https://i.imgur.com/pFlwb2o.gif)
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Amon. on March 05, 2018, 04:08:00 PM
Thanks, Rick. This just added a great deal to my knowledge of AGK2. Looking good so far. Waiting for a new update. :D
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on March 05, 2018, 06:42:27 PM
Glad to be of help.

I've stripped, split up and restructured the code to get a better overview. I've modified the camera handling and refined a few things under the hood.

Currently am preparing the code for being able to use in multiplayer. That means enumerating type arrays and once works the way I like it I'll bring back in the stuff I took out. Need iron out a cam swapping from 1 to another player bug first.

Hope I can release a little update soon..




Road map:
V6.7  (04-03-2018)
*See if can store cam positions/orientations  in typevariables  and  use when switching players (needed for multplayer later on ) and when switch from 1 to another cam mode.


TO DO(not necessarily in this order):
Fase1 - Cam/Player handling.
- Demo cam mode, spinning round player?
- TopView cam mode?
- Put back other routines I took out previously.

Fase2 -  Collectables/ Fire mechanisms.
- Create  bullets collision detection.
- Scorch marks for bullet impact.
- Create item mngr a la jeppe's
- Ammo boxes/ bullet system/inventory/scorches/bullet holes, grenades righthand?
- Target image? /zoom mode?
- Labels /energy levels above players.

Fase3 - Environments.
- Terrain.
- Teleports/spawn points.
- Clouds, sun.
- Foliage?

Fase4 - Enemies/bots.
- NPC(follower/clingers) A*, AI

Fase5 - Networking.
- Peer2Peer (networking stack, msgs)
- Hosting/matchmaking Server?
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: RemiD on March 06, 2018, 08:26:42 AM
@Rick>>i suggest that you try to code a pathfinding system before trying to code a turnmove detectcollisions reposition system, it will expand your mind about the possibilities and constraints...
Depending on the game, you don't need to detect collisions in 3d, so you can check if a turningmoving entity is inside an area or not, and depending on the result, allow a move or reposition it...

To detect collisions between a weapon / bullet and a character, you can always use linepicks and pickables or a meshesintersect-like... (with low details shapes)
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on March 21, 2018, 11:03:38 PM
'Little' update, mostly under the hood.
Source Download <here> (http://www.mediafire.com/file/m7mxy23b6sj8f23/U3D13P_FW%20V6.8.rar)
(http://i64.tinypic.com/biwdbn.jpg]http://i64.tinypic.com/biwdbn.jpg)
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Naughty Alien on March 21, 2018, 11:47:21 PM
..nice..im building Point and click adventure editor, and im wondering, does AGK license allow sales of such product ??
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Qube on March 22, 2018, 12:28:44 AM
'Little' update, mostly under the hood.
Coming along really well :) - I still see the bug there with MacOS and the mouse look code. Not your bug but AGK's. I see there's a thread on the TGC forums about that MacOS mouse look bug and it's not been address yet. I think I'll whip up another example over the weekend so hopefully Paul will fix it.

..nice..im building Point and click adventure editor, and im wondering, does AGK license allow sales of such product ??
Of course :) there are no licensing issues on that side.
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on March 22, 2018, 07:22:12 AM
Quote
Coming along really well :) - I still see the bug there with MacOS and the mouse look code. Not your bug but AGK's. I see there's a thread on the TGC forums about that MacOS mouse look bug and it's not been address yet. I think I'll whip up another example over the weekend so hopefully Paul will fix it.

Thanks, don't have a Mac so can't really check. Hope they'll fix it.
Do you have a url of the thread you're referring to?
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Qube on March 22, 2018, 03:49:02 PM
Here’s the thread https://forum.thegamecreators.com/thread/220725
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on March 24, 2018, 06:49:58 AM
Many thanks Qube, I've just posted a reminder (https://forum.thegamecreators.com/thread/221905)on the Bug Reports section of AGK.
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on December 09, 2018, 01:28:24 PM
Hi guys,
Projects(and myself) -were kinda on hold- due to my health and other circumstances, but couldn't resist to check back at it.
(which is not all that good for me actually, but hey..)  :)


Re-did some things to make it more modular for the multi-player preps and also reduced FPS drop, caused by shadows on my low spec, ancient machine.
So can now choose between 3 shadow modes: optimized for speed, quality or a compromise between those two(default).
(http://i67.tinypic.com/1ymqdj.jpg)



However I noticed an odd behavior:
-When turning round 360degrees in 3rd person cam mode, it appears the player object moves upwards a little (in the Y direction), perhaps while passing over it's own shadow??
-At same time happens also for the other 2 player objects, even while I'm only controlling the 1st player object?!

(http://i66.tinypic.com/30wkr2t.jpg)

Can't really figure out why, as PlayerY variable remains the same and the other 2 players aren't linked to the controls at that time..
Wondering if it's an optical illusion, but don't think so.


Can anybody please confirm/debunk this odd behavior?
(control rotation by pressing A, D or using the mouse)

Sources Download Link(as usual) on:
http://www.mediafire.com/file/2w05fty0l510mdj/U3D13P_FW_V6.9.rar/file (http://www.mediafire.com/file/2w05fty0l510mdj/U3D13P_FW_V6.9.rar/file)
 *Do not use IE for download for it can't handle the nasty popups of MediaFire(I use Chrome to avoid).
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: RemiD on December 09, 2018, 05:21:35 PM
Quote
Projects(and myself) -were kinda on hold- due to my health and other circumstances, but couldn't resist to check back at it.
wondered what happened to you, since you were quite active around here ( i hope that you are ok ;D )


Quote
-When turning round 360degrees in 3rd person cam mode, it appears the player object moves upwards a little (in the Y direction), perhaps while passing over it's own shadow??
-At same time happens also for the other 2 player objects, even while I'm only controlling the 1st player object?!
it could be an error in your code, or a bug in AGK...

few things i would do to determine the cause :
->check in realtime the Yaw value and the Y value to see when this happens exactly
->check the MouseXSpeed value (or similar) or how you increment / decrement the Yaw value to see if there is some weird variation
->recode a similar look turn move function but without collider/physics
->check the procedures which affects all characters (to determine why they are all moved upward)
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on December 09, 2018, 06:35:14 PM
@RemiD

Hehehe, indeed long time no hear, no see. How are you doing?


Unfortunately family related circumstances(I have a very ill family member, which takes a lot out of me and affects my resilience) caused it to tip over and worsened the condition. Add to that my overal physical condition and it's party-time(not).  :(
To makes things worse: this time it really takes a long time to get back to 'normal' levels.

Typing this alone already takes a lot( giving me headaches) so I probably shouldn't, but hey I'm just too bored.


Now to get back on topic:
I thought about that and if my condition permits I'll give it a try. Could be something I previously missed or AGK introduced a bug related to either rotation round the Y-axis(possible, as they recently increased performance) or has has to do with the shadow system(less likely).



Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: RemiD on December 09, 2018, 07:10:55 PM
a few suggestions to (maybe) improve your condition :
->decrease (or stop) eating gluten foods (obstruct the lymphatic pipes)
->decrease (or stop) eating fried foods (obstruct the lymphatic pipes)
->decrease sugar without fibers (fruits are ok, cane sugar jelly honey biscuits not ok or in little amount) (raise blood pressure)
->decrease the salt without fibers (raise blood pressure)
->sleep more
->stop ejaculating (taboo, i know, but some say sperm is made from stuff from the brain / spine)
->try intermittent fasting (basicaly you eat only during a 4-8 hours a day, then the body has 16-20hours to eliminate and repair)
->go outside a little each day and move and breath some fresh air

but as always, do what you want !



good luck with your project
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on December 09, 2018, 07:58:08 PM
Quote

->decrease (or stop) eating gluten foods (obstruct the lymphatic pipes)
->decrease (or stop) eating fried foods (obstruct the lymphatic pipes)

Didn't know that. Hmm..

Quote

->decrease sugar without fibers (fruits are ok, cane sugar jelly honey biscuits not ok or in little amount) (raise blood pressure)

Sugar=evil.
During summer I suffer from severe hayfever, but when I quit using sugar(soda, candy etc) then the intensity decreases immensely. Tested multiple times if really was like that.
E.g. would sit on my mothers balcony for hours without a problem. Then when took only 1 glass of cola and voila: Near continuous sneezing, leaking eyes etc. Very easy to demonstrate.
Wonder why science doesn't make this more widely known(money envolved?).
Fruit indeed is good(not always for the teeth though).

Quote


->decrease the salt without fibers (raise blood pressure)
->sleep more

So true.  Trying to limit salt(not always easy as I love it).
Getting enough sleep is very important for recovering from it, but haven't done too well this time.

Quote

->stop ejaculating (taboo, i know, but some say sperm is made from stuff from the brain / spine)

Interesting, that explains the absence of my braincells. ;)
But indeed, it can wear out the resources and energy of the body. I noticed got headaches returning after some hefty sessions(but I have a very demanding girlfriend  :)) ).
Nevertheless: too few ejaculations can also be bad, and I heard can cause cancer due to rogue cells and auto-immune diseases when gets into the bloodstream(can happen with sterilized men). Men who have it 3x a week appear to have less cancer - not to say it will prevent it if it's in your destiny/ body makeup.

Quote

->try intermittent fasting (basicaly you eat only during a 4-8 hours a day, then the body has 16-20hours to eliminate and repair)

Interesting thought..

Quote

->go outside a little each day and move and breath some fresh hair

(so hope you meant 'air' instead of 'hair'  :P )
I know, running helped me recover the other times. Wasn't easy to bring myself to do so this time, due the fact that I'm a bit of pussy when the weather is bad(and it is raining a lot), plus I have a bad knee.


Balance is the essence, as with most in life.

Quote
good luck with your project
Many thanks(will need it) ;)
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: RemiD on December 09, 2018, 09:24:05 PM
yes i meant "air" not "hair"  :P


about not ejaculating, or not often, i know this is a taboo subject, but did you know that you can have orgasms (several in a day) without loosing sperm (=cells+essential nutrients) and without feeling tired ? if you are interested about that : youtube.com/results?search_query=mantak+chia+sperm+retention

( i became interested about that when i noticed that the more i age, the more it took time (sometimes days) to recover my full vitality strength agility speed endurance clarity after loosing sperm, so now i don't anymore, and i can code things you would not believe ahahah 8) )

i think that the need to ejaculate often is propaganda to make people more stupid and weak.
the cancer cells in the prostate area may happen due to the diet (and personal sensivities), because some foods (mamals meat, mamals milk / cream / yogurt / cheese) are full of hormones which can cause problem in some glands...
personally i feel 10 times more powerful and clarity now than when i was loosing my cells and essentials nutrients... (a cause of aging is lack of cells and lack of essential nutrients!)



about movement (not sport), it is improtant to move because the lymphatic system depends on movement to move / eliminate the lymphatic fluid, but personally i am not a sport guy, i just walk, run a little, and lift some weights 1hour per week...)
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Madjack on December 10, 2018, 03:39:22 PM
personally i feel 10 times more powerful and clarity now than when i was loosing my cells and essentials nutrients... (a cause of aging is lack of cells and lack of essential nutrients!)

Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on December 10, 2018, 03:51:14 PM
Ghi-ghi..  ;D

No, homey don't play that! No sucking the life juice out of me you silly vampire like dames!  :))
"You got the body, now you want my soul- don't even think about it - say nogo " - but then in reverse.  :P

Perhaps we all have to go the Sting way and go tantric..

(How did we get this topic so derailed?? lol)
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: c0d3r9 on December 10, 2018, 05:13:20 PM
Lol i try to write nothing .... but ....
"a cause of aging is lack of cells" .... the cause is that our cell stoped regenerating/repairing...

And about the ejaculating theme....better i say nothing  :)) ....for now i never stand up in the morning...i could lost my energy if i go a few steps.Bullsh..  :))
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Steve Elliott on December 10, 2018, 05:17:09 PM
lmao, we could put this thread down to Festive Drinks...
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on December 10, 2018, 05:49:40 PM
Aging: a beautiful thing. lol

Ah well we can always try using FOXO4-DRI.
Hey wait a sec.. what ever happened to this guy? No more updates? Hope nothing terrible happened.
http://foxo4dri.com/

Besides that: did anybody notice Ray Kurzweil is seemingly getting younger?
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: RemiD on December 10, 2018, 08:48:30 PM
well, you can't be immortal, but you can certainly slowdown aging (by preserving your cells, essential substances, energy) or accelerate aging (by wasting your cells, essential substances, energy)...

Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on December 10, 2018, 09:18:41 PM
So true. I knew a colleague who had a nymphomaniac as a girlfriend who needed it like 5 times a day and he deteriorated in front my eyes in a 2 years time. :)

However, scientific evidence also shown that sex apparently also keeps people young(at least when not overdoing it).

Balance is the essence as with everything in life.
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on December 10, 2018, 09:21:43 PM
Now to get back on topic:  :)

Ok, plot thickens:

To determine if my player model actually really raised from the terrain surface when rotating 360 degrees, I had put up a striped measuring pole, static object for reference.
But:
1.  Appears the height doesn't change in conjuction to this or it also moves upwards,
2.  When used different shadow modes it doesn't show.


Shadow mode 2 - the anomaly only occurs in this mode:
(http://i65.tinypic.com/123prx2.jpg)

Shadow mode 1 - all fine:
(http://i65.tinypic.com/ru67f6.jpg)

Shadow mode 3 - all fine:
(http://i65.tinypic.com/10cvnmc.jpg)



Possibilities:
1) Either it's just an optical illusion only present in shadow mode 2.

Or:
2) All objects, to which the object's shadow has been cast in mode 2, lower itself.

Or:
3) The shadow map gets displaced.
 
My best guess is option 1 or 3 or there's a serious bug in the gfx renderer.

Quote from:
SetShadowMappingMode
Description
Turns shadow mapping on or off, by default this is off. Shadows are only generated by the the global directional light, which can be controlled with the SetSunDirection command. Note that this is not guaranteed to be supported on all devices, you can check for the current device by calling GetShadowMappingSupported. There are currently three shadow modes that can be used, mode 1 uses Uniform shadow mapping which has lower but consistent quality. Mode 2 uses Light Space Perspective shadow mapping (LiPSM) which has higher quality in most cases but if the camera is looking in the same direction as the light then it is no better than Uniform shadow mapping. Light Space Perspective also suffers from shadow shimmering as the camera moves whereas Uniform is more stable. Both have about the same performance. Mode 3 uses Cascade shadow mapping which uses multiple shadow maps to maintain high quality near the camera whilst still allowing lower quality shadows in the distance. This method has much lower performance than the previous two methods but results in better quality shadows in all cases.

Note that when using modes 1 and 2, texture stage 7 on all objects receiving shadow is reserved for the shadow map. When using shadow mode 3 (cascade shadows) then texture stages 4, 5, 6, and 7 are reserved for the shadow maps.


Strikes me rather odd that it *does* look good in mode 1. 
It looks like the shadows get displaced, do no longer touch the models at the base, giving this strange illusion that models moved up in Y direction when rotating the model 360 degrees.
I've asked at the AGK site if someone can shed a little light on this..
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Madjack on December 10, 2018, 09:45:39 PM
Besides that: did anybody notice Ray Kurzweil is seemingly getting younger?

You mean he's found a better brand of hair dye?
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on December 10, 2018, 09:47:32 PM
 ;D
@Qube: we still need a 'rofl'
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: RemiD on December 10, 2018, 09:54:11 PM
maybe your collider is not the same size / radius than your debug mesh / renderer (to see the collider)

for me, in your 3 screenshots, the character floats above the ground...

try to put a grid texture on your ground, so that we can better see the difference
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: blinkok on December 11, 2018, 03:26:26 AM
It is the nature of shadows and what you see. The little bit of background that shows through in the first instance makes you think it's off the ground.
I bet if you coloured that in a image proggy you wouldn't notice the difference
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on December 11, 2018, 03:22:01 PM
@RemiD
Quote
maybe your collider is not the same size / radius than your debug mesh / renderer (to see the collider)
for me, in your 3 screenshots, the character floats above the ground...
try to put a grid texture on your ground, so that we can better see the difference

- Collider and model are same sized. It's a capsule so might look like that.
- Added a quick texture to ground(borrowed from blink0k, hope you don't mind) for testing purposes, but no show.
- For testing I also lowered it into the ground so the cam could see in between the other player models and the ground, but couldn't see through. However, it's tiny little feet are slightly of the floor, but these are just ornaments(intend to animate them later, if I ever get to that lol ).

Close up:
(http://i67.tinypic.com/35lbxna.gif)



@blink0k
Quote
It is the nature of shadows and what you see. The little bit of background that shows through in the first instance makes you think it's off the ground.

- Might very well be.

Quote
I bet if you coloured that in a image proggy you wouldn't notice the difference.

- Still looks little odd.
- Appears shadows are displaced more in mode 2 then in mode 1, while none occurs in mode 3(slowest).

mode1:
(http://i63.tinypic.com/33y53pc.gif)

mode2:
(http://i68.tinypic.com/rqzmus.gif)

mode3:
(http://i65.tinypic.com/2aaeu8i.gif)

Cam angle also appears to have something to do with it.
It's especially clear when rotating round a pole like object:
(http://i65.tinypic.com/2921bp4.gif)


Ok that's a little too much animation, but hey a movie says more than a million words..  :D
(Hope it's not killing bandwidth Qube)
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Steve Elliott on December 11, 2018, 04:31:47 PM
Quote
- Appears shadows are displaced more in mode 2 then in mode 1, while none occurs in mode 3(slowest).

So you don't get a problem with mode 3?  Just that the other modes have made a compromise in accuracy to gain some extra speed?
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: RemiD on December 11, 2018, 04:41:05 PM
so your characters are always on the ground, but depending on the shadows mode, it makes it looks like they are not (because of the shadows offsets)...

the offset depending on the angle of view / caster is similar to what i have noticed with swift shadow system (for Blitz3d)...

A way to prevent the offset was to make the shape go slightly through the floor.
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on December 11, 2018, 05:09:15 PM
@Steve Elliott
Exactly. However, if so should be fixable by adjusting the shadow offset in conjunction to the cam, but that would require access to the engine I guess.

@RemiD
Yeah I've tried that and works but interferes with collision system, would be a workaround and would have to do it for all objects which is a bit silly and make things overly complicated. Besides I think should be fixable by what I mention above.

Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: blinkok on December 11, 2018, 07:41:45 PM
Have you tried SetShadowBias( bias )?
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Qube on December 11, 2018, 08:48:29 PM
Quote
- Appears shadows are displaced more in mode 2 then in mode 1, while none occurs in mode 3(slowest).
Shadows in AGK are not the best in either quality or features. If I remember the angle is based on the sun and that's pretty much it. I hope they update the shadow side and it needs a little love.

Quote
(Hope it's not killing bandwidth Qube)
Nah, it's OK. I pay for their truly unlimited service and they've not complained once yet :P
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: RemiD on December 11, 2018, 09:07:54 PM
so... when you remove all the unfinished / buggy / poorly documented features of AGK, what remains seems not much :))
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Qube on December 11, 2018, 09:36:59 PM
so... when you remove all the unfinished / buggy / poorly documented features of AGK, what remains seems not much :))
Lol, it's not that bad :P - It's very feature rich for the price and it's documentation is 100 times better than later BRL products. The downside is that not all features are fully fleshed out like physics, shadows, 3D models / texturing / animation. It could do with better implementations in parts. Overall I still like it a lot but you have to workaround it's limitations just like anything else.
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: GaborD on December 11, 2018, 09:49:35 PM
For me personally, the only thing that matters is that the foundation is solid, fast and flexible.
In my opinion you have to write the higher level systems (including rendering and the shaders) specifically for each type of project anyway, no matter the language/engine. Because that's the only way to high rendering quality with good performance.
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Steve Elliott on December 11, 2018, 09:50:04 PM
Quote
so... when you remove all the unfinished / buggy / poorly documented features of AGK, what remains seems not much :))

lol like BRL ever produced good documentation and added shaders!  I would say it's very good for 2D.  3D is buggy, but at least they bothered to try to add features, unlike Blitz 3D.
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on December 12, 2018, 10:04:23 AM
Got an answer from AGK's Paul Johnston:

Quote
Mode 2 uses some funky perspective projection matrices that get incredibly inaccurate when the camera and light are pointing in the same direction. The only things I can think of to work around it is to limit the extent of the projection matrix by using SetShadowRange to set the range smaller than the camera view range, or switch to mode 1 when the dot product of the light direction and the camera direction reaches a certain value. i.e. (Lx*Cx + Ly*Cy + Lz*Cz) > 0.7 where (Lx,Ly,Lz) and (Cx,Cy,Cz) are normalized, and 0.7 is a value between 0 and 1, where 1 is looking in exactly the same direction and 0 is perpendicular to each other.

The first suggestion has already been implemented and didn't do much, only effective when drastically reducing.
I'm actually really pushing the system though for using a very large scale to stay compatible with the physics system.

The 2nd suggestion might work but at a cost of accuracy.
I'd prefer to have a command to shift the entire shadow texture as happens to all objects at same time.

But dunno if that's actually feasible, so I asked.
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Holzchopf on December 12, 2018, 10:16:25 AM
I'm no expert in 3D, not even a manager in that field, but I can't resist asking this dumb question: Why should shadows depend on camera direction? They don't in real life, so why do they in AGK?
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on December 12, 2018, 10:50:17 AM
Afaik: Shadows depend on sun(lightsource) position and the cam position/angle in order to represent them.
In an ideal world shouldn't matter, but it's a sim, not the real world.
Would otherwise probably be too FPS intense.

In mode 3 all is fine btw but it's bit more costly on FPS and as I'm on an old rig.. all bits matter.
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: GaborD on December 12, 2018, 04:52:45 PM
I'm no expert in 3D, not even a manager in that field, but I can't resist asking this dumb question: Why should shadows depend on camera direction? They don't in real life, so why do they in AGK?

Not a dumb question at all. You are right about real life, shadows don't care which direction or distance you look at them from.
In real life we basically have infinite shadowmap resolution, in 3D not so much.

What Rick said hits the nail on the head, in 3D resources are very limited and have to be optimized for speed.
Some trickery is necessary to have reasonable shadow resolution near the cam while still covering a big area.
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: blinkok on December 12, 2018, 11:46:38 PM
Is the code in the first post still the latest?
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Holzchopf on December 13, 2018, 06:30:14 AM
In real life we basically have infinite shadowmap resolution, in 3D not so much.

Didn't think about that. Thanks for pointing that out!
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: RemiD on December 13, 2018, 06:44:45 AM
for stencil shadows made with shadow volumes, the camera is not positionned at the lightsource position... it depends on the tech used...
Title: Re: Universal 1st/3rd person AGK framework(without physics)
Post by: Rick Nasher on December 13, 2018, 06:13:47 PM
Is the code in the first post still the latest?
Good point.  8)  Need to update.
[EDIT: I already had under  post# 27  (https://www.syntaxbomb.com/index.php/topic,3468.msg21355.html#msg21355) ]

But perhaps bit hard to follow so I'll put it in the first post too, to avoid confusion.



for stencil shadows made with shadow volumes, the camera is not positionned at the lightsource position... it depends on the tech used...
True. AGK uses a couple of different approaches I believe, depending on the shadow mode.

From the docs:
Quote
"SetShadowMappingMode
Description
Turns shadow mapping on or off, by default this is off. Shadows are only generated by the the global directional light, which can be controlled with the SetSunDirection command. Note that this is not guaranteed to be supported on all devices, you can check for the current device by calling GetShadowMappingSupported. There are currently three shadow modes that can be used, mode 1 uses Uniform shadow mapping which has lower but consistent quality. Mode 2 uses Light Space Perspective shadow mapping (LiPSM) which has higher quality in most cases but if the camera is looking in the same direction as the light then it is no better than Uniform shadow mapping. Light Space Perspective also suffers from shadow shimmering as the camera moves whereas Uniform is more stable. Both have about the same performance. Mode 3 uses Cascade shadow mapping which uses multiple shadow maps to maintain high quality near the camera whilst still allowing lower quality shadows in the distance. This method has much lower performance than the previous two methods but results in better quality shadows in all cases.

 Note that when using modes 1 and 2, texture stage 7 on all objects receiving shadow is reserved for the shadow map. When using shadow mode 3 (cascade shadows) then texture stages 4, 5, 6, and 7 are reserved for the shadow maps. "