3 Replies - 292 Views - Last Post: 09 February 2012 - 12:00 PM

Topic Sponsor:

#1 Afr0  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 06-December 11

XNA equivalent of glVertex2f()?

Posted 08 February 2012 - 02:25 AM

I'm trying to port some OpenGL code to XNA. Can someone tell me what is the XNA-equivalent of glVertex2f()?
It would also be nice to know the equivalent of glColor3f() if possible.

void DrawBonesSkeleton(Bone_t& Bone){
	    glTranslatef(Bone.Translation.x, Bone.Translation.y, Bone.Translation.z);
	    float RotationMatrix[16];
	    FindQuaternionMatrix(RotationMatrix, &Bone.Rotation);
	    glMultMatrixf(RotationMatrix);
	   
	    if(!strcmp(Bone.Name, "ROOT"))
	        glColor3f(1.0, 0.0, 0.0);
	    else if(!strcmp(Bone.Name, "HEAD"))
	        glColor3f(1.0, 1.0, 0.0);
	    else
	        glColor3f(0.0, 1.0, 0.0);
	    glBegin(GL_POINTS); glVertex2f(0, 0); glEnd();
	   
	    for(unsigned i=0; i<Bone.ChildrenCount; i++){
	        glPushMatrix();
	        DrawBonesSkeleton(*Bone.Children[i]);
	        glPopMatrix();
	    }
	}


Is This A Good Question/Topic? 0
  • +

Replies To: XNA equivalent of glVertex2f()?

#2 Kilorn  Icon User is online

  • XNArchitect
  • member icon



Reputation: 988
  • View blog
  • Posts: 3,037
  • Joined: 03-May 10

Re: XNA equivalent of glVertex2f()?

Posted 08 February 2012 - 06:40 AM

I've never worked with OpenGL before, and haven't spent much time at all looking at any code for it, but it appears that the glVertex2f is just a Vector2, and the glColor3f is just a Vector3.
Was This Post Helpful? 0
  • +
  • -

#3 civicdude95  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 18-January 12

Re: XNA equivalent of glVertex2f()?

Posted 08 February 2012 - 02:29 PM

Yes, like Kilorn said, glVertex2f is Vector2 and actually, the glColor3f would be as follows:
glColor3f(1.0, 0.0, 0.0);

// Is == to

new Color(Vector3(1.0, 0.0, 0.0));



You could also do:
// Vector4, the last parameter is the alpha for this color
new Color(Vector4(1.0, 0.0, 0.0, 1.0));



Does that help?
Was This Post Helpful? 0
  • +
  • -

#4 Afr0  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 06-December 11

Re: XNA equivalent of glVertex2f()?

Posted 09 February 2012 - 12:00 PM

Thanks!
Here's how I ported it:

        private void FindQuaternionMatrix(ref Matrix Mat, Quaternion Quat)
        {
            float x2 = Quat.X * Quat.X;
            float y2 = Quat.Y * Quat.Y;
            float z2 = Quat.Z * Quat.Z;
            float xy = Quat.X * Quat.Y;
            float xz = Quat.X * Quat.Z;
            float yz = Quat.Y * Quat.Z;
            float wx = Quat.W * Quat.X;
            float wy = Quat.W * Quat.Y;
            float wz = Quat.W * Quat.Z;

            Mat.M11 = 1.0f - 2.0f * (y2 + z2);
            Mat.M12 = 2.0f * (xy - wz);
            Mat.M13 = 2.0f * (xz + wy);
            Mat.M14 = 0.0f;

            Mat.M21 = 2.0f * (xy + wz);
            Mat.M22 = 1.0f - 2.0f * (x2 + z2);
            Mat.M23 = 2.0f * (yz - wx);
            Mat.M24 = 0.0f;

            Mat.M31 = 2.0f * (xz - wy);
            Mat.M32 = 2.0f * (yz + wx);
            Mat.M33 = 1.0f - 2.0f * (x2 + y2);
            Mat.M34 = 0.0f;

            Mat.M41 = 0.0f;
            Mat.M42 = 0.0f;
            Mat.M43 = 0.0f;
            Mat.M44 = 1.0f;
        }

        public void DrawBones(GraphicsDevice Devc, BasicEffect Effect, Bone Bne)
        {
            Matrix Mat = new Matrix();

            //The translation controls where stuff is rendered in 3D space.
            Mat.Translation = Bne.GlobalTranslation;

            Matrix RotationMatrix = new Matrix();
            FindQuaternionMatrix(ref RotationMatrix, Bne.GlobalRotation);

            //glMultMatrixf()
            Mat = Mat * RotationMatrix;

            VertexPositionColor Vertex;

            if (Bne.BoneName.Equals("ROOT"))
            {
                Vertex = new VertexPositionColor(new Vector3(0.0f, 0.0f, 1.0f), new Color(1.0f, 0.0f,
                    0.0f));
            }
            else if (Bne.BoneName.Equals("HEAD"))
            {
                Vertex = new VertexPositionColor(new Vector3(0.0f, 0.0f, 1.0f), new Color(1.0f, 1.0f,
                    0.0f));
            }
            else
            {
                Vertex = new VertexPositionColor(new Vector3(0.0f, 0.0f, 1.0f), new Color(0.0f, 1.0f,
                    0.0f));
            }

            Effect.World = Mat;

            Devc.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.PointList, new VertexPositionColor[] { Vertex }, 0,
                1);

            for (int i = 0; i < Bne.Children.Count; i++)
                DrawBones(Devc, Effect, Bne.Children[i]);
        }


The problem is that all the bones are drawn in the same location! Why? Please help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1