ToxicLibs Line Mesh Intersection
in
Contributed Library Questions
•
11 months ago
Hello,
I'm trying to get intersection of the line with any mesh geometry (in this case simple plane) and to draw a box at the intersecting point (in library examples there is one called RayReflectSphere that does similar things – but it works for sphere only).
Here is the script I've got so far… but it seems there is something wrong here
Thanks in advance for help
- import processing.core.PApplet;
import toxi.geom.AABB;
import toxi.geom.Intersector3D;
import toxi.geom.IsectData3D;
import toxi.geom.Plane;
import toxi.geom.Ray3D;
import toxi.geom.Ray3DIntersector;
import toxi.geom.ReadonlyVec3D;
import toxi.geom.TriangleIntersector;
import toxi.geom.Vec3D;
import toxi.processing.ToxiclibsSupport;
public class Main extends PApplet
{
Vec3D pos = new Vec3D (0,200,200);
Vec3D target = new Vec3D (0,-50,0);
Vec3D dir = target.sub(pos).normalize();
ToxiclibsSupport gfx;
Vec3D camRot = new Vec3D();
Plane p;
Ray3D ray;
Ray3DIntersector isec;
public void setup()
{
size(600,600,OPENGL);
gfx = new ToxiclibsSupport (this);
p = new Plane();
}
public void draw()
{
background(120);
translate(width/2, height/2, 0);
camRot.interpolateToSelf(new Vec3D(mouseY*0.01f,mouseX*0.01f,0),(float) 0.05);
rotateX(camRot.x);
rotateY(camRot.y);
ray = new Ray3D(pos,dir);
isec = new Ray3DIntersector(ray);
IsectData3D info = isec.getIntersectionData();
ReadonlyVec3D isectPos=info.pos;
stroke(0);
gfx.plane(p, 200);
stroke(0,255,0);
gfx.line(pos, target);
gfx.box(new AABB(isectPos,5));
}
}
1