Hi all,
I have run into an annoying problem and for the life of me cannot work out why my program is behaving the way it is.
I have written a routine that is supposed to fade objects out as they approach a specified distance from the player.
The alpha value is determined by a percentage value derived from the objects distance vs the cutoff distance.
the simple formula for a percentage should be 100/maxscale*value right?
my program is not behaving this way and no matter how I tweak it I just get a value of 100.
I have gone over and over it, but it seems I cannot see the solution yet.
here is a simplified program outlining the issue.
The lines of code in question are between the commented XXXXXXXX lines.
// define perameters for grass routine
grassmax = 1000
grassrad = 500
// make grass objects and position them around the camera
for x = 1 to grassmax
make object cube x,5
position object x,-250+rnd(grassrad),0,-250+rnd(grassrad)
rotate object x,0,rnd(180),0
set object transparency x,6
next x
//place camera at face height
position camera 0,72,0
do
control camera using arrowkeys 0,1,1
gosub grass
sync
loop
grass:
for x = 1 to grassmax
//check for grass outside perimeter===============================
if object position x(x) > camera position x()+grassrad then gosub movegrass
if object position x(x) < camera position x()-grassrad then gosub movegrass
if object position z(x) > camera position z()+grassrad then gosub movegrass
if object position z(x) < camera position z()-grassrad then gosub movegrass
//This bit determines the direction of player movement and places the grass in front or behind the direction of movement============================
if upkey() = 1 then Angle = camera angle y()-90 + rnd(180)
if downkey() = 1 then Angle = camera angle y()+90 + rnd(180)
if leftkey() = 1 then Angle = camera angle y() - rnd(180)
if rightkey() = 1 then Angle = camera angle y() + rnd(180)
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//this variable holds the objects distance from the camera
fadedistance = abs(Object_Distance_From_Camera( x ))
//this variable is a percentage value based upon grass distance vs total grass distance
// It is taken from 100 because I want the objects to fade out into the distance rather than fade in
fade = 100-(100/grassrad*fadedistance)
set alpha mapping on x,fade
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
next x
return
movegrass:
//place grass on oposite side of player movement===================================
Distance = grassrad
CirXNewObj = Sin(Angle) * Distance + camera position x()
CirYNewObj = Cos(Angle) * Distance + camera position z()
position object x, CirXNewObj,0, CirYNewObj
Xrotate object x,object angle x(x)-9+rnd(18)
return
Function Distance_From_Camera( objX# , objY# , objZ# )
thisDistance# = Distance_Between_Points( objX# , objY# , objZ#, camera position x() , camera position y() , camera position z() )
Endfunction thisDistance#
Function Object_Distance_From_Camera( object )
If object > 0
objX#=Object Position X( object )
objY#=Object Position Y( object )
objZ#=Object Position Z( object )
thisDistance2# = Distance_From_Camera( objX# , objY# , objZ# )
Endif
Endfunction thisDistance2#
Function Distance_Between_Objects( obj1 , obj2 )
obj1X#=Object Position X( obj1 )
obj1Y#=Object Position Y( obj1 )
obj1Z#=Object Position Z( obj1 )
obj2X#=Object Position X( obj2 )
obj2Y#=Object Position Y( obj2 )
obj2Z#=Object Position Z( obj2 )
thisDistance# = Distance_Between_Points( obj1X# , obj1Y# , obj1Z#, obj2X# , obj2Y# , obj2Z# )
Endfunction thisDistance#
Function Distance_Between_Points( obj1X# , obj1Y# , obj1Z#, obj2X# , obj2Y# , obj2Z# )
xx# = obj1X# - obj2X#
yy# = obj1Y# - obj2Y#
zz# = obj1Z# - obj2Z#
thisDistance2# = Sqrt((xx#*xx#)+(yy#*yy#)+(zz#*zz#))
Endfunction thisDistance2#
Can anyone see where I am slipping up?
Thankyou.
kezzla
ps: I have tried the formula with float variables and gotten the same result.