THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 04/01/2011 at 14:06, xxxxxxxx wrote:
Cinema 4D Version:
Hi; I'm looking for a functionality to read the current camera pivot (3D rotational center, not the view center) that the view uses for its rotation. I need this for SpaceMouse support.
I can read the camera itself, no problem. I can evaluate the various attributes of a camera and determine the pivot if the mode is Position/Custom. And if the camera rotation is Default and the Model tool is active, I can read the temporary center of the objects (multiselection) through GetRealActiveObject()...
However, my current method leaves a lot to be desired.
First, I evaluate camera settings (and eventually tool settings) manually, so any native change in finding the pivot (e.g. a new mode) is not automatically reflected by my plugin, and any mode/tool I don't support will not work in my plugin.
Second, it's a processing time hog. I can't really compute the center of a point selection myself each time the user moves the SpaceMouse. (I can't even easily use start-drag and end-drag events which are available for the 2D mouse since you only move the SpaceMouse instead of a click-drag-release action.)
Third, it's too much work :-)
I see that C4D's native SpaceMouse support supplies its own (limited) number of modes, which would solve the problem, but leave a bad aftertaste since I really want to support the same options that the real mouse has.
So: How do I ask the system for the current pivot - no matter what tool is selected, what camera mode, what modeling axis, what the selection of objects or points is? Just the same pivot that is used by the GUI when I rotate the view by icon.
On 04/01/2011 at 14:11, xxxxxxxx wrote:
Just to reiterate: I'm not looking for GetRealActiveObject, GetHelperAxis, or CAMERAOBJECT_PIVOT_POSITION. These are all methods / parameters that work only in specific modes or with specific tools.
(forgot to fill in: Version R12, but info about R10 upwards is appreciated... C++ API)
On 05/01/2011 at 14:23, xxxxxxxx wrote:
After a bit of experimenting, it seems that BaseObject's GetModelingAxis() is the closest I can get. I can read a helper / dummy object from the doc that "somehow" represents the current selection:
BaseObject* objcenter = doc->GetRealActiveObject(NULL, NULL);
Then I get the modeling axis as a matrix and reduce it to the position to get the pivot. This works although the objcenter is merely a dummy, and what's even more important, it works for an active polygon tool as well as for an active model tool, in which case the modeling axis is the common center of the selected objects.
Matrix centermat = objcenter->GetModelingAxis(doc);
pivot = centermat.off;
This is still not quite what I'd like to have: it doesn't query the camera settings (it represents only the Object mode), and it doesn't look at the Preferences where you can set a default camera behavior, but at least it solves the most urgent problem of getting the modeling axis for point/edge/polygon tool mode.
On 14/01/2011 at 02:18, xxxxxxxx wrote:
There is currently no way to get the current camera pivot directly. So unfortunatly it's really up to the plugin developer to calculate the pivot.
On 14/01/2011 at 03:17, xxxxxxxx wrote:
Hmm, okay. This is what I'm doing now, and it's several screen pages long, so I will describe it here for documentation:
First, determine the camera of the view:
BaseDraw* basedraw = doc->GetActiveBaseDraw();
BaseObject* camera = NULL;
camera = basedraw->GetSceneCamera(doc);
camera = basedraw->GetEditorCamera();
Then, look into the camera's CAMERAOBJECT_MODE.
If that is CAMERAOBJECT_MODE_DEFAULT, read the preferences (GetWorldContainerInstance) and look at WPREF_CAMERAROTATION.
The values for Center, Camera, and World (for some reason, there don't seem to be any proper constants for WPREF_CAMERAROTATION's values) can be mapped to the camera constants CAMERAOBJECT_MODE_CENTER, CAMERAOBJECT_MODE_CAMERA and CAMERAOBJECT_MODE_WORLD. Mapped, because they are not numerically equal even when they represent the same behavior.
The value for Object, however, can not be mapped to CAMERAOBJECT_MODE_OBJECT, as one would like to expect - this camera mode requires further settings for Object or Pivot, and when you select CAMERAOBJECT_MODE_DEFAULT, then these settings are not there. Consequently, when the preferences are set to Object, only the modeling axis is taken into account, which is a significantly different behavior from CAMERAOBJECT_MODE_OBJECT. Thus, I map it to CAMERAOBJECT_MODE_DEFAULT for simple "switch"ing later on.
You now should evaluate the current keyboard qualifiers, since SHIFT changes the mode to "rotate around active object", and CTRL changes it to "rotate around camera origin", which would be my mapped cases CAMERAOBJECT_MODE_DEFAULT and CAMERAOBJECT_MODE_CAMERA. (I don't have the qualifiers in my input situation, so I don't take them into account.)
Now you can "switch" across your mapped modes. If it's World or Camera, the pivot is right at hand (although in the case of Camera, it will present problems later on when you want to adapt panning speed to the current pivot's distance, which is 0 in this case). If it's Default, we use the ModelingAxis of the RealActiveObject, which works both for object and point/edge/polygon selections.
The mode Object is a bit more complex, because it has two allowed submodes through the camera's CAMERAOBJECT_PIVOT value: CAMERAOBJECT_PIVOT_OBJECT and CAMERAOBJECT_PIVOT_CUSTOM. In case of the first, I look for the object link (CAMERAOBJECT_MODE_LINK); if present, I use it's axis. If not, I take the ModelingAxis of the RealActiveObject again. In case of the second, the pivot has been set by the user directly and can be read as vector value CAMERAOBJECT_PIVOT_POSITION.
The final mode CAMERAOBJECT_MODE_CENTER does not only allow these two submodes, but three(!!!) more: CAMERAOBJECT_PIVOT_AXIS, CAMERAOBJECT_PIVOT_VIEW, and CAMERAOBJECT_PIVOT_CLOSEST. Now don't ask me how to work through these... CAMERAOBJECT_PIVOT_AXIS seems to do the same as CAMERAOBJECT_PIVOT_OBJECT, and the "closest" algorithms for the other two give me a headache. Plus, when you HAVE calculated the potential pivot, you still need to project it to the camera's z axis to keep the real pivot in the view center, and you need to do it in a way that subsequent rotations will not move the pivot depth towards or away from the camera. I really think I shouldn't support these modes... Maxon really went over the top with options here, and I don't have a clue what significant usecases are met here (that couldn't be covered by the other options).
Would love to have a look at the original "calculate pivot" code at Maxon's...