Author Topic: reproject2D3DWS for Walking with Mouse  (Read 1144 times)

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
reproject2D3DWS for Walking with Mouse
« on: December 06, 2011, 05:10:01 pm »
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.

Code: [Select]
     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);
     }
}
     }
« Last Edit: December 06, 2011, 05:14:23 pm by AGP »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: reproject2D3DWS for Walking with Mouse
« Reply #1 on: December 06, 2011, 09:51:04 pm »
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:

Code: [Select]
Matrix mat = theCamera.getBack();
mat = mat.invert3x3();
norm.matMul(mat);

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

Code: [Select]
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.


Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: reproject2D3DWS for Walking with Mouse
« Reply #2 on: December 07, 2011, 12:33:18 am »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: reproject2D3DWS for Walking with Mouse
« Reply #3 on: December 07, 2011, 10:10:40 am »
Yep, that one.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: reproject2D3DWS for Walking with Mouse
« Reply #4 on: December 08, 2011, 06:57:49 am »
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.