Create custom operators for classes

Started by Mihai_Ionut_Floares, November 11, 2020, 18:38:40

Previous topic - Next topic

Mihai_Ionut_Floares

I want to use the "*" to multiply a 4x4 matrix class created by me with a vector4 class.
Now the method to multiply is like that:
public vec4 MatMultiplyVec(vec4 vector){
   /multiply code 
}

and to use it:
vec4 vector = new vec4(10f, 0f, 0f, 1f);
mat4 mat4x4 = new mat();
vec4 result = new vec4(0f, 0f, 0f, 0f); //empty vector
result = mat4x4.MatMultiplyVec(vector); //the multiply method is in the mat4 class


It woud be niceto use something like:
result = mat4x4 * vector;

KaiHH

Java does not have operator overloading, so at least with Java this is not possible.