I wish I could pull out a simple project, but that would be too much
work as this only happens when you have a whole scene. To replicate
what I'm doing would mean to ray test all the vertices. It looks like
with the lineseg/sphere test, the bounds3D may not enclose the entire
object.
Currently I have a wall that is created by putting a few smaller
walls together.
Here is the piece of simplified code that I used:
dim i,c as Integer
dim bnd as Bounds3D
dim v1,v2 as vector3D
v1=light1.position
v2=vertexposition1//transformed to world coordinates
c=mainview.objects.count-1
for i=0 to c
bnd=mainview.objects(i).bounds
if bnd=NIL then bnd=mainview.objects.computebounds(1)
if LineSegmentIntersection(v1,v2)<>NIL then
mainview.objects(i).Visible=true
else
mainview.objects(i).Visible=False
end if
next
Here is a piece of code that works (should be slower, but it works):
dim i,c as Integer
dim bnd as Bounds3D
dim v1,v2,pnt1,pnt2 as vector3D
v1=light1.position
v2=vertexposition1//transformed to world coordinates
camera.position.copy v1
pointobjectat camera,v2
pnt2=camera.WorldToObjectTransform(v2)
c=mainview.objects.count-1
for i=0 to c
bnd=mainview.objects(i).bounds
if bnd=NIL then bnd=mainview.objects.computebounds(1)
pnt1=camera.WorldToObjectTransform(bnd.Center)
if (pnt1.x-bnd.Radius<0 and pnt1.x+bnd.Radius>0) and (pnt1.y-
bnd.Radius<0 and pnt1.y+bnd.Radius>0) and (pnt1.z-bnd.Radius<v4.z and
pnt1.z+bnd.Radius>0) then
if LineSegmentIntersection(v1,v2)<>NIL then
mainview.objects(i).Visible=true
else
mainview.objects(i).Visible=False
end if
end if
next
I'm trying to see if a sphere object is within a line segment
(formed by 2 points in word coordinates), but the results it
returns are incorrect. Some objects that should have intersected
returned negative (or NIL). The same holds true for
LineIntersection. Am I using it correctly?
Hard to say. Can you post a code snipped that demonstrates the
problem?
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|