Manipulating views using matrices

Manipulating views using matrices

Anonymous
Not applicable
1,097 Views
8 Replies
Message 1 of 9

Manipulating views using matrices

Anonymous
Not applicable
It seems to me there is a way of manipulating Inventor views using matrices. There are Matrix objects, and the cameras can get/set the view to World Matrix etc.

Is there any good documentation on this? I would like to mimic OpenGL behaviour in Inventor, for example applying translation matrices to the view in order to move stuff around.

Using VC++

/p6
0 Likes
1,098 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
I really need to know if this is possible.

Can I somehow apply a matrix to the current view to translate/rotate etc?

Thanks
0 Likes
Message 3 of 9

Anonymous
Not applicable
>Is there any good documentation on this?

The Help=>Additional Resources=>Programming Help is a good place to start.


Are you talking about DrawingViews? If so, then the Camera is a Read-only property so it cannot be edited.

If you are talking about the Application.ActiveView, then you can manipulate the camera, however there isn't a method that applies a transform matrix to the camera.

>I would like to mimic OpenGL behaviour in Inventor, for example applying translation matrices to the view in order to move stuff around.

Do you mean "move stuff around" w.r.t. the assembly coordinate system? If so, then you might check into the ComponentOccurrence.Transformation property.
0 Likes
Message 4 of 9

Anonymous
Not applicable
Josh, thanks for your reply.

I was hoping to manipulate the Application.ActiveView with a matrix, but perhaps I can get the same effect by transforming every object in the view instead, by using ComponentOccurrence.

If I transform all objects in my active view with the inverse transform matrix meant for the camera, the effect would be the same.. correct?
0 Likes
Message 5 of 9

Anonymous
Not applicable
The View object in Inventor is basically just a wrapper for the window and
doesn't control what's being viewed within the window. This control is
exposed through the Camera object, which you get from the View object. You
can't explicitly define the camera using a matrix, but you could derive the
information from a matrix to set the various properties of the Camera. The
camera is defined by an eye and target point and up vector. For a
perspective camera you can also supply a perspective angle or for a parallel
camera you can define the extents of the viewable volume.

Here's an example that will fly around the curent part or assembly.

Public Sub FlyAround()
Dim oCamera As Camera
Set oCamera = ThisApplication.ActiveView.Camera

' Create a circle that will reprsent the path of the camera
' where the target point and up vector will remain the same
' but the eye will sweep around.
Dim oCircle As Inventor.Circle
Set oCircle = ThisApplication.TransientGeometry.CreateCircle( _
oCamera.Target, oCamera.UpVector,
oCamera.Target.DistanceTo(oCamera.Eye))

Dim iStepCount As Integer
iStepCount = Val(InputBox("Enter number of steps", "Camera Sample",
"360"))

' Get the evaluator from the circle to get points along the circle.
Dim oCurveEval As CurveEvaluator
Set oCurveEval = oCircle.Evaluator

' Define Pi
Dim dPi As Double
dPi = Atn(1) * 4

' Calculate the angle to step with each increment.
Dim dIncrement As Double
dIncrement = (dPi * 2) / iStepCount

' Determine the position along the circle where the eye currently is.
Dim dCurrent As Double
Dim adEye(2) As Double
adEye(0) = oCamera.Eye.X
adEye(1) = oCamera.Eye.Y
adEye(2) = oCamera.Eye.Z
Dim adGuessparams() As Double
Dim adMaxDeviations() As Double
Dim adParams(0) As Double
Dim aenSolTypes() As SolutionNatureEnum
Call oCurveEval.GetParamAtPoint(adEye, adGuessparams, _
adMaxDeviations, adParams, aenSolTypes)

' Initialize the position using the current eye position.
dCurrent = adParams(0)

' Step around the circle.
Dim i As Integer
For i = 1 To iStepCount
' Calculate a point on the circle using the current parameter.
adParams(0) = dCurrent
Dim adPoint(2) As Double
Call oCurveEval.GetPointAtParam(adParams, adPoint)

' Create a point that defines the eye position.
Dim oNewEye As Point
Set oNewEye = ThisApplication.TransientGeometry.CreatePoint( _
adPoint(0), adPoint(1), adPoint(2))

' Set the eye and apply the camera.
oCamera.Eye = oNewEye
oCamera.ApplyWithoutTransition

' Increment the parameter value.
dCurrent = dCurrent + dIncrement
Next
End Sub
--
Brian Ekins
Autodesk Inventor API

wrote in message news:5944061@discussion.autodesk.com...
Josh, thanks for your reply.

I was hoping to manipulate the Application.ActiveView with a matrix, but
perhaps I can get the same effect by transforming every object in the view
instead, by using ComponentOccurrence.

If I transform all objects in my active view with the inverse transform
matrix meant for the camera, the effect would be the same.. correct?
0 Likes
Message 6 of 9

Anonymous
Not applicable
Brian, thanks for this in depth code snippet.

Let me quickly explain what I'm after;

I have a couple of matrices that I want to use for changing the active view. I know how to derive the translation (x, y, z point) from these matrices, and can move the camera using these.

The problem arise when I want to calculate the angle of the camera. Do you have any suggestion as how to derive the required information from the matrix and apply this as a "rotation" to the camera? (I think it would involve moving the camera target, but I can't figure out with what values)

regards,
p6
0 Likes
Message 7 of 9

Anonymous
Not applicable
I haven't done much with view matrices so I would have to look into more
before I could give a decent answer. I did a quick look on the web and what
I could find it seems the view matrix is defining the position of the camera
in view space but also typically uses a left-hand coordinate system so that
will need to be taken into account. Where are you getting your matrix from?
I don't have time to look into any further at this point but it seems with
some experimentation it shouldn't be too difficult to figure out.
--
Brian Ekins
Autodesk Inventor API
0 Likes
Message 8 of 9

Anonymous
Not applicable
>when I want to calculate the angle of the camera.

are you talking about the orientation of the camera, the rotation of the camera about the view axis or the perspective angle?


If you use the simple model that the camera coordinate system is aligned such that Z points along the view, Y is up, and X points to the right when standing behind the camera, then you can use:

Target = P + Z (where P is position of the camera and Z is the z unit vector from the matrix)

Up Vector = Y
0 Likes
Message 9 of 9

Anonymous
Not applicable

Please HELP...

 

 

Thanks Brian for your wonderfull code to move the camera!

It works very fine in VBA!

 

I tried to use this in VB.NET for my AddIn and got the following Error:

System.ArgumentException: Falscher Parameter. (Ausnahme von HRESULT: 0x80070057 (E_INVALIDARG))

   bei System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)

   bei Inventor.CurveEvaluator.GetParamAtPoint(Double[]& Points, Double[]& GuessParams, Double[]& MaxDeviations, Double[]& Params, SolutionNatureEnum[]& SolTypes)

 

Here are the VB.NET code:

    Public Sub FlyAround()
        Dim oCamera As Inventor.Camera
        oCamera = objInventorApp.ActiveView.Camera

        ' Create a circle that will reprsent the path of the camera
        ' where the target point and up vector will remain the same
        ' but the eye will sweep around.
        Dim oCircle As Inventor.Circle
        oCircle = objInventorApp.TransientGeometry.CreateCircle(oCamera.Target, oCamera.UpVector, oCamera.Target.DistanceTo(oCamera.Eye))

        Dim iStepCount As Integer
        iStepCount = Val(InputBox("Enter number of steps", "Camera Sample", "360"))

        ' Get the evaluator from the circle to get points along the circle.
        Dim oCurveEval As Inventor.CurveEvaluator
        oCurveEval = oCircle.Evaluator

        ' Define Pi
        Dim dPi As Double
        'dPi = System.Math.Atan(1) * 4
        dPi = System.Math.PI

        ' Calculate the angle to step with each increment.
        Dim dIncrement As Double
        dIncrement = (dPi * 2) / iStepCount

        ' Determine the position along the circle where the eye currently is.
        Dim dCurrent As Double
        Dim adEye(2) As Double
        adEye(0) = oCamera.Eye.X
        adEye(1) = oCamera.Eye.Y
        adEye(2) = oCamera.Eye.Z
        Dim adGuessparams() As Double = {}
        Dim adMaxDeviations() As Double = {}
        Dim adParams(0) As Double
        Dim aenSolTypes() As Inventor.SolutionNatureEnum = {}
        Call oCurveEval.GetParamAtPoint(adEye, adGuessparams, adMaxDeviations, adParams, aenSolTypes)

        ' Initialize the position using the current eye position.
        dCurrent = adParams(0)

        ' Step around the circle.
        Dim i As Integer
        For i = 1 To iStepCount
            ' Calculate a point on the circle using the current parameter.
            adParams(0) = dCurrent
            Dim adPoint(2) As Double
            Call oCurveEval.GetPointAtParam(adParams, adPoint)

            ' Create a point that defines the eye position.
            Dim oNewEye As Inventor.Point
            oNewEye = objInventorApp.TransientGeometry.CreatePoint(adPoint(0), adPoint(1), adPoint(2))

            ' Set the eye and apply the camera.
            oCamera.Eye = oNewEye
            oCamera.ApplyWithoutTransition()

            ' Increment the parameter value.
            dCurrent = dCurrent + dIncrement
        Next

    End Sub

 

 What are the invalid argument(s) that passed to the GetParamAtPoint function?

 

I verified the values that passed to the GetParamAtPoint function from VBA and VB.NET and they are the same.

 

Please HELP, Thanks!

0 Likes