www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: AGP on October 23, 2018, 06:59:02 am

Title: Mouse-Walking on a Simple Plane
Post by: AGP on October 23, 2018, 06:59:02 am
I've made three dozen attempts. I have had success on a plane with multiple polygons, but I'd like to make it work on a large plane with only two triangles. My best (unsuccesful) attempt:

Code: [Select]
     public void mouseClicked(MouseEvent e) {
        moveByMouse(e.getX(), e.getY());
     }
     private void moveByMouse(int mouseX, int mouseY) {//WALKBYMOUSE; CALLED ONCE TO SETUP THE WALK DIRECTION
SimpleVector ray = Interact2D.reproject2D3DWS(camera, buffer, mouseX, mouseY);
if (ray != null) {
     SimpleVector norm = ray.normalize();

     float f = theWorld.calcMinDistance(camera.getPosition(), norm, 1000);
     if (1==1/*f != Object3D.COLLISION_NONE*/) {
SimpleVector offset = new SimpleVector(norm);
norm.scalarMul(f);
norm = norm.calcSub(offset);
origin = hero.getRoot().getTransformedCenter();
SimpleVector destination = new SimpleVector(norm);
destination.x += camera.getPosition().x;
destination.z += camera.getPosition().z;
destination.y = origin.y; // Make y the same as for the hero to avoid moving up/down.
hero.getRoot().setRotationMatrix(destination.calcSub(origin).getRotationMatrix());
this.destination = new SimpleVector(destination);
     }
}
go = true;
     }
Title: Re: Mouse-Walking on a Simple Plane
Post by: EgonOlsen on October 23, 2018, 08:39:16 am
The same method that works on planes with multiple polygons will work on planes with two polygons. The logic is the same, but you might have to adjust Config.collideOffset to some higher value.
Title: Re: Mouse-Walking on a Simple Plane
Post by: AGP on October 23, 2018, 07:14:50 pm
Should the above code work? Am I forgetting anything?
Title: Re: Mouse-Walking on a Simple Plane
Post by: EgonOlsen on October 24, 2018, 08:21:23 am
Looks ok to me at first glance. Is this what works with multi-polygon planes? Then it will work with 2 polygonal planes as well if it's able to detect the actual collision/intersection, which depends on the offset setting mentioned above.