![]() |
Polygon Position |
Post Reply
|
Page 123> |
| Author | |||
emberintherain
Member
Joined: 2008 Dec 23 Location: United States Online Status: Offline Posts: 487 |
Post Options
Quote Reply
Topic: Polygon PositionPosted: 2010 Feb 21 at 5:47am |
||
|
User Information: Cinema 4D Version: 11.5Platform: Windows ; Language(s): C++ ; --------- How do I determine the vector positions of the points that make up a given polygon?~Shawn |
|||
![]() |
|||
c4dJack
Member
Joined: 2007 Jul 13 Location: Turkey Online Status: Offline Posts: 454 |
Post Options
Quote Reply
Posted: 2010 Feb 21 at 6:00am |
||
|
Have a look into const CPolygon* PolygonObject::GetPolygonR(void). It gives you an array of all polygons (CPolygon). Each Polygon contains the point indexes of the points it's made from.
Then use const Vector* PointObject::GetPointR(void) to get an array with all points contained in the object. To do your calculation, use the point indexes you got from the CPolygon. Cheers, Jack |
|||
![]() |
|||
emberintherain
Member
Joined: 2008 Dec 23 Location: United States Online Status: Offline Posts: 487 |
Post Options
Quote Reply
Posted: 2010 Feb 21 at 6:03am |
||
|
Thanks Jack, I appreciate your response.
~Shawn |
|||
![]() |
|||
emberintherain
Member
Joined: 2008 Dec 23 Location: United States Online Status: Offline Posts: 487 |
Post Options
Quote Reply
Posted: 2010 Feb 21 at 12:23pm |
||
|
So here's what I have so far.
this gives me the index for each of the points... so now would I do something like this....? Vector pointLocation = Vector(points[lngA].x,points[lngA].y,points[lngA].z); Edited by emberintherain - 2010 Feb 21 at 12:24pm |
|||
![]() |
|||
c4dJack
Member
Joined: 2007 Jul 13 Location: Turkey Online Status: Offline Posts: 454 |
Post Options
Quote Reply
Posted: 2010 Feb 22 at 5:46am |
||
|
What you do now depends on what you consider to be the "polygon's position". Is it a position centered between the polygon's points? In that case, add the positions of points a, b and c, then divide by 3.0. If it's not only a triangle but a quad (check if point c == d to find out about that), add a, b, c and d, then divide by 4.0.
Or is it the centered (or otherwise weighted) position on a triangle face? Then use barycentric coordinates (AFAIK this does only work with triangles).
This is not necessary. Since the points are stored as vectors (point positions) the following is sufficient: Vector pointLocation = points[lngA]; Cheers, Jack Edited by c4dJack - 2010 Feb 22 at 5:51am |
|||
![]() |
|||
emberintherain
Member
Joined: 2008 Dec 23 Location: United States Online Status: Offline Posts: 487 |
Post Options
Quote Reply
Posted: 2010 Feb 22 at 5:53am |
||
|
Thanks Jack, that helps a lot. I think I've got it figured out thanks!
Cheers, ~Shawn
|
|||
![]() |
|||
emberintherain
Member
Joined: 2008 Dec 23 Location: United States Online Status: Offline Posts: 487 |
Post Options
Quote Reply
Posted: 2010 Feb 22 at 4:05pm |
||
|
Is it possible to get the rotation of a a particular polygon?
~Shawn |
|||
![]() |
|||
emberintherain
Member
Joined: 2008 Dec 23 Location: United States Online Status: Offline Posts: 487 |
Post Options
Quote Reply
Posted: 2010 Feb 22 at 5:28pm |
||
|
or better yet, how would I align my first object to the normal of the polygon that is selected?
~Shawn |
|||
![]() |
|||
Matthias Bober
Forum Moderator
Joined: 2006 Oct 16 Location: Germany Online Status: Offline Posts: 1647 |
Post Options
Quote Reply
Posted: 2010 Feb 23 at 2:38am |
||
|
What you want to do is not clearly defined. Basically you have to create a rotation matrix for the polygon. For this you need at least two vectors. One is the normal, the other one has to be defined by you. For instance you could choose the vector pointing from the polygon's midpoint to its first vertex. Or you choose a global vector.
cheers, Matthias |
|||
|
MAXON
developer support |
|||
![]() |
|||
emberintherain
Member
Joined: 2008 Dec 23 Location: United States Online Status: Offline Posts: 487 |
Post Options
Quote Reply
Posted: 2010 Feb 23 at 2:54am |
||
|
I want to move one object and have it sit on the polygon of another object and have it rotate to the normal of that polygon so that the object is sitting flush with that polygon. SO I will need the center between all of the points of that polygon (which I have) and a point in space that points directly outward from that polygon? There is no function in the sdk that provides the normal of a polygon?
so the vector from the center to the first point would create a plane upon which I could determine rotation? how would I get that? Here's how I determine the center of the polygon
how would I set up the rotation matrix with this info if points[lngA] is the first point of the polygon? Thanks, ~SHawn |
|||
![]() |
|||
emberintherain
Member
Joined: 2008 Dec 23 Location: United States Online Status: Offline Posts: 487 |
Post Options
Quote Reply
Posted: 2010 Feb 23 at 3:44pm |
||
|
Okay so I want to set up a rotation matrix for the selected polygon. do I do this by mulitplying the vector of one point by the vector of a second point in the polygon?
~Shawn |
|||
![]() |
|||
emberintherain
Member
Joined: 2008 Dec 23 Location: United States Online Status: Offline Posts: 487 |
Post Options
Quote Reply
Posted: 2010 Feb 23 at 3:49pm |
||
|
Here's what I have so far......
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 Edited by emberintherain - 2010 Feb 23 at 4:34pm |
|||
![]() |
|||
Matthias Bober
Forum Moderator
Joined: 2006 Oct 16 Location: Germany Online Status: Offline Posts: 1647 |
Post Options
Quote Reply
Posted: 2010 Feb 24 at 2:43am |
||
|
I recommend to read up on Vector and Matrix arithmetics.
http://www.flipcode.com/documents/matrfaq.html Also the CINEMA 4D R9.5 COFFEE documentation has a very good tutorial on using matrices. Especially vector cross products are essential to build your own cutom rotation matrices. I can not debug or write your plugin, sorry. cheers, Matthias |
|||
|
MAXON
developer support |
|||
![]() |
|||
emberintherain
Member
Joined: 2008 Dec 23 Location: United States Online Status: Offline Posts: 487 |
Post Options
Quote Reply
Posted: 2010 Feb 24 at 2:48am |
||
|
Thanks for the link Matthias. LOL... I don't want you to write it for me. Where's the fun in that. :)
~Shawn |
|||
![]() |
|||
emberintherain
Member
Joined: 2008 Dec 23 Location: United States Online Status: Offline Posts: 487 |
Post Options
Quote Reply
Posted: 2010 Feb 24 at 7:31am |
||
|
Great tutorial on Matrices. Thanks for that.
~Shawn
|
|||
![]() |
|||
emberintherain
Member
Joined: 2008 Dec 23 Location: United States Online Status: Offline Posts: 487 |
Post Options
Quote Reply
Posted: 2010 Feb 25 at 3:47am |
||
|
Is there a c++ equivalent to the function you mention in the tutorial GetMulP()?
or would I just use firstSelection->SetPos(opMatrix * points[lngA]); first selection being my object, and points[lngA] being the vector location of the point I am trying to move the object to. Thanks, ~Shawn |
|||
![]() |
|||
Matthias Bober
Forum Moderator
Joined: 2006 Oct 16 Location: Germany Online Status: Offline Posts: 1647 |
Post Options
Quote Reply
Posted: 2010 Feb 25 at 5:47am |
||
|
Yes, multiplying a vector with a matrix transforms the vector into the matix' space.
The Matrix class has several overloaded operators for matrix-matrix and matrix-vector arithmetics. cheers, Matthias |
|||
|
MAXON
developer support |
|||
![]() |
|||
emberintherain
Member
Joined: 2008 Dec 23 Location: United States Online Status: Offline Posts: 487 |
Post Options
Quote Reply
Posted: 2010 Feb 26 at 9:38am |
||
|
Okay... SO I think I kindof understand a rotation matrix now. I need to find the vector from the center of the polygon which I did with
This gives me a vector that represents the very center of the polygon Then I need another point along the same plane which I use points[lngA]. This is the first point in the polygon. So mathematically that gives me A & B. Assuming my equation is C = A x B. So to get the point which represents the Z axis or the point hovering directly above the polygon face, I simply multiply
And this should give me my rotation matrix correct? So now my question is how do I then rotate my object to match that rotation matrix? Here is what I am trying.
Please let me know if I am way off base here and am going about this completely wrong so that I know not to continue in this way. Thanks lot for your help. |
|||
![]() |
|||
emberintherain
Member
Joined: 2008 Dec 23 Location: United States Online Status: Offline Posts: 487 |
Post Options
Quote Reply
Posted: 2010 Mar 01 at 6:22am |
||
|
Thanks for all your help Jack. I have officially filled up your PM box. I didn't notice that what you sent me was different. Thanks for that.
~Shawn
|
|||
![]() |
|||
emberintherain
Member
Joined: 2008 Dec 23 Location: United States Online Status: Offline Posts: 487 |
Post Options
Quote Reply
Posted: 2010 Mar 03 at 5:15pm |
||
|
Hey folks. So I believe that I have created the rotation matrix correctly. And when I click the polygon on the second object the object moves to that polygon correctly, however it does not rotate correctly. Sometimes it rotates a bit but not the way it should. I want the firstSelection object to rotate so that it is sitting flush with the polygon no matter what the rotation of the polygon is. Does anyone see any reason in the following code why this wouldn't be happening? Any help would be greatly appreciated. This one's a bit frustrating.
|
|||
![]() |
|||
Post Reply
|
Page 123> |
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |