Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6735513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:01:16+00:00 2026-05-26T11:01:16+00:00

I’ve got a problem with moving and rotating objects in OpenGL. I’m using C#

  • 0

I’ve got a problem with moving and rotating objects in OpenGL. I’m using C# and OpenTK (Mono), but I guess the problem is with me not understanding the OpenGL part, so you might be able to help me even if you don’t know anything about C# / OpenTK.

I’m reading the OpenGL SuperBible (latest edition) and I tried to rewrite the GLFrame in C#. Here is the part I’ve already rewritten:

public class GameObject
{
    protected Vector3 vLocation;
    public Vector3 vUp;
    protected Vector3 vForward;

    public GameObject(float x, float y, float z)
    {
        vLocation = new Vector3(x, y, z);
        vUp = Vector3.UnitY;
        vForward = Vector3.UnitZ;
    }

    public Matrix4 GetMatrix(bool rotationOnly = false)
    {
        Matrix4 matrix;

        Vector3 vXAxis;
        Vector3.Cross(ref vUp, ref vForward, out vXAxis);

        matrix = new Matrix4();
        matrix.Row0 = new Vector4(vXAxis.X, vUp.X, vForward.X, vLocation.X);
        matrix.Row1 = new Vector4(vXAxis.Y, vUp.Y, vForward.Y, vLocation.Y);
        matrix.Row2 = new Vector4(vXAxis.Z, vUp.Z, vForward.Z, vLocation.Z);
        matrix.Row3 = new Vector4(0.0f, 0.0f, 0.0f, 1.0f);

        return matrix;
    }

    public void Move(float x, float y, float z)
    {
        vLocation = new Vector3(x, y, z);
    }

    public void RotateLocalZ(float angle)
    {
        Matrix4 rotMat;

        // Just Rotate around the up vector
        // Create a rotation matrix around my Up (Y) vector
        rotMat = Matrix4.CreateFromAxisAngle(vForward, angle);

        Vector3 newVect;

        // Rotate forward pointing vector (inlined 3x3 transform)
        newVect.X = rotMat.M11 * vUp.X + rotMat.M12 * vUp.Y + rotMat.M13 * vUp.Z;
        newVect.Y = rotMat.M21 * vUp.X + rotMat.M22 * vUp.Y + rotMat.M23 * vUp.Z;
        newVect.Z = rotMat.M31 * vUp.X + rotMat.M32 * vUp.Y + rotMat.M33 * vUp.Z;

        vUp = newVect;
    }
}

So I create a new GameObject (GLFrame) on some random coordinates: GameObject go = new GameObject(0, 0, 5); and rotate it a bit: go.RotateLocalZ(rotZ);. Then I get the matrix using Matrix4 matrix = go.GetMatrix(); and render frame (first, I set the viewing matrix and then I multiply it with modeling matrix)

protected override void OnRenderFrame(FrameEventArgs e)
{
    base.OnRenderFrame(e);
    this.Title = "FPS: " + (1 / e.Time).ToString("0.0");

    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
    GL.MatrixMode(MatrixMode.Modelview);
    GL.LoadIdentity();

    Matrix4 modelmatrix = go.GetMatrix();
    Matrix4 viewmatrix = Matrix4.LookAt(new Vector3(5, 5, -10), Vector3.Zero, Vector3.UnitY);

    GL.LoadMatrix(ref viewmatrix);

    GL.MultMatrix(ref modelmatrix);

    DrawCube(new float[] { 0.5f, 0.4f, 0.5f, 0.8f });

    SwapBuffers();
}

The DrawCube(float[] color) is my own method for drawing a cube.

Now the most important part: If I render the frame without the GL.MultMatrix(ref matrix); part, but using GL.Translate() and GL.Rotate(), it works (second screenshot). However, if I don’t use these two methods and I pass the modeling matrix directly to OpenGL using GL.MultMatrix(), it draws something strange (first screenshot).

How it looks like
How it should look like

Can you help me and explain me where is the problem? Why does it work using translate and rotate methods, but not with multiplying the view matrix by the modeling matrix?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:01:17+00:00Added an answer on May 26, 2026 at 11:01 am

    OpenGL transformation matrices are ordered column wise. You should use the transpose of the matrix you are using.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.