GeRayCollider
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/06/2011 at 02:20, xxxxxxxx wrote:
Hi,
I'm using this script to check out the GeRayCollider - class.
But there are some things I don't understand.1. Even when I set the Rays length to 1 in ray.Intersection(), there is an intersection, although there are elss intersections, there shouldn't be any !
2. I get multiple intersections for each "real" intersection. Testing on a cube, I get 4 Intersections, with only 2 expected. The other 2 Intersections are at the same point as the original ones.
Testing on a Sphere i get 6 Intersections, but I do expect onl 2.3. The object's rotation is not recognized. How do I prevent from this ?
Thanks, Niklas !
The Script:
import c4d from c4d.utils import GeRayCollider def main() : if not op: print "No object selected." return if not op.CheckType(c4d.Opolygon) : print "Must be a Polygon Object." return ray = GeRayCollider() ray.Init(op) v1 = c4d.Vector(300,0,0) v2 = c4d.Vector(-300,0,0) print ray.Intersect(v1, v2, 20) cnt = ray.GetIntersectionCount() for i in xrange(cnt) : obj = c4d.BaseObject(c4d.Osphere) obj[c4d.PRIM_SPHERE_RAD] = 5 sct = ray.GetIntersection(i) pos = sct["hitpos"] obj.SetAbsPos(pos) doc.InsertObject(obj) obj.Message(c4d.MSG_UPDATE) print pos main()
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 17/06/2011 at 09:43, xxxxxxxx wrote:
Did you ever figure out how this works?
I have been wondering about this too.The ray collision is always off until the distance value reaches 100.
Then the collision is always on. Regardless of where the object is. In relation to the origin of the ray.import c4d from c4d.utils import GeRayCollider def main() : obj = doc.SearchObject("Cube") # The object the ray collides with ray = GeRayCollider() # Create a new GeRayCollider object ray.Init(obj) # Assign the object to a variable start = c4d.Vector(0 ,0, 0) #The position of the ray's origin direction = c4d.Vector(1, 0, 0) #The direction it points distance = 100 CollisionState = ray.Intersect(start, direction, distance) cnt = ray.GetIntersectionCount() gi = ray.GetIntersection(0) nearest = ray.GetNearestIntersection() print CollisionState print gi print nearest main()
-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/06/2011 at 13:40, xxxxxxxx wrote:
Still pushing.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/06/2011 at 16:38, xxxxxxxx wrote:
Create a Cube and a Null.
Make the Cube editable and then add a python tag to one of them and put this code in it:import c4d from c4d.utils import GeRayCollider def main() : sourceobj = doc.SearchObject("Null") # The object the ray will start from targetobj = doc.SearchObject("Cube") # The object the ray collides with ray = GeRayCollider() # Create a new GeRayCollider object ray.Init(targetobj, True) # Assign the object to a variable start = sourceobj.GetAbsPos() direction = c4d.Vector(1, 1, 1) #The direction the ray points. #In this case we shoot a ray out in each direction distance = 100 CollisionState = ray.Intersect(start, direction, distance) if CollisionState: targetobj[c4d.ID_BASEOBJECT_XRAY] = True else: targetobj[c4d.ID_BASEOBJECT_XRAY] = False main()
This way the Cube's X-Ray state let's you easily see the collision state occurring.
Notice that if you move the target object(the Cube) you don't get any collisions.
But if you move the the source object(the ray object). The collision state will change._ But_....
It's not changing based on the "collision" between the two objects.
It's changing based on the position of the source object. Compared to the length of the ray(the distance value).Houston...We have a problem.
-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/06/2011 at 04:32, xxxxxxxx wrote:
As far as I remember, I had the same issues when building my collision detection with the RayCollider. Somehow I just ignored all the wrong results and built my way around it.
So, I wil do this: PUSH
Cheers,
maxx -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/06/2011 at 05:00, xxxxxxxx wrote:
direction = c4d.Vector(1, 1, 1) #The direction the ray points.
#In this case we shoot a ray out in each directionDidn't test it yet. But why do we shoot out a ray in each direction ? This is only one direction, the direciton 1,1,1 What my experience tells me is, when you have a ray directing to 1,1,1 starting at 0,0,0 with a length of 10, you won't get intersections behinder 1,1,1 because the ray does end there. I'm not sure if this is right, but this is my experience with it, yet.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/06/2011 at 08:50, xxxxxxxx wrote:
I did that way so you would see the results no matter which direction you moved the Null:
direction = c4d.Vector(1, 0, 0)= Only produces collision results when moving the Null in X direction = c4d.Vector(0, 1, 0)= Only produces collision results when moving the Null in Y direction = c4d.Vector(0, 0, 1)= Only produces collision results when moving the Null in Z
direction = c4d.Vector(1, 1, 1)= collision results when moving the Null in any direction.
It sounds like we're all having problems with it.
Bump!-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/06/2011 at 09:04, xxxxxxxx wrote:
Ahh, I did now check it and see what you mean. Yes, the GeRayCollider does use the points positions relative to "Cube" and does not multiply them with the Cubes matrix.
Very unfortunate. -.-Yep, we have problems with it!