How to resize an object?
-
On 09/01/2014 at 13:09, xxxxxxxx wrote:
Howdy,
Originally posted by xxxxxxxx
Yes. And so far I don't see how to do it.
You scale the geometry's vertices.
Adios,
Cactus Dan -
On 09/01/2014 at 13:25, xxxxxxxx wrote:
I have no idea how to scale the vertices.. if you could give me a hint Dan, I would appreciate it!
Here is an update, and a piece of code that does what I want, with one exception, it does scale the object in question, which I don't want.void ResizeToModel(GeListNode* node, BaseObject* model, BaseObject* victim) { BaseDocument* doc = node->GetDocument(); if(doc && model && victim) { Vector vModel = model->GetRad(); Vector vVictim = victim->GetRad(); Real scaleX = (vModel.x / vVictim.x) * model->GetRelScale().x; Real scaleY = (vModel.y / vVictim.y) * model->GetRelScale().y; Real scaleZ = (vModel.z / vVictim.z) * model->GetRelScale().z; doc->StartUndo(); doc->AddUndo(UNDOTYPE_CHANGE_SMALL, victim); victim->SetAbsScale(Vector(scaleX, scaleY, scaleZ)); doc->EndUndo(); } }
In hindsight.. maybe I should use victim->SetRelScale(..) ??
Edited:
Ok, this code is not perfect, I am currently experimenting and trying to improve it. -
On 10/01/2014 at 01:15, xxxxxxxx wrote:
To scale the vertices move them in object space. E.g. to double the size, if a vertex has X=100, move it so that X=200. Repeat with Y & Z, and iterate through all vertices in the object. At the end, your object has twice the size but the same scale in its matrix.
Steve
-
On 10/01/2014 at 01:49, xxxxxxxx wrote:
Originally posted by xxxxxxxx
To scale the vertices move them in object space.
Thanks Steve! I will try to find out how to get hold of the vertices, and then how to move them in object space.
I started another thread here in this forum yesterday, where I wish for a library / collection of common functions for moving / resizing / measuring objects in 3D space.As it is now, we plugin writers probably sit around in our own caves, building up such libraries. Each of us.. One library pr. developer..
In other words - wrapping up the C4D SDK API in common functions with readable understandable English names, functions we use all the time. -
On 10/01/2014 at 07:11, xxxxxxxx wrote:
Originally posted by xxxxxxxx
I will try to find out how to get hold of the vertices, and then how to move them in object space.
Do it like this:
Vector *padr = ToPoint(object)->GetPointW(); // get the object's points array LONG i, cnt = ToPoint(object)->GetPointCount(); // get the object's point count // loop through the points and scale them for(i=0; i<cnt; i++) { padr[i].x = padr[i].x * scale.x; padr[i].y = padr[i].y * scale.y; padr[i].z = padr[i].z * scale.z; }
Adios,
Cactus Dan -
On 10/01/2014 at 15:57, xxxxxxxx wrote:
Howdy Dan
Super Duper!!!
By combining your post, with the one of Robert, I made it work. At first, nothing happened, then I saw Robert had added the message end event stuff, now it is magic, it works!!Vector* padr = ToPoint(cubeA)->GetPointW(); // get the object's points array LONG i, cnt = ToPoint(cubeA)->GetPointCount(); // get the object's point count Vector scale = Vector(0.5); // loop through the points and scale them for(i = 0; i < cnt; i++) { padr[i].x = padr[i].x * scale.x; padr[i].y = padr[i].y * scale.y; padr[i].z = padr[i].z * scale.z; } cubeA->Message(MSG_CHANGE); EventAdd();
I have to add though, why scaling a point works, is beyond my comprehension.. I just have to accept that is works. If there was a function:
BaseArray<Vertice*> padr = ToPoint(cubeA)->GetVerticeW();
I could have understood it. Ok, it is me, I just have to understand not only how, but why things work..
Greetings from cold Norway and a warm programmer's cave -
On 11/01/2014 at 10:27, xxxxxxxx wrote:
You're not scaling a point, it's a misnomer. What you're doing is changing the vertex position relative to the object axis. The effect is to make the object look bigger (or smaller) but the scale of the object remains the same.
That's why I said you have to move the points in object space. If you step through Dan's code for the eight points of a cube, you'll see what I mean.
Steve
-
On 11/01/2014 at 11:14, xxxxxxxx wrote:
Hi Steve, yes I thought about it since my last post, and understand it now. The words move, transfer, translate, shift etc. instead of scale would have made it more understandable for me I suppose.
It is my fault, mixing "scale" and "move", since you wrote "move".
In any case, it works very well!! -
On 11/01/2014 at 11:26, xxxxxxxx wrote:
Howdy,
The thing to remember is that there is a distinct difference between size and scale. Think of it as when you were 6 years old, your size was small but your scale was 1. At your current age, your size is larger but your scale is still 1.
Adios,
Cactus Dan -
On 11/01/2014 at 12:30, xxxxxxxx wrote:
Originally posted by xxxxxxxx
Think of it as when you were 6 years old, your size was small but your scale was 1. At your current age, your size is larger but your scale is still 1.
Howdy!
A good comparison, indeed.
Although, when it comes to the local politicians here, I am not sure about to what extent that rule of scaling applies -
On 11/01/2014 at 12:34, xxxxxxxx wrote:
Howdy,
Yes indeed. Politicians everywhere always think their scale is bigger than 1.
Adios,
Cactus Dan