C++ API - Create a camera and set active viewport to that camera

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 03 March 2009   #1
C++ API - Create a camera and set active viewport to that camera

Hi,
Here is a question,
how can I create a camera and set it to current viewport view in C++ API,

here is code so far,


M3dView view;
MObject camera;
MDagPath cameraPath;
// create new camera
view = M3dView::active3dView(&status);
MFnCamera fnCamera;
fnCamera.create(camera,NULL);
//
// get dagpath for new camera
cameraPath = pathFromObject(camera);
view.setCamera(cameraPath); // this is causing maya crash


Camara creation successful but setCamera results in Maya crash,
I wonder how can I get dagPath of a newly created MObject,

Thanks
__________________
Vishang Shah
http://shahvishang.blogspot.com/
 
Old 03 March 2009   #2
getPath

Found the answer,

M3dView view;
MObject camera;
MDagPath cameraPath;
// create new camera
view = M3dView::active3dView(&status);
MFnCamera fnCamera;
fnCamera.create(camera);
fnCamera.getPath(cameraPath);
//
view.setCamera(cameraPath); // this is causing maya crash
__________________
Vishang Shah
http://shahvishang.blogspot.com/
 
Old 03 March 2009   #3
MFnCamera::create() returns the transform for a newly created camera, in case you don't provide one as first parameter. You do but it's MObject::kNullObj, so you actually don't.

Using MObject camera = fnCamera.create(); will return the transform of the new camera.

Get the MDagPath of that transform or its shape, don't know which one you need exactly and you're done.
__________________
Freelance | Consulting | Development | Autodesk Authorized Developer
Boole | Stitch | Konstrukt | SmartDuplicate | Wire | Contours | MultiTool
 
Old 03 March 2009   #4
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 04:06 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.