(Dit topic ging eerst over iets anders, maar dat was snel na het plaatsen opgelost.)Met behulp van
dit Wikipedia artikel heb ik een simpele 3D projectie van een kubus gemaakt:
/// create
for (i = 0; i < 10; i++) {
node[i] = instance_create(0, 0, obj_node); // obj_node is leeg naast het draw event
node[i].number = i;
}
for (i = 0; i < 3; i++) {
for (ii = 0; i < 3; i++) {
xRotationMatrix[i, ii] = 0;
yRotationMatrix[i, ii] = 0;
zRotationMatrix[i, ii] = 0;
}
}
/// draw event
matrix_update();
projection(node[0], x - 32, y - 32, 0);
projection(node[1], x + 32, y - 32, 0);
projection(node[2], x + 32, y + 32, 0);
projection(node[3], x - 32, y + 32, 0);
projection(node[4], x - 32, y - 32, 64);
projection(node[5], x + 32, y - 32, 64);
projection(node[6], x + 32, y + 32, 64);
projection(node[7], x - 32, y + 32, 64);
/// matrix_update();
xRotationMatrix[0, 0] = 1;
xRotationMatrix[0, 1] = 0;
xRotationMatrix[0, 2] = 0;
xRotationMatrix[1, 0] = 0;
xRotationMatrix[1, 1] = cos(rotX);
xRotationMatrix[1, 2] = -sin(rotX);
xRotationMatrix[2, 0] = 0;
xRotationMatrix[2, 1] = sin(rotX);
xRotationMatrix[2, 2] = cos(rotX);
yRotationMatrix[0, 0] = cos(rotY);
yRotationMatrix[0, 1] = 0;
yRotationMatrix[0, 2] = sin(rotY);
yRotationMatrix[1, 0] = 0;
yRotationMatrix[1, 1] = 1;
yRotationMatrix[1, 2] = 0;
yRotationMatrix[2, 0] = -sin(rotY);
yRotationMatrix[2, 1] = 0;
yRotationMatrix[2, 2] = cos(rotY);
zRotationMatrix[0, 0] = cos(rotZ);
zRotationMatrix[0, 1] = -sin(rotZ);
zRotationMatrix[0, 2] = 0;
zRotationMatrix[1, 0] = sin(rotZ);
zRotationMatrix[1, 1] = cos(rotZ);
zRotationMatrix[1, 2] = 0;
zRotationMatrix[2, 0] = 0;
zRotationMatrix[2, 1] = 0;
zRotationMatrix[2, 2] = 1;
/// projection(node, x, y, z);
// dus in principe gewoon het doelwit met de gewenste coördinaten in een niet-bestaande driedimensionale ruimte
var X, Y, Z, XX, YY, ZZ;
X = xRotationMatrix[0, 0] * argument1 + xRotationMatrix[0, 1] * argument2 + xRotationMatrix[0, 2] * argument3;
Y = xRotationMatrix[1, 0] * argument1 + xRotationMatrix[1, 1] * argument2 + xRotationMatrix[1, 2] * argument3;
Z = xRotationMatrix[2, 0] * argument1 + xRotationMatrix[2, 1] * argument2 + xRotationMatrix[2, 2] * argument3;
XX = yRotationMatrix[0, 0] * X + yRotationMatrix[0, 1] * Y + yRotationMatrix[0, 2] * Z;
YY = yRotationMatrix[1, 0] * X + yRotationMatrix[1, 1] * Y + yRotationMatrix[1, 2] * Z;
ZZ = yRotationMatrix[2, 0] * X + yRotationMatrix[2, 1] * Y + yRotationMatrix[2, 2] * Z;
argument0.x = zRotationMatrix[0, 0] * XX + zRotationMatrix[0, 1] * YY + zRotationMatrix[0, 2] * ZZ;
argument0.y = zRotationMatrix[1, 0] * XX + zRotationMatrix[1, 1] * YY + zRotationMatrix[1, 2] * ZZ;
// ik heb momenteel geen z-coördinaat nodig
Resultaat:

De punten kan ik verbinden met een simpel script:
/// draw_line_nodes();
// niet per se nodig, maar het is wel zo makkelijk
draw_line(node[argument0].x, node[argument0].y, node[argument1].x, node[argument0].y);

Om de kubus te vullen zou ik deze gewoon een aantal honderd keer op een steeds kleinere schaal kunnen tekenen (nog niets getest), maar dat lijkt mij heel inefficiënt. Wat is de beste manier om deze kubus op te vullen? Ik zoek een oplossing die ook werkt met complexere figuren, maar belichting is hier niet van belang.