Author Topic: modelViewProjectionMatrix  (Read 3735 times)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: modelViewProjectionMatrix
« Reply #15 on: July 24, 2012, 10:06:37 pm »
Object3D.getID() ... Object3D has still same ID or it can be reset?
« Last Edit: July 24, 2012, 10:08:12 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: modelViewProjectionMatrix
« Reply #16 on: July 24, 2012, 10:10:07 pm »
The ids will be assigned by the engine, but you can set/reset the counter. However...why would you want to?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: modelViewProjectionMatrix
« Reply #17 on: July 24, 2012, 10:17:19 pm »
I want to store MVM and IRenderHook in HashMap, render and return all original IRenderHook...

edit: and original shader...
« Last Edit: July 24, 2012, 10:19:30 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: modelViewProjectionMatrix
« Reply #18 on: July 24, 2012, 10:19:42 pm »
Ok, but why do you want to reset the id for that?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: modelViewProjectionMatrix
« Reply #19 on: July 24, 2012, 10:32:57 pm »
I don't want to reset IDs, I thought, that jPCT can reset them in some cases...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: modelViewProjectionMatrix
« Reply #20 on: July 24, 2012, 10:36:36 pm »
I misunderstood you there...no, jPCT doesn't reset the id by itself.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: modelViewProjectionMatrix
« Reply #21 on: July 24, 2012, 10:45:10 pm »
Ok and IDs are also unique between worlds or not?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: modelViewProjectionMatrix
« Reply #22 on: July 24, 2012, 10:48:15 pm »
Yes

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: modelViewProjectionMatrix
« Reply #23 on: July 24, 2012, 10:51:01 pm »
Thanks ;)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: modelViewProjectionMatrix
« Reply #24 on: July 25, 2012, 08:41:44 pm »
Could you add method for get RenderHook from Object3D?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: modelViewProjectionMatrix
« Reply #25 on: July 27, 2012, 07:45:55 pm »
I've added that method. Please download the latest beta jar.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: modelViewProjectionMatrix
« Reply #26 on: July 29, 2012, 08:42:02 pm »
I've added that method. Please download the latest beta jar.

Thanks ;) I can set uniforms per object, now.

I've added support for a new uniform called "projectionMatrix" to the beta jar. The model view matrix can be calculated like this (unoptimized):

Code: [Select]
Matrix mc=new Matrix();
Matrix mv=obj.getWorldTransformation();
mc.setTo(world.getCamera().getBack());
SimpleVector v=world.getCamera().getPosition();
v.scalarMul(-1);
mc.translate(v);
mv.matMul(mc);

In these calculations is small bug. If someone will need it, here is fixed code.

Code: [Select]
private Matrix calcModelViewMatrix(World world, Object3D object) {
Camera cam = world.getCamera();
Matrix mc = new Matrix();
Matrix modelView = object.getWorldTransformation();
Matrix backMatrix = cam.getBack();
mc.setTo(backMatrix);
SimpleVector v = cam.getPosition();
v.scalarMul(-1);
modelView.translate(v);
modelView.matMul(mc);
return modelView;
}