Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Rotating a 2D line

Rotating a 2D line

Scheduled Pinned Locked Moved C / C++ / MFC
learning
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FarPointer
    wrote on last edited by
    #1

    Hi, How can we rotate a 2d line in 3d to get a cone or can anyone point me to any useful resource on this (Open GL). Thanx in Advance , Regards, FarPointer

    I A E Steve EcholsS 4 Replies Last reply
    0
    • F FarPointer

      Hi, How can we rotate a 2d line in 3d to get a cone or can anyone point me to any useful resource on this (Open GL). Thanx in Advance , Regards, FarPointer

      I Offline
      I Offline
      includeh10
      wrote on last edited by
      #2

      OpenGL is very special, I think u should post ur Q on a OpenGL forum. good luck.


      A nice tool for optimizing your Microsoft html-help contents. Includeh10

      F 1 Reply Last reply
      0
      • I includeh10

        OpenGL is very special, I think u should post ur Q on a OpenGL forum. good luck.


        A nice tool for optimizing your Microsoft html-help contents. Includeh10

        F Offline
        F Offline
        FarPointer
        wrote on last edited by
        #3

        Hi, I couldnt Find OpenGL Forum in CodeProject you got a better idea were i can . Regards, FarPointer

        1 Reply Last reply
        0
        • F FarPointer

          Hi, How can we rotate a 2d line in 3d to get a cone or can anyone point me to any useful resource on this (Open GL). Thanx in Advance , Regards, FarPointer

          A Offline
          A Offline
          Andy Moore
          wrote on last edited by
          #4

          This really isn't OpenGL specific but is just trigonometry. Decide on how many points you want to use in your rotation. For each point on the line you want to rotate it 360 degress around the z-axis. Decide what your delta theta is. For each point you will loop from 0 to the number of points and create a vertex as follows: glBegin( GL_QUADS ); for each point on line for each delta theta x1 = x * cos(theta); y1 = y * sin(theta); z1 = z1; glVertex3f( x1, y1, z1 ); glEnd(); I hope this helps you get started. Deus caritas est

          1 Reply Last reply
          0
          • F FarPointer

            Hi, How can we rotate a 2d line in 3d to get a cone or can anyone point me to any useful resource on this (Open GL). Thanx in Advance , Regards, FarPointer

            E Offline
            E Offline
            El Corazon
            wrote on last edited by
            #5

            FarPointer wrote:

            How can we rotate a 2d line in 3d to get a cone or can anyone point me to any useful resource on this (Open GL).

            actually, you are making it too difficult. OpenGL relative to order of operations. So assuming you want to rotate a line 30 degrees you go from this:

            glBegin(GL_LINES);
            glVertex3f(0.0f, 0.0f, 0.0f);
            glVertex3f(50.0f, 50.0f, 50.0f);
            glEnd();

            to this:

            glPushMatrix();
            glRotatef(30.0,0.0f,1.0f,0.0f);
            // rotate 30 degrees on Y-Axis
            // then draw line
            glBegin(GL_LINES);
            glVertex3f(0.0f, 0.0f, 0.0f);
            glVertex3f(50.0f, 50.0f, 50.0f);
            glEnd();
            glPopMatrix();

            although the glPushMatrix() and glPopMatrix() are not required operations if you draw another primitive it is relative to the last rotate, push and pop operations restores the rotation matrix to prior to the rotate so that another primitive is relative to the original scene-view not the last rotation. see this tutorial over at Nehe: Nehe OpenGL tutorial on Rotations[^] _________________________ Asu no koto o ieba, tenjo de nezumi ga warau. Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)

            1 Reply Last reply
            0
            • F FarPointer

              Hi, How can we rotate a 2d line in 3d to get a cone or can anyone point me to any useful resource on this (Open GL). Thanx in Advance , Regards, FarPointer

              Steve EcholsS Offline
              Steve EcholsS Offline
              Steve Echols
              wrote on last edited by
              #6

              Might be a little late for this reply, but... If you want to display a cone in wire or solid form, include glaux.h, and call either auxWireCone(radius, height) or auxSolidCone(radius, height). If you want to construct a cone on your own, you'll need the mathematical formula for a cone and some code to draw the triangles that form the cone (GL_TRIANGLE_STRIP), and the base of the cone (if desired, also GL_TRIANGLE_STRIP or GL_TRIANGLE_FAN). In either case, you can call glRotate before drawing the cone, to get the desired orientation of the cone. delete this; * poof! *

              • S
                50 cups of coffee and you know it's on!
                Code, follow, or get out of the way.
              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups