Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Can't get the Camera inverse matrix...

    SDK Help
    0
    15
    1.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 12/06/2003 at 14:28, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   6.3 
      Platform:   Windows  ;   
      Language(s) :     C++  ;

      ---------
      I have a very strange problem. After I get the camera object in the scene, I try to get the inverse matrix for the camera. It returns all zeros! I can get the non-inverted camera matrix. Here is the call I am using:
      cameramatrix = !cameraob->GetMgn();
      mv0 = cameramatrix.v1;
      mv1 = cameramatrix.v2;
      mv2 = cameramatrix.v3;
      mv3 = cameramatrix.off;
      Shouldn't this do it for me? This was working before, and I didn't think I changed anything. Ugh.... I don't have much hair left....

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 13/06/2003 at 05:19, xxxxxxxx wrote:

        Hi,
        are you really using the 6.3 SDK???
        Try to get the camera matrix with BaseView::GetMg() and the inverse Matrix of the camera with BaseView::GetMi()

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 13/06/2003 at 06:03, xxxxxxxx wrote:

          If you need a MAC compile, just ask 😉

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 13/06/2003 at 07:56, xxxxxxxx wrote:

            Ha, sad but true, still using version 6.3. For some reason. MAXON hasn't offered me a free copy of version 7 or version 8. Im still waiting though! 🙂
            Thanks for the tips. I think something is wrong with either my code or my computer because when I compile the plugin at home it seems to work, but at work it doesn't.
            Matt

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 13/06/2003 at 12:35, xxxxxxxx wrote:

              Ha, sad but true, still using version 6.3. For some reason. MAXON hasn't offered me a free copy of version 7 or version 8. Im still waiting though! 🙂
              😉
              Thanks for the tips. I think something is wrong with either my code or my computer because when I compile the plugin at home it seems to work, but at work it doesn't.
              strange. Let us know what the problem was...

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 13/06/2003 at 21:30, xxxxxxxx wrote:

                Ok, this gets stranger.

                If I comment our the code under where it exports the camera, then everything works. In face as long as I comment out the code that exports polygon data, everything works. But as soon a I un-comment that code, the camera no longer will excport (I can't get the inverse matrix) Why would code after the exporting of the camera affect the camera data?

                Matt

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                  On 14/06/2003 at 00:56, xxxxxxxx wrote:

                  Unless you're only talking to yourself, which indeed can sometimes be a valuable debugging tool, please post some more code to help us solve the mystery... 😉

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                    On 14/06/2003 at 07:31, xxxxxxxx wrote:

                    You mean you can't read my mind? Maybe the next version of the SDK will include that... Here is some code. I am skipping a lot, but I will try and put the pertinent parts in. Also, remember Im really not much of a programmer, so any help is appreciated.
                    It is a menu plugin. At the beginning of the execute function, I define most of the variable that are being used:

                        
                        
                          
                        BaseObject *object ;   //holds the object being exported  
                        BaseObject *cameraob;  //holds the camera object  
                        Vector position;   //holds the position of the object  
                        Vector lightcolor;   //holds the color of the light  
                        Real intensity;    //holds the intensity of the light  
                        Vector sphererad;    //stores the radius of hte primitive sphere  
                        Matrix cameramatrix;  //holds the cameras matrix  
                        Matrix objectmatrix;  //holds the objects matrix  
                        Vector mv0, mv1, mv2, mv3 = 0; //used to save the Transform line in the RIB file  
                        BaseContainer data;   //container to hold object container  
                        Vector objectcolor;   //hold the color of the object  
                        BaseTag *ptag = NULL;  
                        BaseChannel *channel = NULL;  //holds the channel of the material  
                        BaseContainer chcontainer; //the container of the channel  
                        String shaderinfo;   //holds any custom shader defined with the RMShader tag plugin  
                        String outputfilename;  
                        Bool ok;     //did the export get cancelled...  
                        Filename fn;    //holds the filename of the exported file  
                        RenderData *rd = NULL;    //holds the render data (resolution, etc)  
                        BaseContainer rdc;   //Render Data container  
                        
                    

                    Then, after setting up the export file and writing some preliminary info to it, I get the camera:

                        
                        
                          
                        //Camera Options  
                        Real fov;  
                        cameraob = doc->SearchObject("RenderCamera");  
                        if (!cameraob)  
                         {   
                          MessageDialog("Render camera not found. Looking for camera named RenderCamera.");  
                          a_file.close();  
                          return;  
                        }  
                           
                        fov = Deg(2 * atan((cameraob->GetAperture()/ 2) / cameraob->GetFocus()));  
                        a_file<<"#Camera options\n";  
                        cameramatrix = !cameraob->GetMgn();  
                        mv0 = cameramatrix.v1;  
                        mv1 = cameramatrix.v2;  
                        mv2 = cameramatrix.v3;  
                        mv3 = cameramatrix.off;  
                        
                    

                    This code works if I comment out the code later on in the source dealing with exporting polygon objects. In fact, I found out last night that it is just the part of the code exporting quads that messes the camera data up, if I leave in the exporting of triangles, everything works. In between the camera export code and the code below is the code for exporting the light data, and all the vraious primities that are supported. Here is the polygon code:

                        
                        
                          
                        else if (object->GetType() == Opolygon)  
                          {  
                           GePrint("Exporting: " + object->GetName());  
                           Vector  p;  
                           Vector *padr = NULL;  
                           Polygon *polyadr=NULL;  
                           LONG    i,j,k,pcnt,ptcnt,polycount;  
                           LONG *dadr=NULL;  
                           Vector normal;  
                           Neighbor n;  
                           Vector scale = object->GetScale();  
                           UVWStruct uv;  
                             
                           //General Stuff  
                           a_file<<"#" << GetText(object->GetName()) << "\n";  
                           a_file<<"AttributeBegin\n";  
                           if (objectcolor != NULL) a_file<<"Color [" << GetText(RealToString(objectcolor.x)) << " " << GetText(RealToString(objectcolor.y)) << " " << GetText(RealToString(objectcolor.z)) << "]\n";  
                           objectmatrix = object->GetMgn();  
                           mv0 = objectmatrix.v1;  
                           mv1 = objectmatrix.v2;  
                           mv2 = objectmatrix.v3;  
                           mv3 = objectmatrix.off;  
                           if (shaderinfo != "")  
                            a_file<<GetText(shaderinfo) << "\n";  
                           else  
                            a_file<<"Surface \"plastic\"\n";  
                           a_file<<"Transform [" << GetText(RealToString(mv0.x)) << " " << GetText(RealToString(mv0.y)) << " " << GetText(RealToString(mv0.z)) << " 0 " << GetText(RealToString(mv1.x)) << " " << GetText(RealToString(mv1.y)) << " " << GetText(RealToString(mv1.z)) << " 0 " << GetText(RealToString(mv2.x)) << " " << GetText(RealToString(mv2.y)) << " " << GetText(RealToString(mv2.z)) << " 0 " << GetText(RealToString(mv3.x/100)) << " " << GetText(RealToString(mv3.y/100)) << " " << GetText(RealToString(mv3.z/100)) << " 1]\n";  
                             
                            //polygon count and polygon address  
                           polyadr = static_cast<PolygonObject*>(object)->GetPolygon();  
                           pcnt = static_cast<PolygonObject*>(object)->GetPolygonCount();  
                           //point count and point address  
                           ptcnt = static_cast<PointObject*>(object)->GetPointCount();  
                           padr = static_cast<PointObject*>(object)->GetPoint();  
                           //initial normal gathering variables  
                           Vector normals = NULL;  
                           long dcnt;  
                           n.Init(ptcnt,polyadr,pcnt,NULL);  
                           //Get UV tag if there is one  
                           ptag = object->GetTag(Tuvw);  
                             
                           //main polygon export loop  
                           for (i=0; i<pcnt; i++)  
                           {  
                            if (polyadr[i].c == polyadr[i].d)   //triangle  
                            {  
                             a_file<<"Polygon \"P\" [";  
                             a_file<<GetText(RealToString(scale.x*padr[polyadr[i].a].x/100) + " " + RealToString(scale.y*padr[polyadr[i].a].y/100) + " " + RealToString(scale.z*padr[polyadr[i].a].z/100) + " ");   
                             a_file<<GetText(RealToString(scale.x*padr[polyadr[i].b].x/100) + " " + RealToString(scale.y*padr[polyadr[i].b].y/100) + " " + RealToString(scale.z*padr[polyadr[i].b].z/100) + " ");   
                             a_file<<GetText(RealToString(scale.x*padr[polyadr[i].c].x/100) + " " + RealToString(scale.y*padr[polyadr[i].c].y/100) + " " + RealToString(scale.z*padr[polyadr[i].c].z/100) + " ");   
                             a_file<<"] \"N\" [";  
                              
                             //normal for point 1  
                             normals = NULL;  
                             n.GetPointPolys(polyadr[i].a,&dadr,&dcnt);  
                             for(k=0;k<dcnt;k++)  
                             {  
                              normals += (CalcFaceNormal(padr,polyadr[dadr[k]]));  
                             }  
                             normals = !((normals)/k);  
                             a_file<<GetText(RealToString(normals.x) + " " + RealToString(normals.y) + " " + RealToString(normals.z) + " ");  
                               
                            //normal for point 2  
                             normals = NULL;  
                             n.GetPointPolys(polyadr[i].b,&dadr,&dcnt);  
                             for(k=0;k<dcnt;k++)  
                             {  
                              normals += (CalcFaceNormal(padr,polyadr[dadr[k]]));  
                             }  
                             normals = !((normals)/k);  
                             a_file<<GetText(RealToString(normals.x) + " " + RealToString(normals.y) + " " + RealToString(normals.z) + " ");  
                               
                             //normal for point 3  
                             normals = NULL;  
                             n.GetPointPolys(polyadr[i].c,&dadr,&dcnt);  
                             for(k=0;k<dcnt;k++)  
                             {  
                              normals += (CalcFaceNormal(padr,polyadr[dadr[k]]));  
                             }  
                             normals = !((normals)/k);  
                             a_file<<GetText(RealToString(normals.x) + " " + RealToString(normals.y) + " " + RealToString(normals.z) + " ");  
                             a_file<<"] ";   
                               
                             if (ptag)  
                             {  
                              a_file<<"\"st\" [";  
                              uv = static_cast<UVWTag*>(ptag)->Get(i);  
                              a_file<<GetText(RealToString(uv.a.x) + " " + RealToString(uv.a.y)+ " " + RealToString(uv.b.x)+ " " + RealToString(uv.b.y)+ " " + RealToString(uv.c.x)+ " " + RealToString(uv.c.y) + " ");         
                                a_file<<"]\n";  
                             }  
                            }  
                              
                            else //quad  
                            {  
                             a_file<<"Polygon \"P\" [";  
                             a_file<<GetText(RealToString(scale.x*padr[polyadr[i].a].x/100) + " " + RealToString(scale.y*padr[polyadr[i].a].y/100) + " " + RealToString(scale.z*padr[polyadr[i].a].z/100) + " ");   
                             a_file<<GetText(RealToString(scale.x*padr[polyadr[i].b].x/100) + " " + RealToString(scale.y*padr[polyadr[i].b].y/100) + " " + RealToString(scale.z*padr[polyadr[i].b].z/100) + " ");   
                             a_file<<GetText(RealToString(scale.x*padr[polyadr[i].c].x/100) + " " + RealToString(scale.y*padr[polyadr[i].c].y/100) + " " + RealToString(scale.z*padr[polyadr[i].c].z/100) + " ");   
                             a_file<<GetText(RealToString(scale.x*padr[polyadr[i].d].x/100) + " " + RealToString(scale.y*padr[polyadr[i].d].y/100) + " " + RealToString(scale.z*padr[polyadr[i].d].z/100) + " ");   
                             a_file<<"] \"N\" [";  
                          
                             //normal for point 1  
                             normals = NULL;  
                             n.GetPointPolys(polyadr[i].a,&dadr,&dcnt);  
                             for(k=0;k<dcnt;k++)  
                             {  
                              normals += (CalcFaceNormal(padr,polyadr[dadr[k]]));  
                             }  
                             normals = !((normals)/k);  
                             a_file<<GetText(RealToString(normals.x) + " " + RealToString(normals.y) + " " + RealToString(normals.z) + " ");  
                          
                             //normal for point 2  
                             normals = NULL;  
                             n.GetPointPolys(polyadr[i].b,&dadr,&dcnt);  
                             for(k=0;k<dcnt;k++)  
                             {  
                              normals += (CalcFaceNormal(padr,polyadr[dadr[k]]));  
                             }  
                             normals = !((normals)/k);  
                             a_file<<GetText(RealToString(normals.x) + " " + RealToString(normals.y) + " " + RealToString(normals.z) + " ");  
                          
                             //normal for point 3  
                             normals = NULL;  
                             n.GetPointPolys(polyadr[i].c,&dadr,&dcnt);  
                             for(k=0;k<dcnt;k++)  
                             {  
                              normals += (CalcFaceNormal(padr,polyadr[dadr[k]]));  
                             }  
                             normals = !((normals)/k);  
                             a_file<<GetText(RealToString(normals.x) + " " + RealToString(normals.y) + " " + RealToString(normals.z) + " ");  
                          
                             //normal for point 4  
                             normals = NULL;  
                             n.GetPointPolys(polyadr[i].d,&dadr,&dcnt);  
                             for(k=0;k<dcnt;k++)  
                             {  
                              normals += (CalcFaceNormal(padr,polyadr[dadr[k]]));  
                             }  
                             normals = !((normals)/k);  
                             a_file<<GetText(RealToString(normals.x) + " " + RealToString(normals.y) + " " + RealToString(normals.z) + " ");  
                             a_file<<"] ";   
                             if (ptag) //object has UV coordinates  
                             {  
                              a_file<<"\"st\" [";  
                              uv = static_cast<UVWTag*>(ptag)->Get(i);  
                              a_file<<GetText(RealToString(uv.a.x) + " " + RealToString(uv.a.y)+ " " + RealToString(uv.b.x)+ " " + RealToString(uv.b.y)+ " " + RealToString(uv.c.x)+ " " + RealToString(uv.c.y) + " " + RealToString(uv.d.x)+ " " + RealToString(uv.d.y) + " ");         
                                a_file<<"]\n";  
                             }  
                               
                            }
                    
                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                      On 14/06/2003 at 07:54, xxxxxxxx wrote:

                      Hi,
                      I haven´t read the complete code but why does the cameramatrix variables take the objectmatrix values later on?
                      mv0 = objectmatrix.v1;
                         mv1 = objectmatrix.v2;
                         mv2 = objectmatrix.v3;
                         mv3 = objectmatrix.off;

                      if you export the camera information after this it´s logical that it´s messed up for it´s overwritten?

                      1 Reply Last reply Reply Quote 0
                      • H
                        Helper
                        last edited by

                        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                        On 14/06/2003 at 11:32, xxxxxxxx wrote:

                        Oops, guess I should have put some line breaks in the post above!..
                         
                        The camera data gets written out and then I reuse the variables for the object matrices. Is that a problem?
                        Matt

                        1 Reply Last reply Reply Quote 0
                        • H
                          Helper
                          last edited by

                          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                          On 15/06/2003 at 03:54, xxxxxxxx wrote:

                          hi,
                          no that shouldn´t be a problem. Have you done some debug sessions already? If not you should do. That way it should be easy to find out where exactly the code messes the camera data up.

                          1 Reply Last reply Reply Quote 0
                          • H
                            Helper
                            last edited by

                            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                            On 15/06/2003 at 13:49, xxxxxxxx wrote:

                            Humor a beginner...
                            How does one do a debug session for Cinema? I tried doing it, but couldn't get anywhere. I tried setting break points and running a debug session from Visual C++. Can you give me a simple step by step on how to set it up? Thanks.
                             
                            Matt

                            1 Reply Last reply Reply Quote 0
                            • H
                              Helper
                              last edited by

                              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                              On 15/06/2003 at 14:03, xxxxxxxx wrote:

                              no prob. Set Breakpoints with F9 and start the debugging with F5. You should switch to Debug version in Build->Set Active Configuration... (remember that you will have to specify the Cinema 4D executable in the settings for the Debug version).
                              When debugging you can go through your code with F10 or get on with F5.
                              Hope that helps...

                              1 Reply Last reply Reply Quote 0
                              • H
                                Helper
                                last edited by

                                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                                On 15/06/2003 at 15:39, xxxxxxxx wrote:

                                ok, I got the debugger working. It didn't work that smoothly in Windows 2000 at work... anyway...
                                What I found was when I set the configuration to Debug, the plugin works, but crashes at the end. If I set the configuration to Release, the plugin doesn't crash, but also doesn't work correctly. Needless to say, since I was in the debug confiruration to debug it, everything worked fine except for a crash at the end (minor problem...) Any idea why the plugin work do this? I checked the configurations and it seems the only difference is the addition of the debug settings.
                                Matt

                                1 Reply Last reply Reply Quote 0
                                • H
                                  Helper
                                  last edited by

                                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                                  On 15/06/2003 at 15:48, xxxxxxxx wrote:

                                  Hmm, sorry, without the code I cannot say anything. It might be a memory problem (had such "end-crashes" only if there was a memory problem). You might want to send the code to [email protected] with a detailed description of the problem. (you should narrow the problematic code area down to a minimum). Maybe Mikael can have a look and find the problem. This "usually" happens within 5 business days...
                                  But maybe Mikael will answer here already a possible solution...
                                  Did you find the problematic area while debugging?

                                  1 Reply Last reply Reply Quote 0
                                  • First post
                                    Last post