Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
public static Quaternion createRotationQuaterion(Vector3f a, Vector3f b){ a = a.normalise(new Vector3f()); b = b.normalise(new Vector3f()); Vector3f d = Vector3f.cross(a,b,new Vector3f()).normalise(new Vector3f()); //normlize hinzugefügt float co = Vector3f.dot(Vector3f.add(a, b, new Vector3f()).normalise(new Vector3f()),a); float si = (float) Math.sqrt(1.0 - co*co); return new Quaternion(d.x*si,d.y*si,d.z*si,co); //vec4(d * si, co); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
public static Matrix4f getRotationMatrix(Quaternion q) { Matrix4f ret = new Matrix4f(); float xx = q.x * q.x; float xy = q.x * q.y; float xz = q.x * q.z; float xw = q.x * q.w; float yy = q.y * q.y; float yz = q.y * q.z; float yw = q.y * q.w; float zz = q.z * q.z; float zw = q.z * q.w; ret.m00 = 1 - 2 * (yy + zz); ret.m01 = 2 * (xy - zw); ret.m02 = 2 * (xz + yw); ret.m10 = 2 * (xy + zw); ret.m11 = 1 - 2 * (xx + zz); ret.m12 = 2 * (yz - xw); ret.m20 = 2 * (xz - yw); ret.m21 = 2 * (yz + xw); ret.m22 = 1 - 2 * (xx + yy); ret.m03 = ret.m13 = ret.m23 = ret.m30 = ret.m31 = ret.m32 = 0; ret.m33 = 1; return ret; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 |
public static FloatBuffer quaternionToFloatBuffer(Quaternion q){ FloatBuffer fb = BufferUtils.createFloatBuffer(32); Rotation.getRotationMatrix(q).store(fb); fb.flip(); return fb; } |
Community-Fossil
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »dot« (11.09.2012, 20:23)
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 |
/* An Schnittpunkt verschieben */ GL11.glTranslatef(intersection.x, intersection.y, intersection.z); /* Rotieren */ GL11.glMultMatrix(quaternionToFloatBuffer(createRotationQuaterion(calcDirection(planet.getPosition(), building.getPosition()), planet.getPosition()))); // Zeichnen |
Community-Fossil
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
vec3 z = gebauedeausrichtungsvektor; // lokale Z-Achse, den hast du ja schon wie du sagst z.normalize(); vec3 x = vecCross(vec3(0, 1, 0), z); // X Achse errechnen x.normalize(); vec3 y = vecCross(x, z); // Y Achse errechnen y.normalize(); mat4 am = mat4(x.x, x.y, x.z, 0, // X Achse eintragen y.x, y.y, y.z, 0, // Y Achse eintragen z.x, z.y, z.z, 0, // Z Achse eintragen 0, 0, 0, 1); |
Administrator
C-/C++-Quelltext
1 vec3 x = vecCross(vec3(0, 1, 0), z); // X Achse errechnen
Community-Fossil
Zitat
Klappt nur nicht, wenn z = (0, 1, 0) ist, denn dann ist das Kreuzprodukt der Nullvektor.
Community-Fossil
Zitat
Vielen Dank, mit deinem Code funktioniert es tadellos! Ich hatte schon befürchtet, es wird nichts meh
Werbeanzeige