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).










share|improve this question




























    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).










    share|improve this question


























      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).










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 17:37

























      asked Jul 20 at 0:59









      Noah the Epic Guy

      114




      114





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python