Align BulletCylinderShape z-axis with vector


#1

Hi all,

Please advise if it is possible to align the z-axis of a BulletCylinderShape with a 3D vector i.e. I have to coordinates say [0, 0, 0] and [10, 0, 0]. I want the cylinder to then lie on the x-axis from 0 to 10.

Thank you


#2

You can indicate which axis it should lie on in the third argument of BulletCylinderShape:

from panda3d import bullet

cyl = bullet.BulletCylinderShape(radius, height, bullet.X_up)

However, you can also just apply a rotation or use lookAt on the NodePath pointing to the rigid body with the cylinder shape.


#3

Hi, @rdb

What if I have two points like [5, 5, 5] and [1, 2, 3]?


#4

Untested, but this should do the job:

# Given these parameters...
radius = 1.0
pt1 = Point3(5, 5, 5)
pt2 = Point3(1, 2, 3)

# Calculate center and length
center = (pt1 + pt2) * 0.5
height = (pt1 - pt2).length()

# Create the shape and rigid body along the Y axis
shape = BulletCylinderShape(radius, height, Y_up)
cyl_path = render.attach_new_node(BulletRigidBodyNode('cylinder'))
cyl_path.node().add_shape(shape)

# Position it at the center and make it look to either point on the Y axis
cyl_path.set_pos(center)
cyl_path.look_at(pt2)

#5

Works great @rdb! Thank you so much!!