reproject2D3DWS for Walking with Mouse

Started by AGP, December 06, 2011, 05:10:01 PM

Previous topic - Next topic

AGP

What does this method look like with the now-existing reproject2D3DWS? I've been trying everything intuitive and it hasn't been working for me. I'm hoping, by the way, to no longer need the collision bit (so I won't need the 3D planes per screen). Thanks in advance.


     private void moveByMouse() {//WALKBYMOUSE; CALLED ONCE TO SETUP THE WALK DIRECTION
mouseWalk = true;
SimpleVector ray = Interact2D.reproject2D3D(theCamera, buffer, mouseX, mouseY);
currentRoom.plane.setVisibility(true);
if (ray != null) {
     SimpleVector norm = ray.normalize();
     Matrix mat = theCamera.getBack();
     mat = mat.invert3x3();
     norm.matMul(mat);

     SimpleVector ws = new SimpleVector(ray);
     ws.matMul(theCamera.getBack().invert3x3());
     ws.add(theCamera.getPosition());

     float f = theWorld.calcMinDistance(theCamera.getPosition(), norm, 1000);
     if (1==1/*f != Object3D.COLLISION_NONE*/) {
SimpleVector offset = new SimpleVector(norm);
norm.scalarMul(f);
norm = norm.calcSub(offset);
SimpleVector heroCenter = hero.getTransformedCenter();
SimpleVector destination = new SimpleVector(norm);
destination.x += theCamera.getPosition().x;
destination.z += theCamera.getPosition().z;
destination.y = heroCenter.y; // Make y the same as for the hero to avoid moving up/down.
hero.setRotationMatrix(destination.calcSub(heroCenter).getRotationMatrix());
target = new SimpleVector(destination);
     }
}
     }

EgonOlsen

That code is confusing...the ws-vector is calculated, but never used...if you remove that part, the only thing that isn't needed anymore when using the ...WS-method instead, is this:


Matrix mat = theCamera.getBack();
mat = mat.invert3x3();
norm.matMul(mat);


You can simply remove this. So the result should be:


private void moveByMouse() {//WALKBYMOUSE; CALLED ONCE TO SETUP THE WALK DIRECTION
mouseWalk = true;
SimpleVector ray = Interact2D.reproject2D3DWS(theCamera, buffer, mouseX, mouseY);
currentRoom.plane.setVisibility(true);
if (ray != null) {
     SimpleVector norm = ray.normalize();
   
     float f = theWorld.calcMinDistance(theCamera.getPosition(), norm, 1000);
     if (1==1/*f != Object3D.COLLISION_NONE*/) {
SimpleVector offset = new SimpleVector(norm);
norm.scalarMul(f);
norm = norm.calcSub(offset);
SimpleVector heroCenter = hero.getTransformedCenter();
SimpleVector destination = new SimpleVector(norm);
destination.x += theCamera.getPosition().x;
destination.z += theCamera.getPosition().z;
destination.y = heroCenter.y; // Make y the same as for the hero to avoid moving up/down.
hero.setRotationMatrix(destination.calcSub(heroCenter).getRotationMatrix());
target = new SimpleVector(destination);
     }
}
     }


BTW: If you don't want to do it with collisions, you have to do it with math like i did in the other thread about mouse-following, but that approach is limited to some special situations.



EgonOlsen


AGP

Thanks a lot.

By the way, can I have the numbers texture you use on certain things (usually for frame rate count and such)? I got Mizuki's cloth simulator and am playing around with it, but I didn't get the textures (I tried making one with 1..0 ordered horizontally but that didn't fit). I'm fairly sure it's your texture because I've seen it on some of your stuff and you helped her optimize the controller.