camera.getPosition() a copy?

Started by .jayderyu, December 30, 2008, 11:26:19 AM

Previous topic - Next topic

.jayderyu

ok so i'm slowly hacking away at getting my core elements going  :P

I've come across a pecularity that came up. I am using LuaJ. It has the problem that it's internvalues don't refer back to floats naturaly in it's enviroment. So if I
camera:setPosition(1.0, 2.0, 3.0); // in lua. This will fail. Ok so I came up with a solution

SimplerVector v = camera:getPosition(); //get the simplevector
bridge:setSimpleVector(v, 1.0, 2.0, 3.0);
 
this doesn't work, no error though. this is my custom class that converts the lua values to floats in the java enviro.

I can however do this
camera:setPosition(bridge:createSimpleVector(1.0, 2.0, 3.0));  this however creates a new SimpleVector

It seems that geting the camera position get's a copy not the the actual vector that camera uses. Am I doing something wrong?
Also if there is no other solution will creating a new SimpleVector per camera update cause a memory problem?




.jayderyu

I'm really stupid sometimes. While I can't find an ideal solution. I at least have one to avoid any memory mis management problems.


local cameraTask = luajava.createProxy("sre.util.Task",
  {
   update = function()
     position = camera:getPosition(); -- get copy? of current camera position. updating purposes
     --when updating the camera, x&y match the player. eventually
     bridge:setSimpleVector(position, 150, -60, -150); -- set the new position into the vector
     camera:setPosition(position);  --apply the vector
     
     bridge:setSimpleVector(position, 0,0,0); -- repeat above
     camera:lookAt(position);
   end
  });


I would still like to know if getPosition is a copy or if i'm doing something wrong :)

EgonOlsen

Yes, it's a copy. The reason for this is, that the camera itself doesn't store the value this way, so i have to create a new instance every time you call that method.

.jayderyu

thank you. It's helpful knowledge. I now know not to continue looking for a better solution.