# Using PyODE (setting rotations)

Hi, I’m using PyODE to do some physics simulation in my application. From PyODE I can do body.getPosition , body.getRotation.
Setting position is simple -> I just call node.setPos(position) and it works.
The problem is that body.getRotation returns a row major rotation matrix for the object.

How can I use this matrix with a Panda3d object?

THanks

dunno if this helps you. but might be worth looking at since its a ODE sample in cobination with panda. tried it myself month ago and worked quite well.
https://discourse.panda3d.org/viewtopic.php?t=1485&highlight=ode
if not. just try to search the forum for “ode”

There is a setCell / getCell function on Mat4 & Mat3 matrix in panda3D.

I use following code to convert from Newton to P3D and from P33D to Newton.

Newton follow a row major convention (it’s the same convention than DirectX in fact).

`````` def toNewtonMatrix(self,P3Dmatrix):
nMat=nMatrix()
offset=0
for i in range(4):
for j in range(4):
nMat[offset+j]=c_float(P3Dmatrix.getCell(i,j))
offset=offset+j+1
return nMat

def toP3DMatrix(self,NEWTONmatrix):
pMat=Mat4(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0)
offset=0
for i in range(4):
for j in range(4):
pMat.setCell(i,j,NEWTONmatrix[offset+j])
offset=offset+j+1
return pMat``````

Hi,

this is what I do:

``````   def set_model_pos_and_rot (self, pos = None, rot = None):
if not pos:
pos = self.geom.getPosition ()
if not rot:
q = self.geom.getQuaternion () # (w, x, y, z)
gquat = Quat (q [0], q [1], q [2], q [3])
else:
gquat = Quat ()
gquat.setFromMatrix (Mat3 (*rot))
gpos = VBase3 (pos [0], pos [1], pos [2])
self.model.setPosQuat (gpos, gquat)``````

Cheerio
Peter