PDA

View Full Version : Creating a Polygon with coffee


Scott Ayers
04-02-2010, 06:57 PM
Using the example about splines Lennart gave as a guide. I tried to expand on it and create a quad polygon object.
I'm almost there. But I'm stuck on the building of the polygon section.
I can build a triangle. But I can't seem to figure out how to build a quad.
////////Create Points Section////////
var mypoly = AllocObject(Opolygon); // the empty object
var pointcount = 4;
var arr = new(array, pointcount);
mypoly->SetPoints(arr);
var vc = new(VariableChanged); // Important
vc->Init(0,pointcount); // Important
mypoly->Message(MSG_POINTS_CHANGED,vc); // Important

mypoly->SetPoint(0,vector(-100,0,-100));
mypoly->SetPoint(1,vector(-100,0,100));
mypoly->SetPoint(2,vector(100,0,100));
mypoly->SetPoint(3,vector(100,0,-100));
doc->InsertObject(mypoly,NULL,NULL);

////////Create Polygon Section////////

var polycount = mypoly->GetPolygonCount();
vc->Init(polycount, polycount+1); // add 1 new polygon
var ok = mypoly->MultiMessage(MSG_POLYGONS_CHANGED, vc);

var p = mypoly->GetPolygon(polycount);

// Create the new poly based on the points
p->a = 0;
p->b = 1;
p->c = 2;
p->d = 3;
p->a = mypoly->GetPointCount()-1; <---Creates a triangle polygon

mypoly->SetPolygon(polycount, p);
mypoly->Message(MSG_UPDATE); // Notify object of change

Can anyone give me a hint?
Am I doing this the right way?

-ScottA

Scott Ayers
04-03-2010, 02:05 PM
Never mind.I found the problem.
I changed the line:
p->a = mypoly->GetPointCount()-1;
to
p->d = mypoly->GetPointCount()-1;


Thanks again Lennart for your great Spline example on the other thread.
I was wondering when I would ever need to use a custom array in C4D. And now I can see how handy they are if you need to build something from scratch without using the built in commands.

-ScottA

CGTalk Moderation
04-03-2010, 02:05 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.