THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 12/03/2003 at 12:26, xxxxxxxx wrote:
Cinema 4D Version: 8.012
Platform: Windows ;
Language(s) : C++ ;
i can't get the matrix stuff for object (and especially sub objects) working. one thing i know for sure is that the drawing in my own 3d engine works but the code in the cinema exporter does definitely not. my engine takes the object matrix to do the object rotation, scale and position in the world and multiplies the parent object matrix with the current object matrix. the ordering of the matrices in this multiplication is correct.
in the exporter i tried the following things for the object matrix in my engine..(no method worked)
1. get the object's global matrix with BaseObject->GetMg () as it is
2. apply the object's local matrix (BaseObject->GetMl ()) to the object's vertex data and take the object's global matrix
3. calculate the object matrix with built in cinema math functions by getting the Rotation (HPBToMatrix (BaseObject->GetRot ())), the Scale (BaseObject->GetScale()), the Postition (BaseObject->GetPos ()) and multiplying these matrices together (tried all possible multiplication orderings)
4. the same as above in 3. plus applying the local matrix to the object's vertex data
the subobjects appear displaced, wrong rotated, wrong scaled, and with several combinations it even breaks the texture mapping's UV coordinates what i absolutely do not understand.
maybe someone got the master plan to this trivial problem for me.
thanks a lot in advance
On 12/03/2003 at 13:12, xxxxxxxx wrote:
What are you trying to export? the objects point in world coordinates? there is nothing wrong with the matrix functions in c4d, it there was, nothing would work! they are used all over, therefore, you've probably misunderstood something if I understand what you need, I can probably help out getting you back onto the right path.
On 12/03/2003 at 13:24, xxxxxxxx wrote:
i am trying to export the objects so called "world matrix" for further usage in .. let's say .. direct 3d (or any other 3d api). hope now it's clear.
On 12/03/2003 at 13:30, xxxxxxxx wrote:
You just want the matrix? and you need it in the same format? in that case you just use GetMg(), that is it! but you'll need to make sure you need the same format, left/right-hand coordinate system etc.
On 12/03/2003 at 13:33, xxxxxxxx wrote:
yes. indeed. you got it. i just want the matrix. because all the other stuff is already working. and just getting the matrix with GetMg and passing it thru to d3d does not work. maybe it is indeed a coordinate system problem, i'm not sure, that's why i am asking here.
On 12/03/2003 at 13:46, xxxxxxxx wrote:
Ok, I'm not sure what system D3D uses, but you can easily find out by running a basic test, just place an object in C4D (just one!) at say (100,100,100) and do your export, then see if the object is at the correct position in D3D, if so, it uses the same coordinate system. I -think- D3D is left-handed, and so is C4D, so you should be ok for that bit. Try breaking down the steps, test one object, then one with a single child etc. If you only use GetMg() and do no other matrix maths (don't try and combine mg with ml or anything else, mg -is- the objects world matrix provided the points are all local, when combined it will be fine, the other alternative is to use a unit matrix and change the points, just export them multiplied by mg) then for each object it will be correct.
On 12/03/2003 at 13:48, xxxxxxxx wrote:
already did that. no success.
On 12/03/2003 at 14:04, xxxxxxxx wrote:
does it work for a single object? which parts fail, have you tried just the position, then just rotation, then just scale etc. which one (if any) work and what combinations fail, can you set the values manually in your export (or D3D display?) and then compare with the mg from C4D to see where the difference is, hard to help really since it isn't a c4d problem, more some break down between the c4d matrix, how you export it, and then how it is used maybe someone with D3D experience will be able to help.
On 12/03/2003 at 14:12, xxxxxxxx wrote:
yes, i did those tests. and they failed all somehow. i started by just applying the translation part to the matrices only ... it looked somehow right translated, but - of course - not properly rotated... then i added the rotation and the translation was wrong ... not to speak about the scaling. it's all a little bit weird with all those matrices ... besides, i am not sure the global matrix that GetMg returns can be used for handling subobjects ... because a subobject matrix has to be relative to all previous parent's matrices. and it is not said to be in the sdk documentation. only the separated Rotation, Scale and Position vectors are said to be relative to the parent object. but that doesn't work either, as said ...
On 12/03/2003 at 14:59, xxxxxxxx wrote:
I have the impression you've misunderstood the GetMg() and GetMl() and hierarchy system keeping to just one object first, then you don't need to worry about anything else (like subobjects and hierarchy structure), when you apply a translation to the object, just do it say to (100,0,0) [100 along X], and check it? does translation -only- work ok along each axis and all axes combined? (for one object only using GetMg(), not other matrices). If it fails, how do you mean? do you mean you set it to 100 along the x-axis and it moves 100 along Y in D3D?
As for GetMg() and the hierarchy, it depends on how you then intend on using the objects, if you are keeping the hierarchy structure from C4D then you want to be using GetMl(), that gives you the local matrix for the object, it also depends on D3D, does this use a hierarchy structure where the subobjects are combined with the parent matrix?
On 12/03/2003 at 15:09, xxxxxxxx wrote:
let's discuss this one by email. i have to send you some screen shots. i'm speachless
On 12/03/2003 at 15:28, xxxxxxxx wrote:
sure send them to [email protected]
I'll be able to get them or if I'm not around (like I have a day off tomorrow then dev support will, if you can send some screenshots, maybe example source of the export bit, what you are using it in (your own D3D app?) any import source/display info, we'll try and help out, try anyway!
Just as a reminder to all plugin coders...
A good policy to try and keep to when sending info to the sdk_support mail is to supply as much info as possible with source clips and comments if possible, even screenshots if needed, but not too much source (like entire plugins). I know it is hard to balance (experience is the best solution), but if we get too much then it takes ages to sort out and if we don't get enough information, we just have to ask again which delays your answers, and just imagine what would happen if every developer sent entire plugins sources
On 12/03/2003 at 15:42, xxxxxxxx wrote:
uhm. eh. well... i tried a little bit more ... and - it's unbelivable - it finally works!
what i am doing is ..
Matrix ObjectRotation = HPBToMatrix (PolyObj->GetRot ());
Matrix ObjectScale = MatrixScale (PolyObj->GetScale ());
Matrix ObjectPosition = MatrixMove (PolyObj->GetPos ());
ObjectMatrix = ObjectScale * ObjectMatrix;
ObjectMatrix = !ObjectRotation * ObjectMatrix;
ObjectMatrix = ObjectPosition * ObjectMatrix;
somehow i noticed that the rotations are going in the opposite direction, so i just invert the rotaion matrix and it's going. the problems with subobjects are gone, too.
as always .. i helped myself again. but thank you very much for your advice to try even more and WATCH and LOOK
On 13/03/2003 at 00:15, xxxxxxxx wrote:
Ok, I'm not quite sure how that can work based on the info you gave you had said it fails even basic translation (single object, no scale, no rotation), which would imply that code above should fail too also, inverting the rotation matrix is the same as a transpose since it is an orthogonal matrix (transpose is faster too), that suggests the direction of D3D rotations is opposite to the C4D direction... anyway, glad it now works for you