Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
On 18/06/2018 at 04:11, xxxxxxxx wrote:
User Information: Cinema 4D Version: Platform: Language(s) :
--------- Hi folks,
I'm trying to draw a null object inside an ObjectData's Draw() method. I set the nulls position, but when it draws, the position is ignored and instead draws at world centre.
// There's a few class-level variables here // Null_Object is a class level BaseObject::Alloc(Onull) DRAWRESULT Demo_Object::Draw(BaseObject *op,DRAWPASS drawpass,BaseDraw *bd,BaseDrawHelp *bh) { if(drawpass == DRAWPASS_OBJECT) { Draw_Matrix = bh->GetMg(); bd->SetMatrix_Matrix(nullptr,Draw_Matrix); Null_Object->SetAbsPos(Vector(0.0,100.0,-250.0)); Null_Object->Message(MSG_UPDATE); Draw_Result = bd->DrawObject(bh,Null_Object,DRAWOBJECT_USE_OBJECT_COLOR,drawpass,nullptr,colour_vec); if(Draw_Result == DRAWRESULT_OK){GePrint("Point drawn..");} // prints } return SUPER::Draw(op,drawpass,bd,bh); }
I've stripped it to cut to the chase. What am I missing here?
WP.
On 19/06/2018 at 02:08, xxxxxxxx wrote:
Hi,
BaseDraw::DrawObject() doesn't use the passed object transform. The matrix for the BaseDraw has to be set prior to perform any drawing operation. See BaseView / BaseDraw Manual in the C++ docs: Matrix and Objects.
On 21/06/2018 at 03:53, xxxxxxxx wrote:
Hi Yannick,
thanks for your reply. For objects I have in memory (not attached to a document), does this mean I have to construct the matrix myself? I can't use GetMg()?
On 21/06/2018 at 07:03, xxxxxxxx wrote:
Yes, if the object is not attached to a document then you can't rely on GetMg(). You can use MatrixMove() to obtain a transformation matrix from a position/translation vector.
On 22/06/2018 at 03:28, xxxxxxxx wrote:
thanks for MatrixMove(), didn't realise that was there!
I'd been trying to set the matrix with other object matrices but nothing would change it. I shortened it to using the below:
DRAWRESULT Demo_Object::Draw(BaseObject *op,DRAWPASS drawpass,BaseDraw *bd,BaseDrawHelp *bh) { if(drawpass == DRAWPASS_OBJECT) { bd->SetMatrix_Matrix(nullptr,MatrixMove(Vector(0.0,100.0,-250.0))); Draw_Result = bd->DrawObject(bh,Null_Object,DRAWOBJECT_USE_OBJECT_COLOR,drawpass,nullptr,colour_vec); if(Draw_Result == DRAWRESULT_OK) { GePrint("Null drawn.."); // prints } } return SUPER::Draw(op,drawpass,bd,bh); }
but the object is still not drawn where I'd expect. In my initial post I said it was drawing it to world centre, but I've now realised it's drawn to my object's 0,0,0 position. So if I drag my object around the null follows it, does that indicate anything?
On 25/06/2018 at 10:37, xxxxxxxx wrote:
The behavior you describe makes sense, in DRAWPASS_OBJECT the BaseDraw drawings are done in the object's space. Instead of calling bd->SetMatrix_Matrix() try bh->SetMg().
On 26/06/2018 at 03:47, xxxxxxxx wrote:
Ah, you beaut! Thanks Yannick, that was it. Needed bh->SetMg()!
Thanks for you help