# Locking a virtual point to an object.

• On 20/06/2016 at 07:07, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   12
Platform:   Windows  ;
Language(s) :   C.O.F.F.E.E  ;

---------
Hi

I'm still getting to grips with the concepts of a matrix and I've got a question about it please.

I want to lock a virtual point 100mm away from a null in the in the z direction. In other words,  the virtual point must remain at a location of (0, 0, 100) relative to the null, no matter how I move or rotate the null. I then want to find the Global position of the virtual point & store it into a variable.

Could someone please tell me how to accomplish this?

Thanks.

• On 20/06/2016 at 10:42, xxxxxxxx wrote:

Vector globalpos = Vector(0,0,100) * null->GetMg(); //Get global position

• On 20/06/2016 at 16:59, xxxxxxxx wrote:

Originally posted by xxxxxxxx

Vector globalpos = Vector(0,0,100) * null->GetMg(); //Get global position

Hi Katachi
Thank you very much for your reply. I tried the code you supplied but it results in an error "Incompatible Values... VECTOR / OBJECT". Also, it appears that this was intended to only solve the last part of of my original question and I need help with the first part too.

• On 21/06/2016 at 01:45, xxxxxxxx wrote:

Hello,

in his example Samir accesses the global matrix of the given object that is used to transform a point in object space into world space. Then he uses this matrix to perform this transformation on the given Vector.

You find some explanation on how to use matrices in the COFFEE documentation.

Best wishes,
Sebastian

• On 21/06/2016 at 06:54, xxxxxxxx wrote:

The people in this forum are all using C++. So you will always need to convert their answers from C++. Which you are probably not able to do yet.
It sucks to be a noob. We've all been there.

COFFEE version:

``````main(doc,op)
{
var obj = doc->GetActiveObject();
if(!obj) return false;

var gmtx = obj->GetMg(); //The global matrix
var virtPnt_global = gmtx->GetMulP(vector(0,0,100));
println(virtPnt_global);
}
``````

-ScottA

• On 22/06/2016 at 07:15, xxxxxxxx wrote:

Originally posted by xxxxxxxx

Hello,

in his example Samir accesses the global matrix of the given object that is used to transform a point in object space into world space. Then he uses this matrix to perform this transformation on the given Vector.

You find some explanation on how to use matrices in the COFFEE documentation.

Best wishes,
Sebastian

Hi S_Bach

Thanks for your reply. I've been over the documentation quite a few times but I think what has got me stumped is how EG. rotation is derived from the contents of the matrix (I know one can get it with GetHPB but I don't yet understand the inner workings) and the concepts of stuff like vnorm etc. . These things aren't explained very detailed in the documentation. I also always try to find existing answers on the net before I post on a forum but it looks like I'm one of very few who doesn't quite get matrices 'cause questions are usually sparse.
Thanks anyway.

Originally posted by xxxxxxxx

The people in this forum are all using C++. So you will always need to convert their answers from C++. Which you are probably not able to do yet.
It sucks to be a noob. We've all been there.

COFFEE version:

``````main(doc,op)
{
var obj = doc->GetActiveObject();
if(!obj) return false;

var gmtx = obj->GetMg(); //The global matrix
var virtPnt_global = gmtx->GetMulP(vector(0,0,100));
println(virtPnt_global);
}
``````

-ScottA

Hi Scott

Man, you've come to the rescue again. Thank you so much. If I ever visit your country, I'll have to buy you many beers.

I think why I haven't started looking into C++ yet is because I sometimes run into a snag with something I'm busy with and there isn't an available tool or something for what I want to do. Scripting is obviously very handy for quickly writing something to do such a thing. But I'll definitly have to start getting comfortable with C++ as it would give me nice polished tools.

Thank you again. Your code does exactly what I wanted.