Jump to content

[Help] OpenGL for 3D Object Transformation

Alif Robby A
Go to solution Solved by manon_gfx,

so far i able to create a Stand Still 3D Object, about the transformation Matrices i Already learn that the problem is to Implemented it into a code.Thanks btw

 

If that's the case, it should be simple. In 3D graphics you usually have 4different spaces: model space, world space, camera space and screen space.

Model space is the space the model is in when you load it.

World space is where the model is in world, how it's rotated and how it's scaled.

Camera space is basically same as world space, only relative to the camera.

Screen space is where coordinates resemble pixels on the screen.

To go from one space to another you need to transform the vertices by a matrix.

Model space --ToWorldMatrix--> World space --ViewMatrix--> Camera space --ProjectionMatrix--> Screen space.

luckily you can concatenate these matrices together into a single matrix, so you don't have to transform all the vertices 3 times.

This can be done by multiplying them together: Matrix = ProjectionMatrix * ViewMatrix * ToWorldMatrix NOTE: order is important.

In the vertex shader you simply do gl_Position = Matrix * vertex to convert it  to screen space.

The only trick left is to construct the ToWorldMatrix from a position, scale and rotation. This shouldn't be too difficult and can be easily found on the internet.

Need Help for coding a 3D Object that can be : Rotation, Translation, and Scalar Factor.

Java Language if Possible or anything if Java too difficult.

 

if there already a Topic Similar to this please give a Link

Thank You So Much :)

Link to comment
Share on other sites

Link to post
Share on other sites

Not sure why you'd use Java for OpenGL when OpenGL is naturally C++ compatible?

If you're really set on using Java, the first step would be to define an abstract class for your "transmutable object", because you might want different 3D objects to behave differently.

If all that needs to happen is that it needs to move around, you're probably best defining the object in terms of its vertices, center, and any other geometrical detail; from there, OpenGL can actually do a lot of the hard work for you. There are actually glRotate, glTranslate, and glScale methods in every OpenGL version that you can use. As long as you define the series of points/vertices/planes of your object, they can just apply iteratively.

I'd recommend looking at the OpenGL Reference manual, that'll tell you about all the functions available to you through a standard OpenGL C++ compilation (provided you include the right libraries): https://www.opengl.org/sdk/docs/man3/

Like I said, OpenGL is mainly C++ based (because it's the simplest binding to OpenGL from C/C++), but if you really want to stick to you Java, then you'll need to get the JOGL wrapper and learn how that works.

From there it's just natural object recognition and data modification; your shaders and renderers should handle the rest for you.

Link to comment
Share on other sites

Link to post
Share on other sites

You can do these things in java, however the best OpenGL tutorials I have seen are using C++. If you have never used C++ before, I would just stick to java, since you'll have to learn a lot before you can actually do something in C++ like this.

If you haven't learned what vectors and transformation matrices are yet, DO THAT FIRST. This is the most basic form of math in graphics programming.

It would be helpful if you could tell us how much you actually know so far about 3D graphics. You'll have to at least know about: vertices, vectors, matrices, vertex shaders and fragment shaders. If you haven't learned about these topics yet, you'll have to research and understand them.

Link to comment
Share on other sites

Link to post
Share on other sites

Not sure why you'd use Java for OpenGL when OpenGL is naturally C++ compatible?

If you're really set on using Java, the first step would be to define an abstract class for your "transmutable object", because you might want different 3D objects to behave differently.

If all that needs to happen is that it needs to move around, you're probably best defining the object in terms of its vertices, center, and any other geometrical detail; from there, OpenGL can actually do a lot of the hard work for you. There are actually glRotate, glTranslate, and glScale methods in every OpenGL version that you can use. As long as you define the series of points/vertices/planes of your object, they can just apply iteratively.

I'd recommend looking at the OpenGL Reference manual, that'll tell you about all the functions available to you through a standard OpenGL C++ compilation (provided you include the right libraries): https://www.opengl.org/sdk/docs/man3/

Like I said, OpenGL is mainly C++ based (because it's the simplest binding to OpenGL from C/C++), but if you really want to stick to you Java, then you'll need to get the JOGL wrapper and learn how that works.

From there it's just natural object recognition and data modification; your shaders and renderers should handle the rest for you.

Though it doesn't help a lot but your Link give me a little hint Thank you 

 

You can do these things in java, however the best OpenGL tutorials I have seen are using C++. If you have never used C++ before, I would just stick to java, since you'll have to learn a lot before you can actually do something in C++ like this.

If you haven't learned what vectors and transformation matrices are yet, DO THAT FIRST. This is the most basic form of math in graphics programming.

It would be helpful if you could tell us how much you actually know so far about 3D graphics. You'll have to at least know about: vertices, vectors, matrices, vertex shaders and fragment shaders. If you haven't learned about these topics yet, you'll have to research and understand them.

so far i able to create a Stand Still 3D Object, about the transformation Matrices i Already learn that the problem is to Implemented it into a code.Thanks btw

Link to comment
Share on other sites

Link to post
Share on other sites

so far i able to create a Stand Still 3D Object, about the transformation Matrices i Already learn that the problem is to Implemented it into a code.Thanks btw

 

If that's the case, it should be simple. In 3D graphics you usually have 4different spaces: model space, world space, camera space and screen space.

Model space is the space the model is in when you load it.

World space is where the model is in world, how it's rotated and how it's scaled.

Camera space is basically same as world space, only relative to the camera.

Screen space is where coordinates resemble pixels on the screen.

To go from one space to another you need to transform the vertices by a matrix.

Model space --ToWorldMatrix--> World space --ViewMatrix--> Camera space --ProjectionMatrix--> Screen space.

luckily you can concatenate these matrices together into a single matrix, so you don't have to transform all the vertices 3 times.

This can be done by multiplying them together: Matrix = ProjectionMatrix * ViewMatrix * ToWorldMatrix NOTE: order is important.

In the vertex shader you simply do gl_Position = Matrix * vertex to convert it  to screen space.

The only trick left is to construct the ToWorldMatrix from a position, scale and rotation. This shouldn't be too difficult and can be easily found on the internet.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×