Author Topic: Scale many objects together  (Read 1726 times)

Offline rtSJ

  • byte
  • *
  • Posts: 21
    • View Profile
Scale many objects together
« on: April 22, 2014, 02:57:34 pm »
Hello everyone.

I have a problem when I want to scale an object in my world. Because this object is made by a lot de Object3D and when I scale every Object3D, they overlap and don't keep the uniformity of the object (The position of the object between each one).

One solution is to merge all the Object3D, but it wont work because I need to keep all Object3D separate because I want to detect an input on one part.

Anyone had a solution ? Or an idea maybe ?
« Last Edit: April 28, 2014, 11:58:59 am by rtSJ »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11775
    • View Profile
    • http://www.jpct.net
Re: Scale many objects together
« Reply #1 on: April 22, 2014, 08:09:37 pm »
I might help to know what these objects actually resemble to find a fitting solution.

Offline rtSJ

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Scale many objects together
« Reply #2 on: April 23, 2014, 09:14:21 am »
Okay, so here's 3 images that can explain my problem.

The first image is my object (In blender, but it's the same rendering with jPCT). It's a lot of sub parts.


The second is all of the parts of the object can be separate, moved and colored independently.


But I want to scale my model and keep the uniformity (Here, it's only a scale on the Y axis, but it's just an example).


I can put an other image of what happens if I scale using jPCT if you don't understand my problem. Tell me and I upload that, it's not a problem.

Offline Lobby

  • int
  • **
  • Posts: 66
    • View Profile
    • flowersoft
Re: Scale many objects together
« Reply #3 on: April 23, 2014, 10:00:10 am »
I'm not sure, but may it work to add all your objects to an empty parent object which you scale instead?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11775
    • View Profile
    • http://www.jpct.net
Re: Scale many objects together
« Reply #4 on: April 23, 2014, 10:21:23 am »
I understand the problem...but i would like to take a step back and ask: Why do you want to scale them in the first place? Maybe there's another solution than scaling...

Offline rtSJ

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Scale many objects together
« Reply #5 on: April 23, 2014, 10:36:15 am »
@Lobby : Ah yes, maybe. I will test it soon !

@EgonOlsen : Because I want that the user can up and down the size of the model. And you think about zoom in and zoom out with the camera maybe ? I already think about it and it's not working because the model can be a house and I want the user move into the model. So I can't zoom, the camera is used to do something else than up and down the size of the model.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11775
    • View Profile
    • http://www.jpct.net
Re: Scale many objects together
« Reply #6 on: April 23, 2014, 08:49:29 pm »
Adding a common parent won't help here, i'm afraid. It's only natural that this happens...imagine a parking lot...if you start to enlarge all the cars, they would also start to "intersect" unless you move them away from each other in addition. It's an interesting problem and i'm not sure how to solve it. However, i think it depends on how the objects' space is defined. If they all exist in one large object space (i.e. if the oven is 10 units above the ground, it actually is 10 units above it in object space too) or if they all have an object space of their own and are moved into position by translations.
Maybe you should really post that screen shot that shows the actual problem.

Offline lawless_c

  • int
  • **
  • Posts: 91
    • View Profile
Re: Scale many objects together
« Reply #7 on: April 25, 2014, 04:04:08 pm »
okay i think i have it.

Consider scaling as a percentage.
get the offset of each object from the centre object and divide by 100.
multiply that answer by the percentage change in scale.
Add that answer to the position of the object.

Offline rtSJ

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Scale many objects together
« Reply #8 on: April 28, 2014, 10:14:25 am »
Hum, maybe it can works, I try but I think I don't understand the operations. I do that :
Code: [Select]
double d = Math.pow(model.getCenter().x - center.x, 2);
d += Math.pow(model.getCenter().y - center.y, 2);
d += Math.pow(model.getCenter().z - center.z, 2);
d = Math.sqrt(d);
d /= 100;
float factor = (float) (s*100*d);
model.translate(factor, factor, factor);

But the result is not okay. I think I have smething wrong, but I don't understand what... Can you precise your method ?

Edit : In log, for one object I have d=0.02338... and factor=4.677... It's seems correct?
« Last Edit: April 28, 2014, 10:32:25 am by rtSJ »

Offline rtSJ

  • byte
  • *
  • Posts: 21
    • View Profile
Re: Scale many objects together
« Reply #9 on: April 28, 2014, 11:58:09 am »
Okay, so I found a solution and it works. Just when I scale objects, I put this :

Code: [Select]
model.setRotationPivot(center);
center is a SimpleVector same for all the objects. And it keep the uniformity of the model when I scale any objects.

Thank you all !