Scale many objects together

Started by rtSJ, April 22, 2014, 02:57:34 PM

Previous topic - Next topic

rtSJ

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 ?

EgonOlsen

I might help to know what these objects actually resemble to find a fitting solution.

rtSJ

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.

Lobby

I'm not sure, but may it work to add all your objects to an empty parent object which you scale instead?

EgonOlsen

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...

rtSJ

@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.

EgonOlsen

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.

lawless_c

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.

rtSJ

#8
Hum, maybe it can works, I try but I think I don't understand the operations. I do that :

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?

rtSJ

Okay, so I found a solution and it works. Just when I scale objects, I put this :

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 !