THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/02/2010 at 15:49, xxxxxxxx wrote:
Here's what I have so far......
C4DObjectList * objList = C4DObjectList::Alloc();
if (!objList) return FALSE;
//DECLARATIONS & DEFINITIONS
if (!doc) return FALSE;
BaseObject *op = doc->GetActiveObject();
if(!op) return TRUE;
PolygonObject *objPoly = ToPoly(op);
if (!objPoly) return FALSE;
BaseSelect *bsPoly = objPoly->GetPolygonS();
BaseSelect *bsPoint = objPoly->GetPointS();
BaseSelect *bsEdge = objPoly->GetEdgeS();
Real dx, dy, len = data.GetReal(1, 0.0);
BaseContainer device;
Real mousex = msg.GetLong(BFM_INPUT_X);
Real mousey = msg.GetLong(BFM_INPUT_Y);
win->MouseDragStart(KEY_MLEFT, mousex, mousey, MOUSEDRAG_NOMOVE);
LONG lngRad = 1; //MAXIMUM SELECTION RADIUS
LONG lngEditorMode = doc->GetMode();
AutoAlloc<ViewportSelect> vps;
if(!vps) return FALSE;
LONG left, top, right, bottom, width, height;
bd->GetFrame(&left, &top, &right, &bottom);
width = right - left + 1;
height = bottom - top + 1;
if(!vps->Init(width, height, bd, op, doc->GetMode(), TRUE, VIEWPORT_IGNORE_HIDDEN_SEL)) return FALSE;
LONG lngX = mousex;
LONG lngY = mousey;
//DRAW CIRCLE TO SHOW HOTSPOT
vps->SetBrushRadius(data.GetLong(SELECTION_RADIUS)); //SET BRUSH RADIUS
while (win->MouseDrag(&dx, &dy, &device) == MOUSEDRAG_CONTINUE)
{
if (dx == 0 && dy == 0)
continue;
lngX += dx;
lngY += dy;
DrawViews(DA_ONLY_ACTIVE_VIEW|DA_NO_THREAD|DA_NO_ANIMATION);
vps->ShowHotspot(win, lngX, lngY);
}
vps->ShowHotspot(win, lngX, lngY);
//SELECT THE POLYGON THAT IS CLICKED
BaseContainer state;
LONG lngKey = state.GetLong(BFM_INPUT_QUALIFIER);
ViewportPixel *vpPoly = vps->GetNearestPolygon(op,lngX,lngY,lngRad);
ViewportPixel *vpPoint = vps->GetNearestPoint(op,lngX,lngY,lngRad);
ViewportPixel *vpEdge = vps->GetNearestEdge(op,lngX,lngY,lngRad);
Bool shiftDown = GetInputEvent(BFM_INPUT_KEYBOARD, state);
LONG lngPolygonCount = objPoly->GetPolygonCount();
LONG lngPointCount = objPoly->GetPointCount();
const CPolygon * selectedPoly = objPoly->GetPolygonR();
const Vector * points = objPoly->GetPointR();
LONG lngI;
Matrix opMatrix = op->GetMg();
switch (lngEditorMode)
{
//POLYGONS MODE
case Mpolygons:
{
if(vpPoly)
{
//FIRST SELECTION
if (secondSelection == FALSE)
{
bsPoly->DeselectAll();
bsPoly->Select(vpPoly->i);
firstSelection = vpPoly->op;
secondSelection = TRUE;
}
//SECOND SELECTION
else if (secondSelection == TRUE)
{
bsPoly->DeselectAll();
bsPoly->Select(vpPoly->i);
for (lngI=0; lngI < lngPolygonCount; lngI++)
{
if (bsPoly->IsSelected(lngI))
{
lngA = selectedPoly[lngI].a;
lngB = selectedPoly[lngI].b;
lngC = selectedPoly[lngI].c;
lngD = selectedPoly[lngI].d;
//Caclulate the polygon position.
if (selectedPoly[lngI].c == selectedPoly[lngI].d)
{
polyLocation = (points[lngA] + points[lngB] + points[lngC]) / 3; //Polygon is a Triangle
}
else
{
polyLocation = (points[lngA] + points[lngB] + points[lngC] + points[lngD]) / 4; //Polygon is not a Triangle
}
//Align 1st Selection to the polygon of 2nd Selection (X AXIS)
if (polyLocation.x > 0)
{
firstSelection->SetPos(op->GetPos() + polyLocation + Vector(firstSelection->GetRad().x,0,0));
firstSelection->SetRot(CalcFaceNormal(points,selectedPoly[lngI]) * opMatrix);
}
if (polyLocation.x < 0)
{
firstSelection->SetPos(op->GetPos() + polyLocation - Vector(firstSelection->GetRad().x,0,0));
firstSelection->SetRot(CalcFaceNormal(points,selectedPoly[lngI]) * opMatrix);
}
//Align 1st Selection to the polygon of 2nd Selection (Y AXIS)
if (polyLocation.y > 0)
{
firstSelection->SetPos(op->GetPos() + polyLocation + Vector(0,firstSelection->GetRad().y,0));
firstSelection->SetRot(op->GetRot());
}
if (polyLocation.y < 0)
{
firstSelection->SetPos(op->GetPos() + polyLocation - Vector(0,firstSelection->GetRad().y,0));
firstSelection->SetRot(op->GetRot());
}
//Align 1st Selection to the polygon of 2nd Selection (Z AXIS)
if (polyLocation.z > 0)
{
firstSelection->SetPos(op->GetPos() + polyLocation + Vector(0,0,firstSelection->GetRad().z));
firstSelection->SetRot(op->GetRot());
}
if (polyLocation.z < 0)
{
firstSelection->SetPos(op->GetPos() + polyLocation - Vector(0,0,firstSelection->GetRad().z));
firstSelection->SetRot(op->GetRot());
}
bsPoly->DeselectAll();
}
}
secondSelection = FALSE;
}
EventAdd(EVENT_FORCEREDRAW);
op->Message(MSG_CHANGE);
DrawViews(DA_ONLY_ACTIVE_VIEW|DA_NO_THREAD|DA_NO_ANIMATION);
}
I am trying to get (firstSelection) to rotate to the normal of the selected polygon on (op). I am using CalcFaceNormal() but that seems to return incorrect results. Does anyone know how I could get this to rotate properly?
Thanks,
~SHawn