Registriert seit: 26. Nov 2004
Ort: Dresden
274 Beiträge
Delphi 10.3 Rio
|
AW: E2070 unbekannte Direktive 'operator'
30. Mär 2022, 18:57
Ah, ok, die Syntax unterscheidet sich also hier von der in Freepascal.
In wie fern ist es bei FreePascal anders?
Zitat:
the syntax must be compatible with Delphi.
Lediglich der Operatoren Bezeichner.
Zitat:
Note that some FPC operators do not have an equivalent usin a Delphi name.
Nachdem ich alles hier gelesen habe würde ich gern mal auf das hier eingehen:
meinen Quellcode hae ich aus Freepascal übernommen.
Bitte zeige mal etwas davon, ich vermute du redest bzw meinst etwas anderes.
Delphi-Quellcode:
unit vipmath;
interface
uses math,tools;
const
M_PI = 3.14159265358979323846;
type
v3dVector = {packed} record
x,y,z,w:single;
class operator Sub(a,b:v3dVector):v3dVector; //Bereits an Delphi angepasst, den Record brauche in in FP nicht
class operator Mul (a,b: v3dVector):single;
class operator Mul (a,b:v3dVector):v3dVector;
class operator add (a,b:v3dVector):v3dVector;
class operator Mul (a:v3dVector; s:single):v3dVector;
class operator Mul (m:v3dMatrix;v:v3dVector):v3dVector;
class operator Mul (a,b:v3dMatrix):v3dMatrix;
end;
v3dMatrix = array [0..3,0..3] of single;
function aVector(x,y,z:single):v3dVector;
//operator - (a,b:v3dVector):v3dVector;
function v3dDot(a,b:v3dVector):single;
//operator * (a,b:v3dVector):single; So werden die Operatoren in Freepascal definiert
function v3dCross(a,b:v3dVector):v3dVector;
//operator * (a,b:v3dVector):v3dVector; hier nun auskommentiert und im Implementationsteil
Delphi gerecht definiert
function v3dGetLength(v:v3dVector):single;
function v3dNormalize(v:v3dVector):v3dVector;
//operator + (a,b:v3dVector):v3dVector;
//operator * (a:v3dVector; s:single):v3dVector;
function v3dIdentity:v3dMatrix;
//operator * (m:v3dMatrix;v:v3dVector):v3dVector;
//operator * (a,b:v3dMatrix):v3dMatrix;
function v3dMatrixMulIgnoreW(m:v3dMatrix;v:v3dVector):v3dVector;
function v3dMatrixRotateX(a:single):v3dMatrix;
function v3dMatrixRotateY(a:single):v3dMatrix;
function v3dMatrixRotateZ(a:single):v3dMatrix;
function v3dMatrixTranslate(v:v3dVector):v3dMatrix;
function v3dInvertMatrixOrtho(m:v3dMatrix):v3dMatrix;
procedure v3dDumpMatrix(matrix:v3dMatrix);
implementation
function aVector(x,y,z:single):v3dVector;
begin
result.x:=x;
result.y:=y;
result.z:=z;
result.w:=sqrt(x*x + y*y + z*z);
end;
class operator v3dVector.Sub (a,b:v3dVector):v3dVector;
var x,y,z:single;
begin
x:=a.x - b.x;
y:=a.y - b.y;
z:=a.z - b.z;
result:=aVector(x,y,z);
end;
function v3dGetLength(v:v3dVector):single;
begin
v3dGetLength:=sqrt(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w);
end;
function v3dNormalize(v:v3dVector):v3dVector;
var l:single;
begin
l:=v3dGetLength(v);
result.x:=v.x / l;
result.y:=v.y / l;
result.z:=v.z / l;
result.w:=v.w / l;
end;
function v3dDot(a,b:v3dVector):single;
begin
v3dDot:=a.x*b.x + a.y*b.y + a.z*b.z;
end;
function v3dCross(a,b:v3dVector):v3dVector;
var x,y,z:single;
begin
result.x:=a.y * b.z - a.z * b.y;
result.y:=a.z * b.x - a.x * b.z;
result.z:=a.x * b.y - a.y * b.x;
result.w:=1;
end;
class v3dVector. operator Mul (a,b:v3dVector):single;
begin
result:=v3dDot(a,b);
end;
class v3dVector. operator Mul (a,b:v3dVector):v3dVector;
begin
result:=v3dCross(a,b);
end;
class v3dVector. operator Add (a,b:v3dVector):v3dVector;
var x,y,z:single;
begin
x:=a.x + b.x;
y:=a.y + b.Y;
z:=a.z + b.z;
result:=aVector(x,y,z);
end;
class v3dVector. operator Mul (a:v3dVector; s:single):v3dVector;
var x,y,z:single;
begin
x:=a.x * s;
y:=a.y * s;
z:=a.z * s;
result:=aVector(x,y,z);
end;
function v3dIdentity:v3dMatrix;
var m:v3dMatrix;
begin
m[0,0]:=1;
m[0,1]:=0;
m[0,2]:=0;
m[0,3]:=0;
m[1,0]:=0;
m[1,1]:=1;
m[1,2]:=0;
m[1,3]:=0;
m[2,0]:=0;
m[2,1]:=0;
m[2,2]:=1;
m[2,3]:=0;
m[3,0]:=0;
m[3,1]:=0;
m[3,2]:=0;
m[3,3]:=1;
v3dIdentity:=m;
end;
class v3dVector. operator Mul (m:v3dMatrix; v:v3dVector):v3dVector;
begin
result.x:=(m[0,0]*v.x)+(m[1,0]*v.y)+(m[2,0]*v.z)+(m[3,0]*v.w);
result.y:=(m[0,1]*v.x)+(m[1,1]*v.y)+(m[2,1]*v.z)+(m[3,1]*v.w);
result.z:=(m[0,2]*v.x)+(m[1,2]*v.y)+(m[2,2]*v.z)+(m[3,2]*v.w);
result.w:=(m[0,3]*v.x)+(m[1,3]*v.y)+(m[2,3]*v.z)+(m[3,3]*v.w);
end;
function v3dMatrixMulIgnoreW(m:v3dMatrix;v:v3dVector):v3dVector;
begin
result.x:=m[0,0] * v.x + m[0,1] * v.y + m[0,2] * v.z;
result.y:=m[1,0] * v.x + m[1,1] * v.y + m[1,2] * v.z;
result.z:=m[2,0] * v.x + m[2,1] * v.y + m[2,2] * v.z;
result.w:=v.w;
end;
class v3dVector. operator Mul (a,b:v3dMatrix):v3dMatrix;
begin
result[0,0]:=(a[0,0]*b[0,0])+(a[0,1]*b[1,0])+(a[0,2]*b[2,0])+(a[0,3]*b[3,0]);
result[0,1]:=(a[0,0]*b[0,1])+(a[0,1]*b[1,1])+(a[0,2]*b[2,1])+(a[0,3]*b[3,1]);
result[0,2]:=(a[0,0]*b[0,2])+(a[0,1]*b[1,2])+(a[0,2]*b[2,2])+(a[0,3]*b[3,2]);
result[0,3]:=(a[0,0]*b[0,3])+(a[0,1]*b[1,3])+(a[0,2]*b[2,3])+(a[0,3]*b[3,3]);
result[1,0]:=(a[1,0]*b[0,0])+(a[1,1]*b[1,0])+(a[1,2]*b[2,0])+(a[1,3]*b[3,0]);
result[1,1]:=(a[1,0]*b[0,1])+(a[1,1]*b[1,1])+(a[1,2]*b[2,1])+(a[1,3]*b[3,1]);
result[1,2]:=(a[1,0]*b[0,2])+(a[1,1]*b[1,2])+(a[1,2]*b[2,2])+(a[1,3]*b[3,2]);
result[1,3]:=(a[1,0]*b[0,3])+(a[1,1]*b[1,3])+(a[1,2]*b[2,3])+(a[1,3]*b[3,3]);
result[2,0]:=(a[2,0]*b[0,0])+(a[2,1]*b[1,0])+(a[2,2]*b[2,0])+(a[2,3]*b[3,0]);
result[2,1]:=(a[2,0]*b[0,1])+(a[2,1]*b[1,1])+(a[2,2]*b[2,1])+(a[2,3]*b[3,1]);
result[2,2]:=(a[2,0]*b[0,2])+(a[2,1]*b[1,2])+(a[2,2]*b[2,2])+(a[2,3]*b[3,2]);
result[2,3]:=(a[2,0]*b[0,3])+(a[2,1]*b[1,3])+(a[2,2]*b[2,3])+(a[2,3]*b[3,3]);
result[3,0]:=(a[3,0]*b[0,0])+(a[3,1]*b[1,0])+(a[3,2]*b[2,0])+(a[3,3]*b[3,0]);
result[3,1]:=(a[3,0]*b[0,1])+(a[3,1]*b[1,1])+(a[3,2]*b[2,1])+(a[3,3]*b[3,1]);
result[3,2]:=(a[3,0]*b[0,2])+(a[3,1]*b[1,2])+(a[3,2]*b[2,2])+(a[3,3]*b[3,2]);
result[3,3]:=(a[3,0]*b[0,3])+(a[3,1]*b[1,3])+(a[3,2]*b[2,3])+(a[3,3]*b[3,3]);
end;
function v3dMatrixRotateX(a:single):v3dMatrix;
var
c,s:single;
m:v3dMatrix;
begin
c:= cos(a);
s:= sin(a);
// | 1 0 0 0 |
// | 0 c -s 0 |
// | 0 s c 0 |
// | 0 0 0 1 |
m:= v3dIdentity;
m[1,1]:= c;
//m[1,2]:= -s; //orig
//m[2,1]:= s; //orig
m[1,2]:= s; //bero
m[2,1]:= -s; //bero
m[2,2]:= c;
result:=m;
end;
function v3dMatrixRotateY(a:single):v3dMatrix;
var
c,s:single;
m:v3dMatrix;
begin
c:= cos(a);
s:= sin(a);
// | c 0 s 0 |
// | 0 1 0 0 |
// | -s 0 c 0 |
// | 0 0 0 1 |
m:= v3dIdentity;
m[0,0]:= c;
// m[0,2]:= s; // orig
// m[2,0]:= -s; // orig
m[0,2]:= -s; // bero
m[2,0]:= s; // bero
m[2,2]:= c;
result:=m;
end;
function v3dMatrixRotateZ(a:single):v3dMatrix;
var
c,s:single;
m:v3dMatrix;
begin
c:=cos(a);
s:=sin(a);
// | c -s 0 0 |
// | s c 0 0 |
// | 0 0 1 0 |
// | 0 0 0 1 |
m:=v3dIdentity;
m[0,0]:= c;
// m[0,1]:= -s; // orig
// m[1,0]:= s; // orig
m[0,1]:= s; // bero
m[1,0]:= -s; // bero
m[1,1]:= c;
result:=m;
end;
function v3dMatrixTranslate(v:v3dVector):v3dMatrix;
var m:v3dMatrix;
begin
// | 1 0 0 tx |
// | 0 1 0 ty |
// | 0 0 1 tz |
// | 0 0 0 1 |
{
m:= v3dIdentity();
m[0,3]:=v.x;
m[1,3]:=v.y;
m[2,3]:=v.z;
result:=m;
}
result[0,0]:=1.0;
result[0,1]:=0.0;
result[0,2]:=0.0;
result[0,3]:=0.0;
result[1,0]:=0.0;
result[1,1]:=1.0;
result[1,2]:=0.0;
result[1,3]:=0.0;
result[2,0]:=0.0;
result[2,1]:=0.0;
result[2,2]:=1.0;
result[2,3]:=0.0;
result[3,0]:=v.x;
result[3,1]:=v.y;
result[3,2]:=v.z;
result[3,3]:=1.0;
end;
function v3dInvertMatrixOrtho(m:v3dMatrix):v3dMatrix;
var j,k:integer;
begin
for j:=0 to 3 do
for k:=0 to 3 do begin
result[j][k]:=m[k][j];
end;
end;
{
var
det:single;
im:v3dMatrix;
A2323,A1323,A1223,A0323,A0223,A0123,A2313,A1313,A1213,A2312,A1312,A1212,A0313,A0213,A0312,A0212,A0113,A0112:single;
begin
A2323:= m[2, 2] * m[3, 3] - m[2, 3] * m[3, 2];
A1323:= m[2, 1] * m[3, 3] - m[2, 3] * m[3, 1];
A1223:= m[2, 1] * m[3, 2] - m[2, 2] * m[3, 1];
A0323:= m[2, 0] * m[3, 3] - m[2, 3] * m[3, 0];
A0223:= m[2, 0] * m[3, 2] - m[2, 2] * m[3, 0];
A0123:= m[2, 0] * m[3, 1] - m[2, 1] * m[3, 0];
A2313:= m[1, 2] * m[3, 3] - m[1, 3] * m[3, 2];
A1313:= m[1, 1] * m[3, 3] - m[1, 3] * m[3, 1];
A1213:= m[1, 1] * m[3, 2] - m[1, 2] * m[3, 1];
A2312:= m[1, 2] * m[2, 3] - m[1, 3] * m[2, 2];
A1312:= m[1, 1] * m[2, 3] - m[1, 3] * m[2, 1];
A1212:= m[1, 1] * m[2, 2] - m[1, 2] * m[2, 1];
A0313:= m[1, 0] * m[3, 3] - m[1, 3] * m[3, 0];
A0213:= m[1, 0] * m[3, 2] - m[1, 2] * m[3, 0];
A0312:= m[1, 0] * m[2, 3] - m[1, 3] * m[2, 0];
A0212:= m[1, 0] * m[2, 2] - m[1, 2] * m[2, 0];
A0113:= m[1, 0] * m[3, 1] - m[1, 1] * m[3, 0];
A0112:= m[1, 0] * m[2, 1] - m[1, 1] * m[2, 0];
det:= m[0, 0] * ( m[1, 1] * A2323 - m[1, 2] * A1323 + m[1, 3] * A1223 )
- m[0, 1] * ( m[1, 0] * A2323 - m[1, 2] * A0323 + m[1, 3] * A0223 )
+ m[0, 2] * ( m[1, 0] * A1323 - m[1, 1] * A0323 + m[1, 3] * A0123 )
- m[0, 3] * ( m[1, 0] * A1223 - m[1, 1] * A0223 + m[1, 2] * A0123 );
det:= 1 / det;
im[0, 0]:= det * ( m[1, 1] * A2323 - m[1, 2] * A1323 + m[1, 3] * A1223 );
im[0, 1]:= det * - ( m[0, 1] * A2323 - m[0, 2] * A1323 + m[0, 3] * A1223 );
im[0, 2]:= det * ( m[0, 1] * A2313 - m[0, 2] * A1313 + m[0, 3] * A1213 );
im[0, 3]:= det * - ( m[0, 1] * A2312 - m[0, 2] * A1312 + m[0, 3] * A1212 );
im[1, 0]:= det * - ( m[1, 0] * A2323 - m[1, 2] * A0323 + m[1, 3] * A0223 );
im[1, 1]:= det * ( m[0, 0] * A2323 - m[0, 2] * A0323 + m[0, 3] * A0223 );
im[1, 2]:= det * - ( m[0, 0] * A2313 - m[0, 2] * A0313 + m[0, 3] * A0213 );
im[1, 3]:= det * ( m[0, 0] * A2312 - m[0, 2] * A0312 + m[0, 3] * A0212 );
im[2, 0]:= det * ( m[1, 0] * A1323 - m[1, 1] * A0323 + m[1, 3] * A0123 );
im[2, 1]:= det * - ( m[0, 0] * A1323 - m[0, 1] * A0323 + m[0, 3] * A0123 );
im[2, 2]:= det * ( m[0, 0] * A1313 - m[0, 1] * A0313 + m[0, 3] * A0113 );
im[2, 3]:= det * - ( m[0, 0] * A1312 - m[0, 1] * A0312 + m[0, 3] * A0112 );
im[3, 0]:= det * - ( m[1, 0] * A1223 - m[1, 1] * A0223 + m[1, 2] * A0123 );
im[3, 1]:= det * ( m[0, 0] * A1223 - m[0, 1] * A0223 + m[0, 2] * A0123 );
im[3, 2]:= det * - ( m[0, 0] * A1213 - m[0, 1] * A0213 + m[0, 2] * A0113 );
im[3, 3]:= det * ( m[0, 0] * A1212 - m[0, 1] * A0212 + m[0, 2] * A0112 );
result:=im;
end;
}
procedure v3dDumpMatrix(matrix:v3dMatrix);
begin
log(' matrix');
log(floatstr(matrix[0,0]));
log(floatstr(matrix[0,1]));
log(floatstr(matrix[0,2]));
log(floatstr(matrix[0,3]));
log(floatstr(matrix[1,0]));
log(floatstr(matrix[1,1]));
log(floatstr(matrix[1,2]));
log(floatstr(matrix[1,3]));
log(floatstr(matrix[2,0]));
log(floatstr(matrix[2,1]));
log(floatstr(matrix[2,2]));
log(floatstr(matrix[2,3]));
log(floatstr(matrix[3,0]));
log(floatstr(matrix[3,1]));
log(floatstr(matrix[3,2]));
log(floatstr(matrix[3,3]));
end;
begin
end.
Ist schon auf class Operator geändert. In Freepascal werden nur im Interfaceteil die Operatoren definiert und im Implementationsteil mit Operatorkopf und begin end implementiert, den Record brauche in in FP nicht, wobei da auch Sonderzeichen für den Operator zulässig sind, womit ich den Operator mit dem ansonsten für die Operation verwendeten Zeichen benennen kann, was in Delphi nicht der Fall ist, da muss ich ein Alphanumerisches Wort definieren wie Mul für Multiplikation, Sub für Subtraktion statt "*" für Multiplikation oder "-" für Subtraktion.
Compiler meckert aber hier in der ersten Operatorzeile mit "Ungültige Operatordeklaration". Was mache ich da noch falsch?
Geändert von delphifan2004 (30. Mär 2022 um 19:10 Uhr)
|