0

I have the following code in C++:

struct vec3d
{
    float x, y, z;
};

struct triangle
{
    vec3d p[3];
};

struct mesh
{
    vector<triangle> tris;

    bool LoadFromObjectFile(string sFilename) {
        return true;
    }
};

How could I translate this into Java? Would I use classes for that? So in order to group multiple vec3d in a triangle :

public class vec3d  
{
    float x, y, z;
}

public class triangle  
{   
    vec3d[] p = new vec3d[3];
}
1
  • 1
    Unrelated: I recommend that you not waste too much time trying to use Java the same way you'd use C++. It leads to much pain. In this case there's an easy way out: public members, but things often get fugly. Commented Dec 31, 2019 at 1:40

1 Answer 1

-1

To write a structure in Java, similar would be a class. So yes, you somewhat answered your question.

I believe that this is a better detailed explanation: Creating struct like data structure in Java

Sign up to request clarification or add additional context in comments.

1 Comment

Don't link to a duplicate in your answer if the question is fully answered by the duplicate. Vote to close as a duplicate instead

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.