realbasic-games
[Top] [All Lists]

Re: Bug? LineSegmentIntersection

To: REALbasic Games <realbasic-games at lists dot realsoftware dot com>
Subject: Re: Bug? LineSegmentIntersection
From: Lo Saeteurn <realbasic at miensoftware dot com>
Date: Wed, 21 Sep 2005 09:52:16 -0700
Delivered-to: realbasic-games at lists dot realsoftware dot com
References: <A62133C5-26E7-4F77-85C7-3CBD6D5AC3CA at miensoftware dot com> <a06200716bf573a7915d2 at [10 dot 0 dot 1 dot 4]>
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>

<Prev in Thread] Current Thread [Next in Thread>