1
Support / Rotating a cylinder in a direction given by a simple vector
« on: April 16, 2012, 10:40:51 pm »
I don't get it.
I have a cylinder representing a line. And on building it, I want to translate it to a certain point (working) and rotate it, that it looks into the same direction as a given vector. The last thing does not work.
When I give the vector
* (1/0/0), the cylinder's direction is the z-axis (or -z, I could not see),
* (0/1/0) the cylinder's direction is also the z-axis (or -z)
* (0/0/1) the cylinde's direction is the x-axis.
I changed the coordinate system to an "upright" as needed in school.
Almost the same code works fine with points (as already said, translating works) and even planes (translating and rotating so that the normal vector looks into a given direction.
Can anybody help?
I have a cylinder representing a line. And on building it, I want to translate it to a certain point (working) and rotate it, that it looks into the same direction as a given vector. The last thing does not work.
When I give the vector
* (1/0/0), the cylinder's direction is the z-axis (or -z, I could not see),
* (0/1/0) the cylinder's direction is also the z-axis (or -z)
* (0/0/1) the cylinde's direction is the x-axis.
I changed the coordinate system to an "upright" as needed in school.
Code: [Select]
public static void addGerade(Gerade g){
Object3D gt = Primitives.getCylinder(6, 0.1f, 150);
// Changing the ccordinates from the calculated line to the ones needed to draw it
double ax = g.getA().getX1();
double ay = -g.getA().getX3();
double az = g.getA().getX2();
double rx = g.getV().getX();
double ry = -g.getV().getZ();
double rz = g.getV().getY();
SimpleVector Aufpunkt = new SimpleVector (ax, ay, az);
SimpleVector Richtung = new SimpleVector(rx, ry, rz);
Matrix r = Richtung.getRotationMatrix();
gt.setRotationMatrix(r);
gt.translate(Aufpunkt);
gt.setTexture("linet");
gt.build();
world.addObject(gt);
buffer.clear(java.awt.Color.DARK_GRAY);
world.renderScene(buffer);
// world.drawWireframe(buffer, Color.WHITE);
world.draw(buffer);
buffer.update();
}
Almost the same code works fine with points (as already said, translating works) and even planes (translating and rotating so that the normal vector looks into a given direction.
Can anybody help?