WorldViz User Forum Fluent viewpoint rotation towards an object
 User Name Remember Me? Password
 Register FAQ Search Today's Posts Mark Forums Read

 Thread Tools Rating: Display Modes
#1
05-07-2013, 07:53 AM
 4711 Member Join Date: Jan 2010 Posts: 15
Fluent viewpoint rotation towards an object

Hi everybody,

I have a simple question:

How can I fluently turn the viz.MainView towards an object somewhere in my environment (without knowing the angle between the current viewing direction and the object)?

I could do all the math behind such a rotation myself, but I guess there's a smarter and much shorter way to achive that with Vizard's built-in methods. What I'm looking for is basically what the "viz.MainView.lookAt" function already does, extended by the possibility for a fluent movement instead of the discrete jump in viewing direction.

Can anybody help me out with a good idea?

Thanks in advance!
#2
05-07-2013, 09:41 AM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
Are you using Vizard 3 or 4?

If you are using Vizard 4, then you can use the vizact.spinTo action to animate the viewpoint to look towards a specific point. Example:
Code:
```# Animate looking at specified point for half a second
lookAtAction = vizact.spinTo(point=(0,1.8,8),time=0.5,interpolate=vizact.easeOut)

# Add action to main view
viz.MainView.runAction(lookAtAction)```
#3
05-07-2013, 10:14 AM
 4711 Member Join Date: Jan 2010 Posts: 15
farshizzo,

thanks for the quick reply. I'm running my script under Vizard 3, since large parts were written before the release of Vizard 4. Unfortunately, it seems like your code doesn't produce the result it's supposed to in Vizard 3.

Is there any other possibility how this could work in Vizard 3?
#4
05-09-2013, 09:12 AM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
You can still use the spinto action in Vizard 3, however you will need to manually calculate the final rotation to spinto. You can do this by saving the main views current rotation, call the lookat function and save the new rotation, then restore the previous rotation.
#5
05-23-2013, 03:58 AM
 4711 Member Join Date: Jan 2010 Posts: 15
farshizzo,

I can't see how quickly setting the viewpoint towards the object via "lookat()" and then set it back again to the original direction can work without resulting in a short flickering in the viewpoint. Maybe I got you wrong?
#6
05-23-2013, 04:20 AM
 4711 Member Join Date: Jan 2010 Posts: 15
I wrote some code myself to solve the problem:

Code:
```import math
import viz

# --- REQUIRED FUNCTIONS --- #

def Angle2Euler( angle ):

euler = 0

# Not defined for negative values
if angle < 0:
return 0

# Calculate 'euler' depending on quadrant
else:
if angle <= 90:
# Q1
euler = 90 - angle
elif angle <= 270:
# Q2 & Q3
euler = -( angle-90 )
else:
# Q4
euler = 360 - angle + 90

return euler

def Cart2Pol( x, y, unit='rad' ):

# Radius
r = math.sqrt( math.pow(x,2) + math.pow(y,2) )

# Angle in [rad]
t = math.atan2( y ,x )

# Angle in [deg]
if unit.lower() == 'deg':
t = math.degrees( math.atan(float(y)/float(x)) )
if x < 0:
t += 180 # Q2 & Q3
elif x > 0 and y < 0:
t += 360 # Q4

return r, t

def LookAt( Target ):

# Get current position and orientation
Pos = viz.MainView.getPosition()
Ori = viz.MainView.getEuler()

# Define position as 2D point 'P'
P = [Pos[0], Pos[2]]

# Define target as 2D point 'T'
T = [Target[0], Target[2]]

# Shift 'P' into origin (= 'P0') and
# move 'T' accordingly (= 'T0')
T0 = [T[0]-P[0], T[1]-P[1]]

# Get location of 'T0' as polar angle
angle = Cart2Pol( T0[0], T0[1], 'deg' )[1]

# Convert angle to Vizard's Euler style
euler = Angle2Euler( angle )

# Create rotation action towards target
rotation = vizact.spinTo( euler=[euler,0,0], time=2 )

# Apply rotation to MainView
viz.MainView.runAction( rotation )

# --- AN EXAMPLE --- #

# Go!
viz.add('court.ive')
viz.go()

# Add a box behind the MainView
box = viz.add('box.wrl')
box.setPosition([-5,1.7,-10])

# Look at the box
LookAt( box.getPosition() )```
This may not be the easiest or most elegant way, but it works!

 Tags fluent, rotation, viewpoint

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements Vizard Precision Position Tracker (PPT) Plug-in development

 Similar Threads Thread Thread Starter Forum Replies Last Post Darkmax Vizard 1 11-12-2010 12:52 PM Philippe Vizard 5 10-07-2010 05:31 PM Xianshi Xie Vizard 1 06-22-2009 12:31 PM Andrey Vizard 4 06-13-2007 03:49 PM paulgoldberg Vizard 5 09-05-2006 12:33 PM

All times are GMT -7. The time now is 11:18 AM.

 Contact Us - WorldViz Home - Archive - Top

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC