I tried those coords:
[code=delphi]
Vert[0] := 0.0;
Vert[1] := 1.0;
Vert[2] := 0.0;
Vert[3] := -1.0;
Vert[4] := -1.0;
Vert[5] := 0.0;
Vert[6] := 1.0;
Vert[7] := -1.0;
Vert[8] := 0.0;
[/code]
Matrix code:
[code=delphi]
Cam := MatrixTransform(VectorNegate(Camera.Pos), VectorUniform(0.0),
VectorUniform(1.0));
ModelView := MatrixTransform(VectorCreate(0.0, 0.0, 0.0),
VectorCreate(0.0, TriangleRot, 0.0), VectorUniform(0.5));
ModelView := MatrixMultiply(ModelView, Cam);
glUniformMatrix4fv(glGetUniformLocation(ShaderMana ger.GLSLPrograms['minimal'].
ProgramHandle, 'modelViewMatrix'), 1, ByteBool(GL_FALSE), @ModelView);
[/code]
And changed the MatrixTransform function back to its original form:
Code:
{ .: MatrixTransform :. }
function MatrixTransform(const Position, Rotation, Scale: TVector): TMatrix;
var
CosRx, CosRy, CosRz: Single;
SinRx, SinRy, SinRz: Single;
begin
CosRx := Cos(Rotation.X); // Used 6x
CosRy := Cos(Rotation.Y); // Used 4x
CosRz := Cos(Rotation.Z); // Used 4x
SinRx := Sin(Rotation.X); // Used 5x
SinRy := Sin(Rotation.Y); // Used 5x
SinRz := Sin(Rotation.Z); // Used 5x
Result := MatrixIdentity;
with Result do
begin
_11 := CosRy * CosRz * Scale.X;
_12 := CosRy * SinRz * Scale.X;
_13 := -SinRy * Scale.X;
_21 := (CosRz * SinRx * SinRy * Scale.Y) - (CosRx * SinRz * Scale.Y);
_22 := (CosRx * CosRz * Scale.Y) + (SinRx * SinRy * SinRz * Scale.Y);
_23 := CosRy * SinRx * Scale.Y;
_31 := (CosRx * CosRz * SinRy * Scale.Z) + (SinRx * SinRz * Scale.Z);
_32 := (-CosRz * SinRx * Scale.Z) + (CosRx * SinRy * SinRz * Scale.Z);
_33 := CosRx * CosRy * Scale.Z;
_41 := Position.X;
_42 := Position.Y;
_43 := Position.Z;
end;
end;
And it worked! It even worked when I changed the coordinates to (3,0,0), so this approach seems to be working well.
Can someone explain why it does work and what I should do to avoid such mistakes in the future?
Bookmarks