my decal example
rem
rem AGK Application 2017.05.15
rem 3D Shooter decal
rem MR 16.05.2017
rem Landscape App
SetDisplayAspect( 4.0/3.0 )
setdefaultwrapu(0)
setdefaultwrapv(0)
//------------------------------------------ Cam
cameraID=1
SetCameraRange( cameraID, 1, 1000 )
SetCameraPosition( cameraID, 0,2,-10 )
SetCameraLookAt( cameraID, 0, 0, 5, 0 )
//------------------------------------------ Light
SetSunActive(1)
SetSunColor(255, 255, 255)
SetSunDirection(0, -1, 1)
//------------------------------------------ Ground
iGround=CreateObjectBox( 100, 0.01, 100 )
SetObjectCollisionMode( iGround, 1 ) //<<<<
SetObjectColor( iGround, 128,255,128,255 )
SetObjectLightMode(iGround,1)
//------------------------------------------ Cube
iBox=CreateObjectBox( 1, 1, 1 )
SetObjectPosition( iBox, 0, 0.5, 4 ) //+1
SetObjectCollisionMode( iBox, 1 ) //<<<<
SetObjectColor( iBox, 255,255,255,255 )
SetObjectLightMode(iBox,1)
RotateObjectLocalY( iBox, 45 )
//------------------------------------------ Image decal
imgBlood=loadimage("Blood.png")
//------------------------------------------ Scope
imgScope=loadimage("Scope.png")
sprScope=createsprite(imgScope)
setspritesize(sprScope,4,4)
//------------------------------------------
do
cx#=GetCameraX(1)
cy#=GetCameray(1)
cz#=GetCameraz(1)
mx#=getpointerx()
my#=getpointery()
sx#=Get3DVectorXFromScreen(mx#,my#)*1000.0
sy#=Get3DVectorYFromScreen(mx#,my#)*1000.0
sz#=Get3DVectorZFromScreen(mx#,my#)*1000.0
ObjectRayCast(0,cx#,cy#,cz#,sx#,sy#,sz#)
n=GetObjectRayCastNumHits()
print(n)
for i=0 to n-1
obj = GetObjectRayCastHitID(i)
x#=GetObjectRayCastx(i)
y#=GetObjectRayCastY(i)
z#=GetObjectRayCastz(i)
nx#=GetObjectRayCastNormalX(i)
ny#=GetObjectRayCastNormalY(i)
nz#=GetObjectRayCastNormalZ(i)
tx#=GetScreenXFrom3D(x#,y#,z#)
ty#=GetScreenYFrom3D(x#,y#,z#)
setspritepositionbyoffset(sprScope,tx#,ty#)
next
if getpointerpressed()=1
iBlood=createobjectplane(0.5,0.5)
SetObjectLightMode(iBlood,1)
SetObjectPosition(iBlood,x#+nx#*0.1,y#+ny#*0.1,z#+nz#*0.1)
SetObjectLookAt(iBlood,x#+nx#*1.0,y#+ny#*1.0,z#+nz#*1.0,0)
SetObjectTransparency( iBlood, 1 )
setobjectimage(iBlood,imgBlood,0)
SetObjectCollisionMode( iBlood, 0 ) //<<<<
endif
Sync()
loop
end
AGK (Steam) V2017.03.31 : Windows 10 Pro 64 Bit : AMD (17.2.1) Radeon R7 265 : Mac mini OS Sierra (10.12.2)