几何尺寸与公差论坛

 找回密码
 注册
查看: 1018|回复: 0

【转帖】icamera manipulation

[复制链接]
发表于 2009-4-12 18:41:16 | 显示全部楼层 |阅读模式
icamera manipulation ?
hello!
i am very interested - what are the ideas and rules of using method and properties of icamera ?
the documentation is very poor. i can't figure out which methods should i use
the problem is that i can't reconstruct the view correctly.
i capture settings of perspective camera at 1st position, change the view, then try to reset camera to 1st position and failed.
does anybody know?
so what exactly are you trying to do. what camera name are you getting the settings from, and then why are you trying to clone them instead of just setting the current camera view back to the same camera?
hello mentor-
i have many solidworks templates with studio lights and camera locations. so, set up what you want and just save the file as a template. assembly templates work good for me, i can just drag a part or assembly file into it.
if you go here, to my blog, i have a presentation on this method:
2 luke:
well, imagine i have perspective camera
the settings for the 1st view are:
camera info: 'camera3' (1)
+type = swcameratype_floating
+aspectratio = 1.29412
+perspective = 1
+fieldofviewangle = 0.660595
+fieldofviewdepth = 0.269172
+fieldofviewheight = 0.184575
getfocaldistance = 0.824514
getpointofinterestdistance = 0.266712
getposition = -0.198427 -0.0056169 0.0679377
getpositioncartesian = -0.198427 -0.0056169 0.0679377
getpositionspherical = 0 0 0
getupvector = -0.0419549 0.999111 0.00415019
getviewvector = 0.997862 0.0421101 -0.0499752
+positiontype = swcameraposition_spherical
+rotationrollangle = 0.00204643
+targetpointposition = 0.0431823 0.00457909 0.0558373
then i rotate and pan model a bit:
camera info: 'camera3' (1)
+type = swcameratype_floating
+aspectratio = 1.29412
+perspective = 1
+fieldofviewangle = 0.660595
+fieldofviewdepth = 0.269172
+fieldofviewheight = 0.184575
getfocaldistance = 0.824514
getpointofinterestdistance = 0.268543
getposition = -0.174815 0.11702 -0.0643902
getpositioncartesian = -0.174815 0.11702 -0.0643902
getpositionspherical = 0 0 0
getupvector = 0.42336 0.905925 0.00814997
getviewvector = 0.898266 -0.420917 0.126282
+positiontype = swcameraposition_spherical
+rotationrollangle = -0.0508896
+targetpointposition = 0.0426793 0.0151045 -0.0338139
so, which api in which order should i use to reset camera to the 1st view?
well if the camera is called "camera3" then just loop all cameras, check the name, and set the current camera... but if you are modifying the actual camera then you should create a new camera first using modeldocextension.insertcamera and set its values to the initial settings, then reset it after:
swmodelview.setcamerabyname "camera3"
well, the problem is not with selecting the camera, but with the setting camera's settings
i have already inserted and selected my new camera. now i want to manipulate it (pan, rotate, zoom). i previously have recorded camera's settings and now want to apply them to my new camera.
but i fail.
in particular,
imagine, i move model from left corner to the right (with the tool "pan", without any rotation and zoom). in camera-settings terms, it means that only targetpointposition & getpositioncartesian settings are changed.
when i rotate camera, lots of settings are changed, including setpositionspherical.
so i reset all the settings' to the recorded once, but they are not applied.
not sure i understand your problem. get the camera with:
lnumcameras = swmodel.extension.getcameracount
for lcameraid = 0 to (lnumcameras - 1)
set swcamera = swmodel.extension.getcamerabyid(lcameraid)
if swcamera.name = "camera3"
' got camera, do what you want with it...
next
then you just set the properties like:
swcamera.fieldofviewangle = ... etc
where exactly is the issue does it not work for you?
i should be more specific
well, there's a perspective not-locked floating camera, selected in view. it's grabbed settings are:
camera info: 'camera1' (0)
+type = swcameratype_floating
+aspectratio = 1.29412
+perspective = 1
+fieldofviewangle = 0.47109
+fieldofviewdepth = 0.202107
+fieldofviewheight = 0.0970112
getfocaldistance = 0.276344
getpointofinterestdistance = 0.326413
getposition = -0.0692115 0.0174997 -0.326413
getpositioncartesian = -0.0692115 0.0174997 -0.326413
getpositionspherical = 0.276344 -3.14159 -0
getupvector = 0 1 0
getviewvector = 0 0 1
+positiontype = swcameraposition_spherical
+rotationrollangle = 0
+targetpointposition = -0.0692115 0.0174997 -0.0500687
then i move my model from left corner to right with "pan" tool only (no zooming & no rotation). we get new camera settings:
camera info: 'camera1' (0)
+type = swcameratype_floating
+aspectratio = 1.29412
+perspective = 1
+fieldofviewangle = 0.47109
+fieldofviewdepth = 0.202107
+fieldofviewheight = 0.0970112
getfocaldistance = 0.276344
getpointofinterestdistance = 0.326413
getposition = 0.0543433 0.0213403 -0.326413
getpositioncartesian = 0.0543433 0.0213403 -0.326413
getpositionspherical = 0.276344 -3.14159 -0
getupvector = 0 1 0
getviewvector = 0 0 1
+positiontype = swcameraposition_spherical
+rotationrollangle = 0
+targetpointposition = 0.0543433 0.0213403 -0.0500687
as we can see, only 'positioncartesian' & 'targetposition' properties have changed - so i use them to reset camera to the 1st position. and it works! i get the model at the left corner!
the same situation with zoom & with pan+zoom. i only use those properties and it works.
but, of course, i should use something more if i have rotation. after rotation+zoom+pan camera has settings as below:
camera info: 'camera1' (0)
+type = swcameratype_floating
+aspectratio = 1.29412
+perspective = 1
+fieldofviewangle = 0.47109
+fieldofviewdepth = 0.202107
+fieldofviewheight = 0.0970112
getfocaldistance = 0.276344
getpointofinterestdistance = 0.218617
getposition = -0.0262508 -0.15383 -0.139299
getpositioncartesian = -0.0262508 -0.15383 -0.139299
getpositionspherical = 0.276344 -2.74235 -0.883587
getupvector = -0.263653 0.633882 -0.727104
getviewvector = 0.2466 0.773019 0.584491
+positiontype = swcameraposition_spherical
+rotationrollangle = -0.0397354
+targetpointposition = 0.0418955 0.0597893 0.0222218
as we can see, settings 'pointofinterestdistance', 'position', 'positioncartesian', 'positionspherical', 'rotationrollangle' & 'targetpointposition' have changed. what should i do to reset camera to the 1st settings?
simple list of calls, passing values from the 1st set:
camera.setpositioncartesian(...);
camera.setpositionspherical(...);
camera.setrotationrollangle(...);
camera.settargetpointposition(...);
does not make camera to have exactly the same settings!
that is the problem. hope i made it clear now
p.s.
i attached an example. if you wonder, you may:
1) extract, compile.
2) start solidworks, register addin.
3) open some model.
4) insert camera.
5) make it to be perspective, floating and not-locked.
6) select it into the view.
7) under "swaddin1" menu, select "capture 1st camera position" menu item - the camera's settings are grabbed.
8) change the view - rotate a little.
9) under "swaddin1" menu, select "reset camera position to 1st" menu item - as you can see, model didn't return to 1st position ( as it was before (8) ).
edited: 03/27/2009 at 04:39 am by mentor graphics
hi mentor-
did you know you can save animations in assembly templates? all these settings could be saved in the template.
it just seems like a lot of work to program all this.
good luck.
best regards,
devon t. sowell
certified solidworks professional
originally posted by: luke malpass
well if the camera is called "camera3" then just loop all cameras, check the name, and set the current camera... but if you are modifying the actual camera then you should create a new camera first using modeldocextension.insertcamera and set its values to the initial settings, then reset it after:
swmodelview.setcamerabyname "camera3"
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2025-1-3 10:36 , Processed in 0.039694 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表