Lineofsight3d help

Blitz3D Forums/Blitz3D Programming/Lineofsight3d help

ace33(Posted 2007) [#1]
hi I am working with the lineofsight3d function, which can be found here ---http://www.blitzbasic.com/codearcs/codearcs.php?code=532--- and can only get it to work with objects such as a cone,circle ect. I am trying to get a loaded MD2 model, or any other model such as .B3d ect., to use the function but it always returns false.

Any help would be very welcome
thank you


Stevie G(Posted 2007) [#2]
Not sure but doubt animated models will work as the function relies on the mesh geom being pickable.

This slight modification will work with non-pickable meshes but is not as accurate as you can see ...



An alterative would be to create a cube or sphere, scale it for an approximate fit to your mesh , set entityalpha to 0, set pickmode to 2 and parent your animated mesh to this cube.

Stevie


ace33(Posted 2007) [#3]
hey, thanks for the quick responce, but I dont think the pick mode is my problem.I can get objects(like a cone,cube ect.) to see the loaded mesh's but I cant get loaded mesh's to see anything else

for example
visible2 = LineOfSight3D(enemy\entity,c4,vd,va) doesnt work but
visible2 = LineOfSight3D(c3,enemy\entity,vd,va)
does The C3 is just the cone from the LINEOFSIGHT3d code and C4 is the circle


Stevie G(Posted 2007) [#4]
Strange. I could take a look if you e-mail me the model and code.


ace33(Posted 2007) [#5]
hey, thanks this is the non-working parts of the LINEOFSIGHT3d function, any help would be more than welcome... you will need to replace the enemy with your own model

vd# = 100.0
va# = 90.0

visible2 = LineOfSight3D(enemy\entity,c4,vd,va)

Function LineOfSight3D(observer,target,viewrange#=10.0,viewangle# = 90.0)

Local dist# = EntityDistance(observer,target);
If dist<=viewrange

TFormVector 0,0,1,observer,0
Local ox# = TFormedX()
Local oy# = TFormedY()
Local oz# = TFormedZ()

Local dx# = (EntityX(target,True)-EntityX(observer,True))/dist#
Local dy# = (EntityY(target,True)-EntityY(observer,True))/dist#
Local dz# = (EntityZ(target,True)-EntityZ(observer,True))/dist#

Local dot# = ox*dx + oy*dy + oz*dz
If dot => Cos(viewangle/2.0)
If LinePick(EntityX(observer,True),EntityY(observer,True),EntityZ(observer,True),dx*viewrange,dy*viewrange,dz*viewrange,0.01)=target
Return True
End If
End If

End If

Return False
End Function


here is the enemy

Global enemy.enemy = New enemy
enemy\entity = LoadMD2("MODEL.md2")
ScaleEntity enemy\entity,0.04,0.04,0.04
pogo_tex = LoadTexture("mesh.bmp")
EntityTexture enemy\entity,pogo_tex
PositionEntity enemy\entity,25,6,120
RotateEntity enemy\entity,0,180,0
AnimateMD2 enemy\entity,1,0.1,41,46
EntityRadius enemy\entity,.9
EntityType enemy\entity,ENEMY_TYPE
EntityShininess enemy\entity,1
enemy\x# = 0
enemy\y# = 200
enemy\responce=IDLE
enemy\z# = 50
enemy\state = IDLE
enemy\life# = 100.0
enemy\range# = 50.0
enemy\botty=enemy\entity
enemy\current_waypoint=1
EntityPickMode enemy\entity,1

and here is a target

c4=CreateSphere()
EntityColor c4,128,50,50
PositionEntity c4,2,1,-6
EntityPickMode c4,2
HidePointer


fredborg(Posted 2007) [#6]
Ah, I think it's because you are using the sphere picking mode for the enemy. And unlike polygon picking mode, it will compute a pick even if the linepick is done from inside the sphere and out. To avoid it you can offset the linepick from the enemy first.

Try with this version:

And set the offset parameter so it is larger than the radius of the enemy... That should work. I think :)