logo
down
shadow

OpenTK - How to rotate a 2D object


OpenTK - How to rotate a 2D object

By : user2955002
Date : November 22 2020, 10:33 AM
will be helpful for those in need In the fixed function pipeline, Rotate operations are not appended. Instead the second one is replacing the first one (as long as there is no PushMatrix operation inbetween). So what you are currently drawing is the first object rotated around 180 degree and the second object around -180 degree.
Back to your question: If you replace the second call to Rotate with LoadIdentity, the current modelmatrix is resetted to an identity matrix, removing all transformations.
code :
drawObject();
GL.Rotate(180, Vector3d.UnitZ);
drawObject();
GL.LoadIdentity();
drawObject();


Share : facebook icon twitter icon
Save cube in variable and apply scale/rotate/move OpenTK

Save cube in variable and apply scale/rotate/move OpenTK


By : Jon J.
Date : March 29 2020, 07:55 AM
I wish this helpful for you Use the GL.Translate(x,y,z), GL.Rotate(θ,x,y,z) and GL.Scale(sx,sy,sz) functions to move the coordinate system origin, orientation and scaling.
So drawing a cube after the command
code :
GL.Translate(10,10,100);
can i use opentk and xna in the same project and showing the data on the same window? Does OpenTk Support Xna?

can i use opentk and xna in the same project and showing the data on the same window? Does OpenTk Support Xna?


By : VictorMoral
Date : March 29 2020, 07:55 AM
wish helps you XNA is using Direct3d, whereas OpenTK is OpenGL. In the general case, you cannot draw using OpenGL into a Direct3d window.[1]
What you can do is switch from XNA to MonoGame. It is an open-source implementation of XNA and supports both Direct3d and OpenGL. If you use the OpenGL version, you will be able to draw into the same window using both XNA and OpenTK.
Draw and rotate the text along z axis in opengl/opentk

Draw and rotate the text along z axis in opengl/opentk


By : Pankaj Singh
Date : March 29 2020, 07:55 AM
Hope this helps I need to draw string/text in opengl/opentk and then rotate it along z axis from the center of text itself. ,
I am able to write text with this but unable to rotate
code :
OpenTK.Graphics.OpenGL.GL.MatrixMode(OpenTK.Graphics.OpenGL.MatrixMode.ModelView);
OpenTK.Graphics.OpenGL.GL.PushMatrix();
OpenTK.Graphics.OpenGL.GL.Rotated( angle_degree, 0.0, 0.0, 1.0);

OpenTK.Graphics.OpenGL.GL.Begin(OpenTK.Graphics.OpenGL.PrimitiveType.TriangleFan);
OpenTK.Graphics.OpenGL.GL.TexCoord2(0, 0);
OpenTK.Graphics.OpenGL.GL.Vertex2(x, y);
OpenTK.Graphics.OpenGL.GL.TexCoord2(1, 0);
OpenTK.Graphics.OpenGL.GL.Vertex2(x + charDict[charid].bitmap.Width * scale, y);
OpenTK.Graphics.OpenGL.GL.TexCoord2(1, 1);
OpenTK.Graphics.OpenGL.GL.Vertex2(x + charDict[charid].bitmap.Width * scale, y + charDict[charid].bitmap.Height * scale);
OpenTK.Graphics.OpenGL.GL.TexCoord2(0, 1);
OpenTK.Graphics.OpenGL.GL.Vertex2(x + 0, y + charDict[charid].bitmap.Height * scale);
OpenTK.Graphics.OpenGL.GL.End();

OpenTK.Graphics.OpenGL.GL.PopMatrix();
OpenTK.Graphics.OpenGL.GL.PushMatrix();
OpenTK.Graphics.OpenGL.GL.Translate( rotate_center_x, rotate_center_y, 0.0);
OpenTK.Graphics.OpenGL.GL.Rotated( angle_degree, 0.0, 0.0, 1.0);
OpenTK.Graphics.OpenGL.GL.Translate( -rotate_center_x, -rotate_center_y, 0.0);

.....

OpenTK.Graphics.OpenGL.GL.PopMatrix();
Get orientation of object in OpenTK C#

Get orientation of object in OpenTK C#


By : fdonatti
Date : March 29 2020, 07:55 AM
it fixes the issue I recommend to change the order of the angles, when you apply them tho the current matrix:
code :
GL.Rotate(rotateCAz, new Vector3d(1, 0, 0));
GL.Rotate(rotateCAy, new Vector3d(0, 1, 0));
GL.Rotate(rotateCAx, new Vector3d(0, 0, 1));
GL.Rotate(zRot, new Vector3d(1, 0, 0));
GL.Rotate(yRot, new Vector3d(0, 1, 0));
GL.Rotate(xRot, new Vector3d(0, 0, 1));
Matrix4 currentModelView;
GL.GetFloat(GetPName.ModelviewMatrix, out currentModelView);
Matrix4 currentModelView = 
    Matrix4.CreateRotationX(xRot * (float)Math.PI / 180.0f) *
    Matrix4.CreateRotationY(yRot * (float)Math.PI / 180.0f) *
    Matrix4.CreateRotationZ(zRot * (float)Math.PI / 180.0f) * 
    Matrix4.CreateRotationX(rotateCAx * (float)Math.PI / 180.0f) *
    Matrix4.CreateRotationY(rotateCAy * (float)Math.PI / 180.0f) *
    Matrix4.CreateRotationZ(rotateCAz * (float)Math.PI / 180.0f);
Quaternion q = currentModelView.ExtractRotation();
const double epsi = 0.0001;
double y = 2.0 * (q.Y * q.Z + q.W * q.X);
double x = q.W * q.W - q.X * q.X - q.Y * q.Y + q.Z * q.Z;

double pitch = (Math.Abs(q.X) < epsi && Math.Abs(q.Y) < epsi) ? 2.0 * Math.Atan2(q.X, q.W) : Math.Atan2(y, x);
double yaw = Math.Asin(Math.Min(Math.Max(-2.0 * (q.X * q.Z - q.W * q.Y), -1.0), 1.0));
double roll = Math.Atan2(2.0 * (q.X * q.Y + q.W * q.Z), q.W * q.W + q.X * q.X - q.Y * q.Y - q.Z * q.Z);
float rot_x = pitch * 180.0f / (float)Math.PI; 
float rot_y = yaw   * 180.0f / (float)Math.PI; 
float rot_z = roll  * 180.0f / (float)Math.PI;
does glRotate in OpenGL rotate the camera or rotate the world axis or rotate the model object?

does glRotate in OpenGL rotate the camera or rotate the world axis or rotate the model object?


By : Narayan Gowda v
Date : March 29 2020, 07:55 AM
I hope this helps . I want to know whether glRotate rotates the camera, the world axis, or the object. Explain how they are different with examples. ,
the camera
Related Posts Related Posts :
  • Why does C# also not allow empty conditions in while loops?
  • Unable to get a block of code into my regex match groups
  • What is difference between dbcontext.Add and dbcontext.AddObject
  • How do I update the file version number of C# DLL without recompiling?
  • Value for html control always null
  • HttpClient hangs when timeout is setting (Windows Phone)
  • Handle Multiple Form tag in asp.net page?
  • create word document with html content in c#
  • Confusion about Find And Replace
  • Format sms messages in Clickatell
  • Automated Function Overload
  • String to date in MS Access SQL statement gives type mismatch error
  • ShowDialog exiting on certain events
  • Is there a try Convert.ToInt32... avoiding exceptions
  • How to move wpf application into minimize tray at Window Start-up C#?
  • How to change display format of long variable?
  • How to use Addfields in MongoDB C# Aggregation Pipeline
  • MsTest TestCleanup method not called when an unhandled exception is thrown
  • missing last data when exporting gridview to excel
  • How to add array of objects to List in c#
  • Lambda Expression to order (sort) my list collection
  • Library for displaying music notation
  • How to compare two dictionaries in c# and get the output as True and False after validation
  • specify fields to be serialized with JSON
  • How do you obtain the content of a specific node using XmlDocument in C#?
  • How to ignore the first line in a csv file when you read the csv file in C#
  • c# - Problem calling public void from class
  • How to tell a class which objects it should create? Type vs. object confusion :(
  • Save CheckBox state to xml
  • WIX CAQuietExec NETSH Command Fails
  • Issues sending http put request every 60 seconds to RoR app
  • ConfigurationManager.ConnectionStrings.ConnectionString Issue
  • Real size WPF controls for printing
  • How to cancel properly?
  • C# String multiplication error
  • Using Solrnet and Assigning Attributes with Entity Framework Generated POCOs
  • Regex pattern for single backslash
  • TextBox: insert spaces for credit card number?
  • C# DLL loaded for exe-application is not found when launching similar DLL by rundll32.exe
  • Debug a Windows Service with WCF library
  • Open a file from an external assembly?
  • Servicestack RegistrationFeature Unable to bind request
  • Index was outside the bounds of the array confusion
  • Error in Xml to List code. The ':' character, hexadecimal value 0x3A, cannot be included in a name
  • I am trying to do a while loop with a string conditional statement in C#
  • C# 'Cannot access a disposed object. Object name: 'SslStream'.'
  • How to make Gecko use seperate CookieContainer per instance?
  • C# Advanced form "please wait"
  • Send and Receive data C# using network stream
  • How to discover that appsettings changed in C#?
  • Check what needs full trust
  • What is the execution order of an MVC Razor view/layout
  • Table designer (Entity Framework) is too resource intense
  • How to clean up an exception string so it can be displayed via Javascript Alert?
  • Configuring Amazon SES Feedback Notifications via Amazon SNS in ASP.NET MVC (C#)
  • C# api responce and request
  • Dynamodb putitem function not working properly
  • theme in windows phone(light or dark) using c#
  • Backup attached database file(.mdf) using c# and SQL Server
  • What is 'TextFile' and where it is uses in WPF project
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org