.NET API has exposed the ability of viewpoint camera. There are some blogs:
Navisworks .NET API 2013 new feature – Viewpoint 1
Navisworks .NET API 2013 new feature – Viewpoint 2
In COM API, there are some objects which can also manipulate camera. This is a demo sample
Download Manipulat_ecamera_plugin_vs2010
In the following, we take the code snippet to explain some aspects how to use these APIs.
1. It is very straightforward if you want to set position, AlignUp, e.g.
using Com = Autodesk.Navisworks.Api.Interop.ComApi;
private void buttonPosition_Click(object sender, EventArgs e)
{
//InputXYZ is a dialog in the sample
// get input of X-Y-Z values of the new position
InputXYZ oInput = new InputXYZ();
if (oInput.ShowDialog() ==
System.Windows.Forms.DialogResult.OK)
{
//
// Group up edits so get recorded as one operation for Undo.
//
m_state.BeginEdit("Position Camera");
//
// Get camera and set position.
//
Com.InwNvCamera cam = m_state.CurrentView.ViewPoint.Camera;
cam.Position.SetValue(
Double.Parse(oInput.corX),
Double.Parse(oInput.corY),
Double.Parse(oInput.corZ));
// edit ends
m_state.EndEdit();
}
}
private void buttonAlignUp_Click(object sender, EventArgs e)
{
//InputXYZ is a dialog in the sample
// get input of X-Y-Z values of the new AlignUp
InputXYZ oInput = new InputXYZ();
if (oInput.ShowDialog() ==
System.Windows.Forms.DialogResult.OK)
{
m_state.BeginEdit("Align Up");
Com.InwNvCamera cam =
m_state.CurrentView.ViewPoint.Camera;
//
// Let's align "Up" vector along the specified axis
//
// create a new vector based on the new values
Com.InwLVec3f vec =
(Com.InwLVec3f)
(object)m_state.ObjectFactory(
Com.nwEObjectType.eObjectType_nwLVec3f);
vec.SetValue(Double.Parse(oInput.corX),
Double.Parse(oInput.corY),
Double.Parse(oInput.corZ));
// align up with the new vector.
cam.AlignUp(vec);
m_state.EndEdit();
}
}
The internal camera representation is a position and an orientation. No LookAt value is stored. You could calculate a look at value using position + ViewDir. If the camera is part of a viewpoint, it may have a focal distance which can be used to calculate a better look at point. If not defined, the FocalDistance property will throw an exception. If defined LookAt = Postion + FocalDistance * ViewDir.
2. Rotation is a bit complex. You can directly modify the camera Rotation property which is stored as rotation around an axis (equivalent to a Quaternion). http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation. The attached sample provides a very useful tool class for Quaternion. You can use it to convert the Rotation of API to Quaternion, or vice verse. With that, the Rotation is much simple. e.g.
private void RotateCamera(double angle)
{
m_state.BeginEdit("Rotate Camera");
Com.InwNvCamera cam = m_state.CurrentView.ViewPoint.Camera;
//
// Here, we create a new Quaternion from the camera rotation.
//
Quaternion orig = new Quaternion(cam.Rotation);
//
// And create a Quaternion to represent the rotation we want to
// apply to the camera.
//
//Quaternion delta = Quaternion.FromAngleAxis(0, 0, 1, angle);
Quaternion delta =
Quaternion.FromAngleAxis(Double.Parse(textRotX.Text),
Double.Parse(textRotY.Text),
Double.Parse(textRotZ.Text), angle);
//
// And we simply multiple the original rotation with the new one.
//
Quaternion new_rot = Quaternion.Multiply(orig, delta);
//
// And update the rotation of the camera.
//
cam.Rotation = new_rot.ToRotation();
m_state.EndEdit();
updatePos();
}