Rotation Point Troubles in Java
up vote
2
down vote
favorite
Bit of back story on my project (because your probably going to say, "Just use OpenGL.")
a.k.a. The Reason I Hate OpenGL
So, my computer is around 7 years old, with OpenGL 3.30 on my hardware (Using an ATI Radeon HD 4300/4500), and I really wanted to make my own 3D game engine using OpenGL. Long story very short, shaders are broken for me (detail at bottom). So, I said screw it I'm going to make my own 3D renderer. I got the rendering done, but I need help on rotations.
The More Boring Story of why this happened
Well, the truth is I started making my own engine because my laptop was too old to follow the tutorial, so I started work on a 2D engine with a cool parallax system, then it hit me. The reason why I said the story about my computer being to old is because that is really when I started thinking about rotation on a whole different level.
The Code
This is where the problems started:
x = (float) ((x * Math.cos(Math.toRadians(main.cameraRot)) - z * Math.sin(Math.toRadians(main.cameraRot))));
z = (float) (z * Math.sin(Math.toRadians(main.cameraRot)) - x * Math.cos(Math.toRadians(main.cameraRot)));
I think I see the problem, I think I need to add zsin(cameraRot) to xcos(cameraRot)
I've even drawn out how Sine and Cosine functions work, mainly because I was also working on a water effect at the time, and I thought, "I should be able to use sin (and only sin) to rotate." I was wrong (obviously). I have also used a graphing calculator (TI-83+ from 1999, not 2011) to graph those functions (they were a bit different, and yes I used the graphing mode where you could input both X and Y values). I'm trying out some stuff right now, and I think I see the main problem. The Z rotation uses the X rotation, but the X rotation uses the Z coordinate (If that was complicated, I'll break it down: We need to use the original X value to calculate the rotation for the Z value, but we instead use the X value after it's changed to a rotated X, which would make a huge difference).
It doesn't work at all. cameraRot (rotation) is constantly increasing, but there is no effect.
Here's the code for rendering:
g.drawRect((int) (x / (z - main.camZ) - 256 / (z - main.camZ) / 2),(int) (0 - 256 / (z - main.camZ) / 2),(int) (256 / (z - main.camZ)),(int) (256 / (z - main.camZ)));
But it screws up rendering. Yes, I know that I'm drawing a square, but the previous one I made (on a laptop) was more complete, but used the same rendering algorithm and broke when I tried adding in rotations, every object appeared to be at 0,0,1.
Any suggestions on how to fix this?
Is it from the rendering or the equation? (I'm going to save you the trouble and tell you its the rotation equation.
Just a little side note, I accidentally made that rendering algorithm.
How the Shaders were Broken
I tried using uniforms with VertexShaders but they only work with Fragment Shaders. The tutorial I followed used "#version 330" (like me) but they had OpenGL version 4.3 (and they were using java) and I had version 3.30 (and used java).
java swing 3d rotation
add a comment |
up vote
2
down vote
favorite
Bit of back story on my project (because your probably going to say, "Just use OpenGL.")
a.k.a. The Reason I Hate OpenGL
So, my computer is around 7 years old, with OpenGL 3.30 on my hardware (Using an ATI Radeon HD 4300/4500), and I really wanted to make my own 3D game engine using OpenGL. Long story very short, shaders are broken for me (detail at bottom). So, I said screw it I'm going to make my own 3D renderer. I got the rendering done, but I need help on rotations.
The More Boring Story of why this happened
Well, the truth is I started making my own engine because my laptop was too old to follow the tutorial, so I started work on a 2D engine with a cool parallax system, then it hit me. The reason why I said the story about my computer being to old is because that is really when I started thinking about rotation on a whole different level.
The Code
This is where the problems started:
x = (float) ((x * Math.cos(Math.toRadians(main.cameraRot)) - z * Math.sin(Math.toRadians(main.cameraRot))));
z = (float) (z * Math.sin(Math.toRadians(main.cameraRot)) - x * Math.cos(Math.toRadians(main.cameraRot)));
I think I see the problem, I think I need to add zsin(cameraRot) to xcos(cameraRot)
I've even drawn out how Sine and Cosine functions work, mainly because I was also working on a water effect at the time, and I thought, "I should be able to use sin (and only sin) to rotate." I was wrong (obviously). I have also used a graphing calculator (TI-83+ from 1999, not 2011) to graph those functions (they were a bit different, and yes I used the graphing mode where you could input both X and Y values). I'm trying out some stuff right now, and I think I see the main problem. The Z rotation uses the X rotation, but the X rotation uses the Z coordinate (If that was complicated, I'll break it down: We need to use the original X value to calculate the rotation for the Z value, but we instead use the X value after it's changed to a rotated X, which would make a huge difference).
It doesn't work at all. cameraRot (rotation) is constantly increasing, but there is no effect.
Here's the code for rendering:
g.drawRect((int) (x / (z - main.camZ) - 256 / (z - main.camZ) / 2),(int) (0 - 256 / (z - main.camZ) / 2),(int) (256 / (z - main.camZ)),(int) (256 / (z - main.camZ)));
But it screws up rendering. Yes, I know that I'm drawing a square, but the previous one I made (on a laptop) was more complete, but used the same rendering algorithm and broke when I tried adding in rotations, every object appeared to be at 0,0,1.
Any suggestions on how to fix this?
Is it from the rendering or the equation? (I'm going to save you the trouble and tell you its the rotation equation.
Just a little side note, I accidentally made that rendering algorithm.
How the Shaders were Broken
I tried using uniforms with VertexShaders but they only work with Fragment Shaders. The tutorial I followed used "#version 330" (like me) but they had OpenGL version 4.3 (and they were using java) and I had version 3.30 (and used java).
java swing 3d rotation
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Bit of back story on my project (because your probably going to say, "Just use OpenGL.")
a.k.a. The Reason I Hate OpenGL
So, my computer is around 7 years old, with OpenGL 3.30 on my hardware (Using an ATI Radeon HD 4300/4500), and I really wanted to make my own 3D game engine using OpenGL. Long story very short, shaders are broken for me (detail at bottom). So, I said screw it I'm going to make my own 3D renderer. I got the rendering done, but I need help on rotations.
The More Boring Story of why this happened
Well, the truth is I started making my own engine because my laptop was too old to follow the tutorial, so I started work on a 2D engine with a cool parallax system, then it hit me. The reason why I said the story about my computer being to old is because that is really when I started thinking about rotation on a whole different level.
The Code
This is where the problems started:
x = (float) ((x * Math.cos(Math.toRadians(main.cameraRot)) - z * Math.sin(Math.toRadians(main.cameraRot))));
z = (float) (z * Math.sin(Math.toRadians(main.cameraRot)) - x * Math.cos(Math.toRadians(main.cameraRot)));
I think I see the problem, I think I need to add zsin(cameraRot) to xcos(cameraRot)
I've even drawn out how Sine and Cosine functions work, mainly because I was also working on a water effect at the time, and I thought, "I should be able to use sin (and only sin) to rotate." I was wrong (obviously). I have also used a graphing calculator (TI-83+ from 1999, not 2011) to graph those functions (they were a bit different, and yes I used the graphing mode where you could input both X and Y values). I'm trying out some stuff right now, and I think I see the main problem. The Z rotation uses the X rotation, but the X rotation uses the Z coordinate (If that was complicated, I'll break it down: We need to use the original X value to calculate the rotation for the Z value, but we instead use the X value after it's changed to a rotated X, which would make a huge difference).
It doesn't work at all. cameraRot (rotation) is constantly increasing, but there is no effect.
Here's the code for rendering:
g.drawRect((int) (x / (z - main.camZ) - 256 / (z - main.camZ) / 2),(int) (0 - 256 / (z - main.camZ) / 2),(int) (256 / (z - main.camZ)),(int) (256 / (z - main.camZ)));
But it screws up rendering. Yes, I know that I'm drawing a square, but the previous one I made (on a laptop) was more complete, but used the same rendering algorithm and broke when I tried adding in rotations, every object appeared to be at 0,0,1.
Any suggestions on how to fix this?
Is it from the rendering or the equation? (I'm going to save you the trouble and tell you its the rotation equation.
Just a little side note, I accidentally made that rendering algorithm.
How the Shaders were Broken
I tried using uniforms with VertexShaders but they only work with Fragment Shaders. The tutorial I followed used "#version 330" (like me) but they had OpenGL version 4.3 (and they were using java) and I had version 3.30 (and used java).
java swing 3d rotation
Bit of back story on my project (because your probably going to say, "Just use OpenGL.")
a.k.a. The Reason I Hate OpenGL
So, my computer is around 7 years old, with OpenGL 3.30 on my hardware (Using an ATI Radeon HD 4300/4500), and I really wanted to make my own 3D game engine using OpenGL. Long story very short, shaders are broken for me (detail at bottom). So, I said screw it I'm going to make my own 3D renderer. I got the rendering done, but I need help on rotations.
The More Boring Story of why this happened
Well, the truth is I started making my own engine because my laptop was too old to follow the tutorial, so I started work on a 2D engine with a cool parallax system, then it hit me. The reason why I said the story about my computer being to old is because that is really when I started thinking about rotation on a whole different level.
The Code
This is where the problems started:
x = (float) ((x * Math.cos(Math.toRadians(main.cameraRot)) - z * Math.sin(Math.toRadians(main.cameraRot))));
z = (float) (z * Math.sin(Math.toRadians(main.cameraRot)) - x * Math.cos(Math.toRadians(main.cameraRot)));
I think I see the problem, I think I need to add zsin(cameraRot) to xcos(cameraRot)
I've even drawn out how Sine and Cosine functions work, mainly because I was also working on a water effect at the time, and I thought, "I should be able to use sin (and only sin) to rotate." I was wrong (obviously). I have also used a graphing calculator (TI-83+ from 1999, not 2011) to graph those functions (they were a bit different, and yes I used the graphing mode where you could input both X and Y values). I'm trying out some stuff right now, and I think I see the main problem. The Z rotation uses the X rotation, but the X rotation uses the Z coordinate (If that was complicated, I'll break it down: We need to use the original X value to calculate the rotation for the Z value, but we instead use the X value after it's changed to a rotated X, which would make a huge difference).
It doesn't work at all. cameraRot (rotation) is constantly increasing, but there is no effect.
Here's the code for rendering:
g.drawRect((int) (x / (z - main.camZ) - 256 / (z - main.camZ) / 2),(int) (0 - 256 / (z - main.camZ) / 2),(int) (256 / (z - main.camZ)),(int) (256 / (z - main.camZ)));
But it screws up rendering. Yes, I know that I'm drawing a square, but the previous one I made (on a laptop) was more complete, but used the same rendering algorithm and broke when I tried adding in rotations, every object appeared to be at 0,0,1.
Any suggestions on how to fix this?
Is it from the rendering or the equation? (I'm going to save you the trouble and tell you its the rotation equation.
Just a little side note, I accidentally made that rendering algorithm.
How the Shaders were Broken
I tried using uniforms with VertexShaders but they only work with Fragment Shaders. The tutorial I followed used "#version 330" (like me) but they had OpenGL version 4.3 (and they were using java) and I had version 3.30 (and used java).
java swing 3d rotation
java swing 3d rotation
edited Nov 10 at 17:37
asked Jul 20 at 0:59
Noah the Epic Guy
114
114
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51433674%2frotation-point-troubles-in-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown