*) EDIT: This has been solved -see last post.
Off topic: Would be nice if we could change or at least add to the topic title something like [SOLVED] or [WORKAROUND FOUND]..
Hi,
I've stumbled onto something puzzeling.. Before I could have 2 animated characters displaying shadows without any issues in Win 10 x64. See pics below:
(code+media can be downloaded here: http://www.mediafire.com/file/55whby55hsv1dj1/CharacterController_Ragdoll3.rar )
// Project: CharacterController Ragdoll
// Created: 2016-06-07
#include "Camera.agc"
#include "Ragdoll.agc"
#include "CharacterController.agc"
// set window properties
SetWindowTitle( "CharacterController Ragdoll" )
SetWindowSize( GetDeviceWidth(), GetDeviceHeight(), 0 )
//Set display properties
SetVirtualResolution ( GetDeviceWidth(), GetDeviceHeight() )
SetVSync( 1 )
//Set Backdrop color
SetClearColor( 0,170,204 ) // light blue
//Set display orientation for mobile device
SetOrientationAllowed( 0, 0, 1, 0 )
SetScissor( 0, 0, 0, 0 )
//Set camera
SetCameraRange( 1, 1, 50000 )
SetCameraPosition( 1, 0, 100.0, -150.0 )
SetCameraLookAt( 1, 0.0, 100.0, 0.0, 0.0 )
//Set Text size and color as displayed to screen.
SetPrintSize( 22.0 )
SetPrintColor( 255, 255, 0 )
//SetSkyBoxVisible( 1 )
//Set the error reporting for debugging.
//SetErrorMode( 2 )
DisplayLogo()
Create3DPhysicsWorld()
// ###################### camera & fog######################
global fog=0 // fog is 'on'/off
global shadowMode = 3 // shadows
global useCharacter = 1 //
global time# = 0
global DeltaTime# = 0
global ColorTime# = 0
//global ColorID
global Red# = 0
global Green# = 0
global Blue# = 0
SetCameraRange( 1, 0.1, 2000 )
//SetCameraRange( 1, 0.1, 100 )
// point camera towards the object
//SetCameraPosition(1, 383, 30, 383)
//SetCameraPosition( 1, 340,10,460 )
//SetCameraLookAt( 1, 330,2,420,0 )
// add some atmospheric fog
SetFogMode( fog )
SetFogColor( 161,183,209 )
SetFogRange( 50, 700 )
//SetFogRange( 60,95 )
SetFogSunColor( 255,230,179 )
// ###################### lighting & shadows #################
//SetAmbientColor( 128,128,128 )
SetAmbientColor( 28,28,28 )
// shadows
shadowMode = 3 // start with cascade shadow mapping which gives the best quality
SetShadowMappingMode( shadowMode )
SetShadowSmoothing( 2 ) // random sampling
SetShadowMapSize( 1024, 1024 )
SetShadowRange( -1 ) // use the full camera range
SetShadowBias( 0.0012 ) // offset shadows slightly to avoid shadow artifacts
// ###################### skybox & sun #### #################
// enable the sky box, show the sun, not necessary but improves the experience
SetSkyBoxVisible( 1 )
//dx# = -0.3714
xdir# = -0.3714
//dy# = -0.7428
ydir# = -0.7428
//dz# = 0.5571
zdir# = 0.5571
//SetSunDirection( dx#, dy#, dz# )
SetSunDirection( xdir#, ydir#, zdir# )
SetAmbientColor( 30,30,30 )
// DayNight - SunColor stuff thing...
type ColorData
Red#
Green#
Blue#
Time#
endtype
global Color as ColorData[]
global ColorID=0
AddColor(60,60,60,0)
AddColor(255,180,150,90)
AddColor(255,230,179,180)
AddColor(255,60,60,270)
AddColor(60,60,60,360)
//########################################
//collision groups and masks
global group0 = 1
global group1 = 2
global group2 = 4
global group3 = 8
global group4 = 16
global group5 = 32
global mask0 = 1
global mask1 = 2
global mask2 = 4
global mask3 = 8
global mask4 = 16
global mask5 = 32
global FPS as integer
global floorBoxID as integer
global floorTexID as integer
global ballTex as integer
global crateTex as integer
global concreteTex as integer
global dumpsterTex as integer
global chapelTex as integer
global L_VirtualJoystick as integer
global R_VirtualJoystick as integer
global C_VirtualJoystick as integer
LoadDemoTextures()
//Make Physics floor
floorBoxID = CreateObjectBox( 10000.0, 12.0, 10000.0 )
floorTexID = LoadImage("/media/steelPanelTiled.png")
SetObjectImage( floorBoxID, floorTexID, 0 )
SetImageWrapU ( floorTexID,1)
SetImageWrapV ( floorTexID,1)
SetObjectUVScale (floorBoxID, 0,20,20)
//SetObjectImage( floorBoxID, floorTexID, 0 )
//SetObjectColor( floorBoxID, 112, 100, 100, 255 )
SetObjectLightMode( floorBoxID, 1 )
SetObjectPosition( floorBoxID, 0.0, 0.0, 0.0 )
//This command creates a static physics body for the floor box with a triangle mesh collision shape.
//A static physics body has no mass and does not get moved.
Create3DPhysicsStaticBody( floorBoxID )
//This 3D Physics command changes the collision shape to a primative box shape since we do not need the accuracy of
// polygon collision for just a box. The physics body is still static.
SetObjectShapeBox( floorBoxID ) //
SetObjectReceiveShadow( floorBoxID, 1 )
stairsObj = LoadObject( "/media/Stairs.x" )
SetObjectImage( stairsObj, concreteTex, 0 )
SetObjectPosition( stairsObj, 0.0, 6.0, 200.0 )
RotateObjectGlobalY( stairsObj, 180.0 )
Create3DPhysicsStaticBody( stairsObj )
SetObject3DPhysicsGroupAndMask( stairsObj, group0, -1 )
SetObjectReceiveShadow( stairsObj, 1 )
SetObjectCastShadow( stairsObj, 1 )
global dumpster
dumpster = LoadObject( "/media/dumpster_3yardOnFloor.x")
SetObjectImage( dumpster, dumpsterTex, 0 )
//SetObjectColor( dumpster, 255-200, 3, 239, 255 )
SetObjectPosition( dumpster , -300.0, 1500, 0.0 )
Create3DPhysicsDynamicBody( dumpster )
//This command changes the collison shape to a convex hull.
//SetObjectShapeConvexHull( dumpster )
SetObject3DPhysicsMass( dumpster, 2.0 )
SetObjectReceiveShadow( dumpster, 1 )
SetObjectCastShadow( dumpster, 1 )
chapelObj = LoadObject( "/media/Models/chapel.obj" )
SetObjectImage( chapelObj, chapelTex, 0 )
//SetObjectUVScale (chapelObj, 0,20,20)
SetObjectPosition( chapelObj, -500.0, 6.0, 0.0 )
RotateObjectGlobalY( chapelObj, 180.0 )
SetObjectScale(chapelObj, .5,.5,.5)
Create3DPhysicsStaticBody( chapelObj )
SetObject3DPhysicsGroupAndMask( chapelObj, group0, -1 )
SetObjectReceiveShadow( chapelObj, 1 )
SetObjectCastShadow( chapelObj, 1 )
// Payer
remstart
stairsObj = LoadObject( "/media/stairsObj.x" )
SetObjectImage( stairsObj, concreteTex, 0 )
SetObjectPosition( stairsObj, 0.0, 6.0, 200.0 )
RotateObjectGlobalY( stairsObj, 180.0 )
Create3DPhysicsStaticBody( stairsObj )
SetObject3DPhysicsGroupAndMask( stairsObj, group0, -1 )
SetObjectReceiveShadow( stairsObj, 1 )
SetObjectCastShadow( stairsObj, 1 )
remend
maskedSoldierTex = LoadImage( "/media/Masked Soldier.png" )
SetImageWrapU(maskedSoldierTex,1)
SetImageWrapV(maskedSoldierTex,1)
global maskedSoldier // <<< Added for follow cam
maskedSoldier = LoadObjectWithChildren( "/media/Masked Soldier Frag.x" )
SetObjectImage( maskedSoldier, maskedSoldierTex, 0 )
SetObjectLightMode( maskedSoldier, 1 )
//position above floor for charcater controller
SetObjectPosition( maskedSoldier, -40.0, 10.0, -20.0 )
SetObjectRotation( maskedSoldier, 0, 90, 0 )
SetObjectAnimationSpeed( maskedSoldier, 30.0 )
PlayObjectAnimation( maskedSoldier, "Animation", 3002, 3547, 1, 0.0 )
SetObject3DPhysicsMass( maskedSoldier, 5.0 )
CreateCharacterController( maskedSoldier )
Stand3DPhysicsCharacterController( maskedSoldier )
Set3DPhysicsCharacterControllerStepHeight( maskedSoldier,12.0 )
Set3DPhysicsCharacterControllerJumpSpeed( maskedSoldier, 7.0 )
SetObjectCastShadow( maskedSoldier, 1 )
SetObjectReceiveShadow( maskedSoldier, 1 )
PickJointSetup()
CreateRagdollVectors()
//========= dude 2 ==============================
SoldierTex = LoadImage( "/media/Soldier_body_1_D.png" )
SetImageWrapU(SoldierTex,1)
SetImageWrapV(SoldierTex,1)
global Soldier // <<< Added for follow cam
Soldier = LoadObjectWithChildren( "/media/Original_Soldier.X" )
SetObjectImage( Soldier, SoldierTex, 0 )
SetObjectLightMode( Soldier, 1 )
//position above floor..
SetObjectPosition( Soldier, 60.0, 15.0, 0.0 )
SetObjectRotation( Soldier, 0, 0, 0 )
SetObjectAnimationSpeed( Soldier, 20 )
PlayObjectAnimation( Soldier, "Anim1", 1000, 1282, 1, 0 )
SetObject3DPhysicsMass( Soldier, 2.0 )
SetObjectCastShadow( Soldier, 1 )
SetObjectReceiveShadow( Soldier, 1 )
// =============================================
remstart
CheckSizeObject=CreateObjectCapsule(20,80,90)
SetObjectPosition( CheckSizeObject, 120.0, 45.0, 0.0 )
SetObjectCastShadow( CheckSizeObject, 1 )
SetObjectReceiveShadow( CheckSizeObject, 1 )
remend
L_VirtualJoystick = 1
R_VirtualJoystick = 2
C_VirtualJoystick = 3
AddVirtualJoystick( L_VirtualJoystick, 60.0, GetScreenBoundsBottom() - 60.0, 120.0 )
AddVirtualJoystick( R_VirtualJoystick, GetScreenBoundsRight() -60, GetScreenBoundsBottom() - 60.0, 120.0 )
AddVirtualJoystick( C_VirtualJoystick, GetDeviceWidth() / 2 , GetScreenBoundsBottom() - 60.0, 120.0 )
do
FreeFlightCameraUsingMouseAndArrowKeys( 1, 2.0 )
FreeFlightCameraUsingVirtualJoysticks( 1, 3.0 )
//This function casts a ray, then creates a pick joint at that the contact point.
PickJointCreateAndUpdate()
if GetRawMouseRightPressed()
//To move dynamic physics bodies we need to apply velocity to the physics body.
ThrowBall( 800.0, 2.0 )
endif
//Press R to create ragdoll
if GetRawKeyPressed( 82 )
if Get3DPhysicsRagdollExist( maskedSoldier ) = 0 then CreateRagdollSkelton( maskedSoldier )
Delete3DPhysicsCharacterController( maskedSoldier )
endif
if Get3DPhysicsCharacterControllerExists( maskedSoldier )
CharacterControllerInput( maskedSoldier )
endif
if GetRawKeyPressed( 70 ) // f= reset
if Get3DPhysicsRagdollExist( maskedSoldier )
Delete3DPhysicsRagdoll( maskedSoldier )
SetObjectAnimationFrame ( maskedSoldier, "Animation", 3002, 0.75 )
CreateCharacterController( maskedSoldier )
Stand3DPhysicsCharacterController( maskedSoldier )
Set3DPhysicsCharacterControllerStepHeight( maskedSoldier,12.0 )
Set3DPhysicsCharacterControllerJumpSpeed( maskedSoldier, 6.0 )
endif
endif
//Sun()
FPS = ScreenFPS()
PrintC( "Fame Rate: " ) : Print( FPS )
PrintC( "Total Physics Objects: " ) : Print( Get3DPhysicsTotalObjects() )
PrintC( "Active Physics Objects: " ) : Print( Get3DPhysicsActiveObjects() )
Print( "Rmb to throw sphere object " )
Print( "Lmb to pick Dynamic objects " )
Print( "Arrow Keys to move camera, Mouse to Rotate" )
Print( "WASD To Move Character, Q & E to Rotate, " )
Print( "SpaceBar to jump and C to crouch " )
Print( "The R Key will Ragdoll the Character , F key will Reset" )
Sync()
Step3DPhysicsWorld() //required for updating physics.
loop
function DisplayLogo()
bulletLogo = LoadImage("/media/agk2_logokit/bullet_logo_small.png")
SetImageWrapU( bulletLogo,1 )
SetImageWrapV( bulletLogo,1 )
bulletSprite = CreateSprite( bulletLogo )
SetSpritePosition( bulletSprite, GetScreenBoundsRight() -310.0, GetScreenBoundsTop() )
agkLogo = LoadImage("/media/agk2_logokit/Made-With-AGK-128px.png")
SetImageWrapU( agkLogo,1 )
SetImageWrapV( agkLogo,1 )
agkSprite = CreateSprite( agkLogo )
SetSpritePosition( agkSprite, GetScreenBoundsRight() -128.0, GetScreenBoundsTop() )
endfunction
function LoadDemoTextures()
floorTexID = LoadImage( "/media/steelPanelTiled.png" )
SetImageWrapU( floorTexID, 0 )
SetImageWrapV( floorTexID, 0 )
ballTex = LoadImage( "/media/soccerball2.jpg" )
SetImageWrapU( ballTex, 1 )
SetImageWrapV( ballTex, 1 )
crateTex = LoadImage( "/media/Crate_color.png" )
SetImageWrapU( crateTex, 1 )
SetImageWrapV( crateTex, 1 )
concreteTex = LoadImage( "/media/Concrete.png" )
SetImageWrapU( concreteTex, 1 )
SetImageWrapV( concreteTex, 1 )
dumpsterTex = LoadImage( "/media/dumpster_D.png" )
SetImageWrapU( dumpsterTex, 1 )
SetImageWrapV( dumpsterTex, 1 )
chapelTex = LoadImage( "/media/Models/chapel_D.png" )
SetImageWrapU( chapelTex, 1 )
SetImageWrapV( chapelTex, 1 )
endfunction
function ThrowBall( initialSpeed as float, mass as float )
local directionX as float
local directionY as float
local directionZ as float
directionX = Get3DVectorXFromScreen( GetPointerX(), GetPointerY() )
directionY = Get3DVectorYFromScreen( GetPointerX(), GetPointerY() )
directionZ = Get3DVectorZFromScreen( GetPointerX(), GetPointerY() )
throwBall as integer
throwBall = CreateObjectSphere( 8, 16, 32 )
SetObjectImage( throwBall, ballTex, 0 )
SetObjectPosition( throwBall, GetCameraX( 1 ), GetCameraY( 1 ), GetCameraZ( 1 ) )
SetObjectReceiveShadow( throwBall, 1 )
SetObjectCastShadow( throwBall, 1 )
//3D Physics code
Create3DPhysicsDynamicBody( throwBall )
SetObjectShapeSphere( throwBall )
SetObject3DPhysicsMass( throwBall, mass )
SetObject3DPhysicsLinearVelocity( throwBall, directionX, directionY, directionZ, initialSpeed )
SetObject3DPhysicsFriction( throwBall, 0.8 )
SetObject3DPhysicsRollingFriction( throwBall, 0.7 )
endfunction
function PickJointCreateAndUpdate()
//Left mouse btn pressed creates pick joint
if GetPointerPressed()
SetVector3( toVecID, Get3DVectorXFromScreen( GetPointerX(), GetPointerY() ),
Get3DVectorYFromScreen( GetPointerX(), GetPointerY() ),
Get3DVectorZFromScreen( GetPointerX(), GetPointerY() ) )
GetVector3Multiply( toVecID, 1500.0 )
SetVector3( origPosCamVecID, GetCameraX(1), GetCameraY(1), GetCameraZ(1) )
GetVector3Add( toVecID, origPosCamVecID )
RayCast3DPhysics( pickObjectRayID, origPosCamVecID, toVecID, 1 )
HitObjID = Get3DPhysicsRayCastObjectHit( pickObjectRayID, 0 )
if HitObjID > 0
Get3DPhysicsRayCastContactPosition( pickObjectRayID, 0.0, PickVecID )
pickJointID = Create3DPhysicsPickJoint( HitObjID, PickVecID )
endif
endif
//Left Mouse btn held down holds pick joint
if GetPointerState() and pickJointID > 0
SetVector3( updatedPickVecID, Get3DVectorXFromScreen( GetPointerX(), GetPointerY() ),
Get3DVectorYFromScreen( GetPointerX(), GetPointerY() ),
Get3DVectorZFromScreen( GetPointerX(), GetPointerY() ) )
origDistance = GetVector3Distance( origPosCamVecID, PickVecID )
GetVector3Multiply( updatedPickVecID, origDistance )
SetVector3( currPosCamVecID, GetCameraX(1), GetCameraY(1), GetCameraZ(1) )
GetVector3Add( updatedPickVecID, currPosCamVecID )
Update3DPhysicsPickJoint( pickJointID, updatedPickVecID )
elseif pickJointID > 0
Delete3DPhysicsPickJoint( pickJointID )
if HitObjID > 0
SetVector3( updatedPickVecID, Get3DVectorXFromScreen( GetPointerX(), GetPointerY() ),
Get3DVectorYFromScreen( GetPointerX(), GetPointerY() ),
Get3DVectorZFromScreen( GetPointerX(), GetPointerY() ) )
//Unremark this line to apply a force when releasing object.
//SetObject3DPhysicsLinearVelocity( HitObjID, updatedPickVecID, 5000.0)
pickJointID = 0
endif
endif
endfunction
function PickJointSetup()
global pickObjectRayID as integer
global currPosCamVecID as integer
global origPosCamVecID as integer
global toVecID as integer
global updatedPickVecID as integer
global PickVecID as integer
global HitObjID as integer
global pickJointID as integer
pickObjectRayID = Create3DPhysicsRay()
currPosCamVecID = CreateVector3()
origPosCamVecID = CreateVector3()
toVecID = CreateVector3()
PickVecID = CreateVector3()
updatedPickVecID = CreateVector3()
endfunction
Function Sun()
// move the sun
time# = time# + GetFrameTime()*5.5 // /2
xdir# = sin(time#)
ydir# = cos(time#)
zdir# = -0.5
SetSunDirection(xdir#,ydir#,zdir#)
// To Do: make functions for that sun suff
if time#<Color[ColorID].Time#
DeltaTime#=(Color[ColorID].Time#-Color[ColorID-1].Time#)
ColorTime#=(time#/DeltaTime#)-(ColorID-1)
Red#=Lerp(Color[ColorID-1].Red#,Color[ColorID].Red#,ColorTime#)
Green#=Lerp(Color[ColorID-1].Green#,Color[ColorID].Green#,ColorTime#)
Blue#=Lerp(Color[ColorID-1].Blue#,Color[ColorID].Blue#,ColorTime#)
SetSunColor(Red#,Green#,Blue#)
SetFogSunColor(128+Red#*0.5,128+Green#*0.5,128+Blue#*0.5)
SetSkyBoxSunColor(128+Red#*0.5,128+Green#*0.5,128+Blue#*0.5)
SetSkyBoxHorizonColor(128+Red#*0.5,128+Green#*0.5,128+Blue#*0.5)
//print(Red#)
//print(Green#)
//print(Blue#)
//print(ColorTime#)
else
inc ColorID
if ColorID>Color.length
ColorID=0
time#=0
endif
endif
Endfunction
function Lerp(Start#,End#,Time#)
endfunction Start#+Time#*(End#-Start#)
function AddColor(Red#,Green#,Blue#,Time#)
TempColor as ColorData
TempColor.Red#=Red#
TempColor.Green#=Green#
TempColor.Blue#=Blue#
TempColor.Time#=Time#
Color.insert(TempColor)
endfunction
Now, in
AppGameKit-V2017.09.25-Windows, it somehow
messes up the shadows of the 2 animated characters see below:
Anybody has an idea what's going on? Is this a new bug caused by the latest changes? Can anybody confirm it's the same for them?
[EDIT]
To make it more clear:
as soon as I add the 2nd animated character's shadows, then the shadows of both animated characters get mixed up and they are no longer stuck to the individual characters and do no move along with them. So when I move the player
it's shadow doesn't follow him around but remains in the same area and looks distorted, mixed up with the other characters shadow..
BTW: I've now tested under Android too and it's the same there.