Author Topic: Scaling objects dynamically  (Read 3842 times)

Offline thiamant

  • byte
  • *
  • Posts: 19
    • View Profile
Scaling objects dynamically
« on: October 07, 2010, 07:48:15 pm »
I'm trying to scale a model dynamically when the model is already running and visible. Do I have to rebuild the object or something like that? After calling .scale() method the object disappears and I can only see the framebuffer empty (with the background colour).

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Scaling objects dynamically
« Reply #1 on: October 07, 2010, 08:44:06 pm »
Then you are most likely using scale() wrong. Can you post some code?

Offline thiamant

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Scaling objects dynamically
« Reply #2 on: October 07, 2010, 09:34:36 pm »
Code: [Select]
object.disableLazyTransformations();
object.scale(1.5f);
object.enableLazyTransformations();

I do this in the onDraw method if certains conditions are met. This is done before this code:

Code: [Select]
fb.clear(skycolor);
world.renderScene(fb);
world.draw(fb);

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Scaling objects dynamically
« Reply #3 on: October 07, 2010, 09:36:35 pm »
Remember that scale() is cummulative...try setScale() instead.

Offline thiamant

  • byte
  • *
  • Posts: 19
    • View Profile
Re: Scaling objects dynamically
« Reply #4 on: October 08, 2010, 10:56:01 pm »
OK. I'm trying to use setScale and apparently it's scaling correctly. The problem is that I don't appreciate any distance increase from the center of the model. Imagine a theatre and the camera pointing to a door from the center of the theatre. When scaling the whole object the door should be seen far away but it's not. I've tried increasing the FOV but with higher values the optical effect is just too bad.

Any ideas about why this is happening and possible solutions? Maybe I'm just getting the concept wrong (scaling effect and such).

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Scaling objects dynamically
« Reply #5 on: October 08, 2010, 11:03:18 pm »
Maybe you are looking at the center of the object, which doesn't change when scaling the whole thing around it? Or maybe the effect is just too subtle because the location in view already is pretty far away. Some screen shots might help to understand this better...

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Scaling objects dynamically
« Reply #6 on: September 29, 2011, 01:53:57 pm »
I use Object3D.setScale() to rescale an object, but the mesh is not scaled with the object.

I realize that I can delete the object and reload it with the new scale value, but I would like to avoid that.

What function do I call to recreate the mesh on the fly based on the new scale?
(It doesn't matter if the function takes a second or two)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Scaling objects dynamically
« Reply #7 on: September 29, 2011, 08:32:58 pm »
It should be possible to abuse the rotateMesh-method for this. Set your scale, call rotateMesh(), set it back to 1.
« Last Edit: September 30, 2011, 10:28:10 am by EgonOlsen »

Offline K24A3

  • long
  • ***
  • Posts: 231
    • View Profile
Re: Scaling objects dynamically
« Reply #8 on: September 30, 2011, 10:08:49 am »
rotateMesh() did the trick, thanks.