- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
My goal is to design a CAD mouse similar to the 3Dconnexions Spacemouse. So what I want to do is to move the scenery & not the origin of the part. But other than the camera, I don't see what variable I have to work with.
I'm running some tests to understand how the camera movements are working, but I encounter a few issues with the rotations & translations.
For example, if I'm trying to rotate 360deg on the Z-axis while it's at the horizontal. The object will rotate around the Z-axis about 180deg, then flip (mirror) the camera & then execute the other 180deg. The only time it works fine is when the axis of rotation is vertical.
The translations & the scaling don't seem to work when you play in the matrix3D. The scaling can be dealt with the camera viewExtents. But the translation just doesn't seem to work. Any ideas on how to deal with this
Thanks in advance!
import adsk.core, adsk.fusion, adsk.cam, traceback
import math
rotationX = 1
rotationY = 1
rotationZ = 0.02
scalingX = 0.0
scalingY = 0.0
scalingZ = 0.0
translationX = 10
translationY = 0
translationZ = 0
rotateX = [1.0, 0.0, 0.0, 0.0,
0.0, math.cos(rotationX), math.sin(rotationX), 0.0,
0.0, -1*math.sin(rotationX), math.cos(rotationX), 0.0,
0.0, 0.0, 0.0, 1.0]
rotateY = [math.cos(rotationY), 0.0, math.sin(rotationY), 0.0,
0.0, 1.0, 0.0, 0.0,
-1*math.sin(rotationY), 0.0, math.cos(rotationY), 0.0,
0.0, 0.0, 0.0, 1.0]
rotateZ = [math.cos(rotationZ), math.sin(rotationZ), 0.0, 0.0,
-1*math.sin(rotationZ), math.cos(rotationZ), 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0]
scale = [scalingX, 0.0, 0.0, 0.0,
0.0, scalingY, 0.0, 0.0,
0.0, 0.0, scalingZ, 0.0,
0.0, 0.0, 0.0, 1.0]
translation = [1.0, 0.0, 0.0, translationX,
0.0, 1.0, 0.0, translationY,
0.0, 0.0, 1.0, translationZ,
0.0, 0.0, 0.0, 1.0]
test = [0.707, 0.707, 0.0, 5.0,
0.707, 0.707, 0.0, 10.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0]
def run(context):
ui = None
try:
app: adsk.core.Application = adsk.core.Application.get()
ui = app.userInterface
vi = app.activeViewport
camera = vi.camera
eye = camera.eye
# tgt = camera.target
# up = camera.upVector
zoom = camera.viewExtents
camera.isSmoothTransition = False
mat = adsk.core.Matrix3D.create()
print(mat.asArray())
# print(mat.translation)
# vector = adsk.core.Vector3D.create(4.0, 0.0, 0.0)
# show
for n in range(360):
# camera.viewExtents = zoom + n
mat.setWithArray(translation)
# mat.tanslation = vector
eye.transformBy(mat)
print(mat.asArray())
camera.eye = eye
# camera.upVector = vector
vi.camera = camera
vi.refresh()
adsk.doEvents()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.