Got several problems:
-If i alter the position of the sun, the light in the scene does, but not the shadows.
-I got my objects colored by the setobjectcolor command. the colors do not show, it seems the shader is overwriting them.
-if i delete a object, even if i got the function "Shadow_RemoveObject" called before i do so, i recieve an error.
math.agc and shadow.agc not included as i did not alter them.
// Project: CUBE
// Created: 2016-08-04
#include "math.agc"
#include "shadows.agc"
// show all errors
//----------------------------------------------------
SetErrorMode(2)
//----------------------------------------------------
// set window properties
//----------------------------------------------------
SetWindowTitle( "CUBE" )
SetWindowSize( 1024, 768, 0 )
//----------------------------------------------------
// set display properties
//----------------------------------------------------
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 0, 0, 0, 1 )
SetPrintSize(16)
SetPrintColor(100,200,250)
//----------------------------------------------------
// cam properties
//----------------------------------------------------
SetCameraPosition(1,0,-45,0)
RotateCameraGlobalY(1,45)
RotateCameraLocalX(1,25)
MoveCameraLocalZ(1,-210)
//----------------------------------------------------
rem SetSunActive(0)
rem CreatePointLight(1,-50,150,50,600,455,455,440)
SetAmbientColor(66,66,96)
Shadow_Init(100,100,1,512)
SetSunDirection(-10,-50,-20)
SetSunColor(200,200,150)
// objects
//----------------------------------------------------
CubesX=-70
CubesY=1
CubesZ=70
CubesCol=0
CubesNum=1014
for Cubes= 1001 to 1225
CreateObjectBox(Cubes,10,1,10)
SetObjectPosition(Cubes,CubesX,CubesY,CubesZ)
SetObjectColor(Cubes,130+CubesCol,90+CubesCol,50+CubesCol,255)
Shadow_AddObject(Cubes)
CubesX=CubesX+10
CubesCol=CubesCol+10
if CubesCol=20 then CubesCol=0
if Cubes>CubesNum
CubesZ=CubesZ-10
CubesNum=CubesNum+15
CubesX=-70
endif
next Cubes
Global theObjectHit
Global Cursor=100
CreateObjectBox(Cursor,10,10,10)
SetObjectColor(Cursor,10,100,0,155)
Shadow_AddObject(Cursor)
//----------------------------------------------------
global test
test=CreateObjectsphere(6,16,32)
Shadow_AddObject(test)
NewElement=2000
//----------------------------------------------------
do
// rotate cam
//----------------------------------------------------
if GetRawMouseMiddleState() = 1
If GetRawMouseX() > MouseX
SetCameraPosition(1,0,-45,0)
RotateCameraGlobalY(1,GetCameraY(1)*-0.075)
MoveCameraLocalZ(1,-210)
TurnR#=0.1
endif
If GetRawMouseX() < MouseX
SetCameraPosition(1,0,-45,0)
RotateCameraGlobalY(1,GetCameraY(1)*0.075)
MoveCameraLocalZ(1,-210)
TurnL#=0.1
endif
endif
MouseX=GetRawMouseX()
//----------------------------------------------------
// smooth fade cam rotation
//----------------------------------------------------
if TurnR#>0.00
SetCameraPosition(1,0,-45,0)
RotateCameraGlobalY(1,GetCameraY(1)*-0.075*TurnR#)
MoveCameraLocalZ(1,-210)
TurnR#=TurnR#-0.005
endif
if TurnL#>0.00
SetCameraPosition(1,0,-45,0)
RotateCameraGlobalY(1,GetCameraY(1)*0.075*TurnL#)
MoveCameraLocalZ(1,-210)
TurnL#=TurnL#-0.005
endif
//----------------------------------------------------
//create/delete objects
//----------------------------------------------------
Click3dObject()
SetObjectColor(Cursor,10,100,0,155)
if GetRawMouseRightState()=1
if theObjectHit>1999 then SetObjectPosition(Cursor,GetObjectX(theObjectHit),GetObjectY(theObjectHit),GetObjectz(theObjectHit))
SetObjectColor(Cursor,100,10,0,155)
endif
if GetRawMouseLeftPressed()=1
if GetObjectExists(NewElement)=1 then NewElement=NewElement+1
if GetRawMouseRightState()=0
SetObjectColor(Cursor,10,100,0,155)
CreateObjectBox(NewElement,10,10,10)
SetObjectPosition(NewElement,GetObjectX(Cursor),GetObjectY(Cursor),GetObjectz(Cursor))
Shadow_AddObject(NewElement)
endif
if GetRawMouseRightState()=1 and theObjectHit>1999
Shadow_RemoveObject(theObjectHit)
DeleteObject(theObjectHit)
endif
endif
//----------------------------------------------------
// informations
//----------------------------------------------------
Print(ScreenFPS())
info$="LMB=Create/RMB+LMB=Delete/MMB=Rotate Cam"
Print(info$)
Shadow_Update()
Sync()
//----------------------------------------------------
loop
function Click3dObject()
SetObjectPosition(Cursor,-1000,-1000,-1000)
myX as float
myY as float
my3dX as float
my3dY as float
my3dZ as float
rayStartX as float
rayStartY as float
rayStartZ as float
rayEndX as float
rayEndY as float
rayEndZ as float
myX=GetPointerX()
myY=GetPointerY()
my3dX=Get3DVectorXFromScreen(myX,myY)
my3dY=Get3DVectorYFromScreen(myX,myY)
my3dZ=Get3DVectorZFromScreen(myX,myY)
rayStartX=my3dX+GetCameraX(1)
rayStartY=my3dY+GetCameraY(1)
rayStartZ=my3dZ+GetCameraZ(1)
rayEndX=800*my3dX+GetCameraX(1)
rayEndY=800*my3dY+GetCameraY(1)
rayEndZ=800*my3dZ+GetCameraZ(1)
theObjectHit= ObjectRayCast(0,rayStartX,rayStartY,rayStartZ,rayEndX,rayEndY,rayEndZ)
Print(theObjectHit)
if theObjectHit>1000
SetObjectPosition(Cursor,GetObjectX(theObjectHit),GetObjectY(theObjectHit)+GetObjectSizeMaxY(theObjectHit)+5,GetObjectz(theObjectHit))
endif
endfunction