Hello.
I need some help fixing a transformation to place a component instance.
I have a group within which there is:
- a curve that is not necessarily flat.
- A “target” component instance.
I want to place at each point of the curve a “camera” component instance that points to the origin of the “target” instance.
I created a transformation to place the instance. The instance is placed in the right place, looking straight at the target, but has had an unwanted rotation around its X axis. I would like the horizon line of the camera instance to remain horizontal.
Here is my code
def self.place_camera(group,cam_point,target)
# cam_point is a point in the curve
# target is the origin of the instance target
cam_def = Sketchup.active_model.definitions.select{|d| d.name=="Camera"}[0]
if cam_def == nil
url = Sketchup.find_support_file("Camera.skp", "Plugins/" + FOLDER + "/skp/")
cam_def = Sketchup.active_model.definitions.load(url)
end
vector = cam_point.vector_to(target)
if vector.parallel?(X_AXIS)
t_rot = Geom::Transformation.rotation cam_point,vector,0
else
t_rot = Geom::Transformation.rotation cam_point, vector * X_AXIS, vector.angle_between(X_AXIS)
end
vecteur_origine = cam_point.vector_to(ORIGIN)
t_tra = Geom::Transformation.translation(vecteur_origine)
t = t_tra * t_rot
ti = t.inverse
camera = group.entities.add_instance(cam_def,ti)
return camera
end
Thanks in advance for your help.
Simon