sinisterchipmunk / jax

Framework for creating rich WebGL-enabled applications using JavaScript and Ruby
http://jaxgl.com
MIT License
96 stars 16 forks source link

TypeError on intersection test when point of intersection requested #25

Closed sinisterchipmunk closed 12 years ago

sinisterchipmunk commented 12 years ago

Jax.Geometry.Triangle#intersectTriangle receives an optional vec3 to store the point of intersection, but internally the vec3 is eventually passed into Jax.Geometry.Line#intersectLineSegment, which expects a Jax.Geometry.Line and not a vec3. This causes the following rather spectacular barf:

TypeError: Cannot set property '0' of undefined
    at Object.set (http://localhost:3000/assets/glMatrix.js?body=1:77:10)
    at klass.intersectLineSegment (http://localhost:3000/assets/jax/geometry/line.js?body=1:100:26)
    at slow_tri_tri_intersect (http://localhost:3000/assets/jax/geometry/triangle.js?body=1:25:13)
    at klass.intersectTriangle (http://localhost:3000/assets/jax/geometry/triangle.js?body=1:225:24)

Not only must this be resolved, a smarter implementation would check whether dest is a vec3 or Line. If it is a vec3, then it should be populated with the center point of the intersecting line, to avoid biasing the collision point towards A or B along the line.

The offending code is in the slow_tri_tri_intersect function, but the resolution could conceivably be added to intersectLineSegment for better results with vec3.