# Convert euler rotation to lookAt() coordinates

``````file.write("    def loadLights(self):\n")
for x in lampObjs:
loc = bpy.context.selected_objects[0].location
color = bpy.data.lamps[str(x[1])].color
rotDeg = [(x[3][0] * 180) / 3.14, (x[3][1] * 180) / 3.14, (x[3][2] * 180) / 3.14]
lookAt = [ ?, ?, ?]
file.write("        " + 'PL' + str(x[1]) + ".lookAt(" + str(lookAt[0]) + ", " + str(lookAt[1]) + ", " + str(lookAt[2]) + ")\n")``````

I am writing a export script in blender for panda3d. I have converted the euler angles to degrees found in rotDeg. Now I need to find a lookAt point based on the position of the light and it’s rotation angle. I am not certain what this is called, thus when I google this nothing comes up. If I at least knew what this was called I know I could find the answer on google. It’s been too many years since linear algebra and I am embarrassed to now admit that I have forgotten some of the terminology.

quaternion?

Since you’re writing the script, I’m not sure why you don’t just write out the simpler and more reliable hpr coordinates rather than a “lookAt point”. There’s not really a name for this, by the way; it’s just a point relative to the node.

You can get it with something like this:

``point = node.getParent().getRelativePoint(node, Point3(0, 1, 0))``

David

I tried setting the spotlight hpr, however for whatever reason it would not shift the light to the correct point. I am doing this as a last resort. Thank you by the way for all your input. Perhaps if I better explain things everyone will understand my predicament. I am exporting a spotlight that shines only on the edge of a cube mesh. When I do lookAt(cube), it looks dead on at it. I want the spotlight to behave and look identical to the way it does in blender and export a spotlight that shines only on the outer edge. I planed to do this by taking it’s position and rotation angles, then calculate a lookAt() to reflect what is in blender. Early on I looked for any alternatives, including checking if the spotlights in blender have a directional vector the light shines. Turns out it is the rotation itself, apparently blender takes the position and rotation of the spotlight and calculates the vector on it’s own. What formula is used is unknown to me. Is there a feature like this in panda3d that will let me point the light with angles. setHpr in spotlight is not working, is it supposed to work? The following is the code generated by the export what is wrong with it?

``````import sys,os
import cPickle

from pandac.PandaModules import *
from panda3d.core import *
from direct.showbase.ShowBase import ShowBase
from direct.gui.OnscreenText import OnscreenText
from direct.showbase.DirectObject import DirectObject
from math import sin, cos, pi
from random import randint, choice, random
from direct.interval.MetaInterval import Sequence
from direct.interval.FunctionInterval import Wait,Func

class MyApp(ShowBase):
Cube.reparentTo(render)
Cube.setHpr(0.0, 23.65774808415941, 0.0)
Cube.setPos(-1.7526661157608032, -0.4768316447734833, 0.372225284576416)
Cube.setScale(3.584214448928833, 4.571809768676758, 1.8086028099060059)
Spot = Spotlight('Spot')
Spot.setColor(VBase4(1.0, 1.0, 1.0, 1))
lens = PerspectiveLens()
Spot.setLens(lens)
PLSpot = render.attachNewNode(Spot)
render.setLight(PLSpot)
PLSpot.setPos(0.3962751626968384, 0.0, 6.3677520751953125)
PLSpot.setHpr(0.0, 18.13152, 0.0)
#PLSpot.lookAt(0, 0, 0)
def __init__(self):
ShowBase.__init__(self)
self.accept('escape', sys.exit )
app = MyApp()
app.run()``````

Oh, you mean you’re extracting data from Blender? You’d probably be better off asking on the Blender forums what form their rotation vector is in. There are several likely guesses, but your chances are fairly low that it’s an Euler triple, so yeah, I wouldn’t expect to be able to shove that value in for setHpr().

Once you know how Blender represents a rotation, then you can figure out how to convert that representation to one of the forms that Panda understands. But you don’t have a chance without first knowing what those three numbers mean to Blender.

David

I’ve found euler very unreliable, because two programs may apply the rotations in a different order. If possible get a quaternion rotation from Blender instead. Typically in any 3D modeller you will have access to at least one of quaternion or 4x4 matrix, both will be more reliable than euler.

Lets say I have a quaternion of (1,1,1,1) in the form (w,x,y,z). How would I go about applying this to a object in panda3d? I thought I needed to use setQuat(m1,m2) format. But was not sure how to set up the matrices with four float values.

You can use

``nodepath.setQuat(Quat(w, x, y, z))``