|
From: Stef M. <s.m...@ru...> - 2008-12-07 10:29:12
|
hello,
playing a few days with vpython,
I'm very satisfied, it's really powerful.
But I've the idea,
I'm missing a few convenience procedures (or at least they are hidden).
When animating our normal 3D world,
we always have a floor,
as a beginner I've the the xz-plane.
Now when moving objects with the mouse around in this environment,
I found out that the best thing todo is to project the mouse position on
the floor.
Ok there is a method for, so perfect.
But I also want other vectors to be projected onto the floor,
so I made a small ( 1 line ;-) routine for that.
After moving that routine to a general library,
I discovered that there's also a "proj" routine inside visual.
So apparently there might be some interesting hidden routines ?
Back to the angle difference,
for my case: mouse position and all objects projected to the floor,
you can unambiguous determine an angle between 0 and 2*pi.
This makes life so much easier.
So why isn't there a procedure for calculating such a difference angle ?
Or am I doing something stupid by projecting everything on the floor ?
Or does nobody uses these kind mouse interactions ?
Or ...?
Anyway here is the small method
def XZ_Angle ( axis ) :
"""projects the vector on the XZ-plane and
calculates the angle with the X-axis [ 0 .. 2*pi ]"""
axis = vector ( axis.x, 0, axis.z )
a1 = axis.diff_angle ( X_AXIS )
a2 = axis.diff_angle ( Z_AXIS )
if a2 < pi/2 :
a1 = 2*pi - a1
return a1
Although trivial, a procedure that translates radians into degrees is
very handy in debugging.
And of course the frame to world translation would be a good candidate
for the convenience library.
Just some thoughts of a beginner,
cheers,
Stef Mientki
|