Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I guess you are using the measured acceleration to find the direction of gravitational pull (ie, down). If you are moving the accelerometer, apart from just turning it, there will be some additional force; think of the accelerometer having a pendulum weight handing from it, as you move it the pendulum sways (although in this case it would be a very short, fast-reacting pendulum?). You could try doing some sort of movement compensation, but it might be simpler to just try to keep the sensor in a fixed location.</p> <p><strong>Edit:</strong> ok, it looks like I totally misread the question - you want to know <em>how</em> to do the rotation in a script?</p> <p>It looks like each Blender object has three properties (.RotX, .RotY, .RotZ) which contain the current values (in radians) and a method (.rot(new_rotx, new_roty, new_rotz)) which performs a rotation (see documentation at <a href="http://www.blender.org/documentation/249PythonDoc/Object.Object-class.html" rel="nofollow">http://www.blender.org/documentation/249PythonDoc/Object.Object-class.html</a>). I am currently looking at how the rotations are applied; more shortly.</p> <p><strong>Edit2:</strong> it looks like the angles are specified as Euler angles (http://en.wikipedia.org/wiki/Euler_angles); they give some conversion matrices. It also looks like your accelerometer data is underconstrained (you need one more constraint, specifying rotation about the 'down' direction - maybe some sort of inertial 'least distance from previous position' calculation?)</p> <p><strong>Edit3:</strong> there is a sample script which may be helpful; on my machine it is at C:\Users\Me\AppData\Roaming\Blender Foundation\Blender.blender\scripts\object_random_loc_sz_rot.py It shows how to get the currently selected object and tweak its rotation. Hope that helps!</p> <p><strong>Edit4:</strong> for sake of discussion, here is some sample code; it may be a bit redundant (I haven't worked in Blender before) and it doesn't <em>solve</em> the problem, but it will at least give us a common basis for further discussion ;-)</p> <pre><code>#!BPY """ Name: 'Set rotation by accelerometer' Blender: 249 Group: 'Object' Tooltip: 'Set the selected objects rotation by accelerometer' """ __bpydoc__=\ ''' This script sets the selected objects rotation by accelerometer. ''' from Blender import Draw, Scene import math def reorient(alpha, beta, gamma): a = math.cos(alpha) b = math.sin(alpha) c = math.cos(beta) d = math.sin(beta) e = math.cos(gamma) f = math.sin(gamma) ad = a*d bd = b*d return = [ [c*e, -a*f+b*d*e, b*f+a*d*e], [c*f, a*e+b*d*f, -b*e+a*d*f], [-d, b*c, a*c ] ] def getAccel(): # test stub - # need to get actual values from accelerometer here dx = -700 dy = 100 dz = 250 return (dx,dy,dz) def normalize(vec): "Return scaled unit vector" x,y,z = vec mag = (x*x + y*y + z*z)**0.5 return (x/mag, y/mag, z/mag) def main(): scn = Scene.GetCurrent() try: obj = scn.objects.context euler = (obj.RotX, obj.RotY, obj.RotZ) except AttributeError: return down = normalize(getAccel()) matrix = None # do something here to find new rotation-matrix # based on euler and down # then if matrix: obj.setOrientation(matrix) else: # test value: # if reorient() is working properly, the # object's rotation should not change! obj.setOrientation(reorient(*euler)) if __name__=="__main__": main() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload