On 17/02/2017 at 07:37, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R18
Platform: Windows ;
Language(s) : C++ ;
---------
Hello.
I'm trying to click on viewport and get the pointed Polygon.
Here is my code:
void pickObject(BaseDocument* doc){
doc->StopPickSession(true);
pick_session_data->multi = true;
pick_session_data->callback = pickCallback;
doc->StartPickSession(pick_session_data);
}
void pickCallback(Int32 flags, const PickSessionDataStruct* pick_session_data) {
AtomArray* atom_array = pick_session_data->active;
BaseDocument* doc = GetActiveDocument();
Int32 atom_count = atom_array->GetCount();
for (Int32 i = 0; i < atom_count; ++i ) {
C4DAtom* current_atom = atom_array->GetIndex(i);
if (curret_atom && current_atom->IsInstanceOf(Obase)) {
BaseObject* ob = (BaseObject* )current_atom;
if (ob) {
BaseContainer bc;
GetInputState(BFM_INPUT_MOUSE, BFM_INPUT_MOUSELEFT, bc);
Int32 input_x = bc.GetInt32(BFM_INPUT_X), input_y = bc.GetInt32(BFM_INPUT_Y);
BaseDraw* base_draw = doc->GetRenderBaseDraw();
Int32 left, top, right, bottom, width, height;
base_draw->GetFrame(&left, &top, &right, &bottom);
width = right - left + 1;
height = bottom - top + 1;
C4DObjectList* object_list = C4DObjectList::Alloc();
AutoAlloc<ViewportSelect> viewport_select;
Bool init_res = viewport_select->Init( width, height, base_draw, ob, Mpolygons, true, VIEWPORTSELECTFLAGS_0 );
ViewportPixel* vpp = viewport_select->GetNearestPolygon(ob, input_x, input_y, 1, false);
//Do something here
C4DObjectList::Free(object_list);
}
}
}
}
In the for loop I get all the clicked objects. Calling GetNearestPolygon I should get the clicked polygon right ?
Even though the clicked object is correct, GetNearestPolygon returns NULL.
Is there anything else I should take into consideration ?
Thank you for your time.