Hello Guest

Create custom operators for classes

  • 2 Replies
  • 6360 Views
Create custom operators for classes
« 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;

*

Offline KaiHH

  • ****
  • 334
Re: Create custom operators for classes
« Reply #1 on: November 11, 2020, 19:23:04 »
Java does not have operator overloading, so at least with Java this is not possible.

Re: Create custom operators for classes
« Reply #2 on: November 11, 2020, 19:55:20 »
Thanks