LWJGL Forum

Programming => General Java Game Development => Topic started by: Mihai_Ionut_Floares on November 11, 2020, 18:38:40

Title: Create custom operators for classes
Post by: Mihai_Ionut_Floares on November 11, 2020, 18:38:40
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:
Code: [Select]
public vec4 MatMultiplyVec(vec4 vector){
   /multiply code
}
and to use it:
Code: [Select]
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:
Code: [Select]
result = mat4x4 * vector;
Title: Re: Create custom operators for classes
Post by: KaiHH on November 11, 2020, 19:23:04
Java does not have operator overloading, so at least with Java this is not possible.
Title: Re: Create custom operators for classes
Post by: Mihai_Ionut_Floares on November 11, 2020, 19:55:20
Thanks