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
Zitat
public void setZRotation(double angle)
{
m11 = Math.cos(angle);
m12 = Math.sin(angle);
m21 = -1*Math.sin(angle);
m22 = Math.cos(angle);
}
Quellcode |
|
1 |
renderer.render(g, mesh, rotateZMatrix.multiply(transScaleMatrix)); |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
public void render(Graphics g, Mesh mesh, Matrix4x4 modelTransform) { for(int i=0; i<mesh.numTriangles; i++) { // Transformation Vector3d v1 = projectionTransform.multiply(modelTransform.multiply(mesh.vertices[mesh.indices[3*i]])); v1.x += originX; v1.y += originY; Vector3d v2 = projectionTransform.multiply(modelTransform.multiply(mesh.vertices[mesh.indices[3*i+1]])); v2.x += originX; v2.y += originY; Vector3d v3 = projectionTransform.multiply(modelTransform.multiply(mesh.vertices[mesh.indices[3*i+2]])); v3.x += originX; v3.y += originY; // Zeichnen g.setColor(mesh.vertices[mesh.indices[3*i]].color); g.drawLine((int) v1.x, (int) v1.y, (int) v2.x, (int) v2.y); g.drawLine((int) v2.x, (int) v2.y, (int) v3.x, (int) v3.y); g.drawLine((int) v3.x, (int) v3.y , (int) v1.x, (int) v1.y); } } |
Quellcode |
|
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 28 29 30 31 32 33 34 35 |
public Vector3d multiply(Vector3d vec) { Vector3d result = new Vector3d(); result.x = vec.x*m11 + vec.y*m12 + vec.z*m13 + m14; result.y = vec.x*m21 + vec.y*m22 + vec.z*m23 + m24; result.z = vec.x*m31 + vec.y*m32 + vec.z*m33 + m34; return result; } public Matrix4x4 multiply(Matrix4x4 mat) { Matrix4x4 result = new Matrix4x4(); // row result.m11 = m11*mat.m11 + m12+mat.m21 + m13*mat.m31 + m14*mat.m41; result.m12 = m11*mat.m12 + m12*mat.m22 + m13*mat.m32 + m14*mat.m42; result.m13 = m11*mat.m13 + m12*mat.m23 + m13*mat.m33 + m14*mat.m43; result.m14 = m11*mat.m14 + m12*mat.m24 + m13*mat.m34 + m14*mat.m44; // row2 result.m21 = m21*mat.m11 + m22*mat.m21 + m23*mat.m31 + m24*mat.m41; result.m22 = m21*mat.m12 + m22*mat.m22 + m23*mat.m32 + m24*mat.m42; result.m23 = m21*mat.m13 + m22*mat.m23 + m23*mat.m33 + m24*mat.m43; result.m24 = m21*mat.m14 + m22*mat.m24 + m23*mat.m34 + m24*mat.m44;; // row3 result.m31 = m31*mat.m11 + m32*mat.m21 + m33*mat.m31 + m34*mat.m41; result.m32 = m31*mat.m12 + m32*mat.m22 + m33*mat.m32 + m34*mat.m42; result.m33 = m31*mat.m13 + m32*mat.m23 + m33*mat.m33 + m34*mat.m43; result.m34 = m31*mat.m14 + m32*mat.m24 + m33*mat.m34 + m34*mat.m44; // row result.m41 = m41*mat.m11 + m42*mat.m21 + m43*mat.m31 + m44*mat.m41; result.m42 = m41*mat.m12 + m42*mat.m22 + m43*mat.m32 + m44*mat.m42; result.m43 = m41*mat.m13 + m42*mat.m23 + m43*mat.m33 + m44*mat.m43; result.m44 = m41*mat.m14 + m42*mat.m24 + m43*mat.m34 + m44*mat.m44; return result; } |
Zitat von »"Nox"«
*dumididum*
result.m11 = m11*mat.m11 + m12+mat.m21 + m13*mat.m31 + m14*mat.m41;
*grins*
Edit: such die Zeile mal in deinem Code und vergleiche dann mal die Zeilen
Werbeanzeige