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 3236724
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:39:17+00:00 2026-05-17T17:39:17+00:00

I am planning to develop an gyroscope based project like rotating an opengl texture

  • 0

I am planning to develop an gyroscope based project like rotating an opengl texture using gyroscope data, is there any sample code released from apple about gyroscope or any tutorial about integrating gyroscope with openGL… I searched google i didn’t find anything except core motion guide and event handling guide.

Updated: Please let me know if any sample available..

  • 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-17T17:39:18+00:00Added an answer on May 17, 2026 at 5:39 pm

    To get gyro updates you need to create a motion manager object and optionally (but recommended) a reference attitude object

    So in your interface definition you add:

    CMMotionManager *motionManager;
    CMAttitude *referenceAttitude;
    

    According to the docs you should only create one of these managers per application. I recommend making the motionManager accesible through a singleton but thats some extra work which you might not need to do if you only instantiate your class once.

    Then in your init method you should allocate the motion manager object like so;

    motionManager = [[CMMotionManager alloc] init];
    referenceAttitude = nil; 
    

    When you want to enable the motion updates you could create an enableMotion method or just call it from the init method. The following will store the initial device attitude and cause the device to continue sampling the gyro and updating its attitude property.

    -(void) enableMotion{
            CMDeviceMotion *deviceMotion = motionManager.deviceMotion;      
            CMAttitude *attitude = deviceMotion.attitude;
            referenceAttitude = [attitude retain];
            [motionManager startDeviceMotionUpdates];
    }
    

    For virtual reality applications using the gyro and OpenGL is pretty simple.
    You need to get the current gyro attitude (rotation) and then store it in an OpenGL compatible matrix. The code below retrieves and saves the current device motion.

    GLfloat rotMatrix[16];
    
    -(void) getDeviceGLRotationMatrix 
    {
            CMDeviceMotion *deviceMotion = motionManager.deviceMotion;      
            CMAttitude *attitude = deviceMotion.attitude;
    
            if (referenceAttitude != nil) [attitude multiplyByInverseOfAttitude:referenceAttitude];
            CMRotationMatrix rot=attitude.rotationMatrix;
            rotMatrix[0]=rot.m11; rotMatrix[1]=rot.m21; rotMatrix[2]=rot.m31;  rotMatrix[3]=0;
            rotMatrix[4]=rot.m12; rotMatrix[5]=rot.m22; rotMatrix[6]=rot.m32;  rotMatrix[7]=0;
            rotMatrix[8]=rot.m13; rotMatrix[9]=rot.m23; rotMatrix[10]=rot.m33; rotMatrix[11]=0;
            rotMatrix[12]=0;      rotMatrix[13]=0;      rotMatrix[14]=0;       rotMatrix[15]=1;
    }
    

    Depending on what you want to do with that you may have to invert it which is very easy.
    The inverse of a rotation is just its transpose which means swapping the columns and rows.
    So the above becomes:

    rotMatrix[0]=rot.m11; rotMatrix[4]=rot.m21; rotMatrix[8]=rot.m31;  rotMatrix[12]=0;
    rotMatrix[1]=rot.m12; rotMatrix[5]=rot.m22; rotMatrix[9]=rot.m32;  rotMatrix[13]=0;
    rotMatrix[2]=rot.m13; rotMatrix[6]=rot.m23; rotMatrix[10]=rot.m33; rotMatrix[14]=0;
    rotMatrix[3]=0;       rotMatrix[7]=0;       rotMatrix[11]=0;       rotMatrix[15]=1;
    

    If you want the yaw, pitch and roll angles then you can access them easily using

    attitude.yaw
    attitude.pitch
    attitude.roll
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are planning to develop a web based application using Silverlight 2.0. The application
We are planning to develop a client server application using C# and MySQL. We
I am planning to develop a windows application in .net which will act like
I'm planning to use Python to develop a web application. Anybody has any idea
I'm trying to develop a web based digital asset management application. I'm planning to
I'm planning to develop an ASP.NET server control to provide asynchronous username availability validation
I'm planning to develop a web-services (SOAP to C++ client) in Java with Metro/Hibernate
I'm planning to write a program in Ruby to analyse some data which has
I'm planning to develop an Add-in for Visual Studio 2008 that will allow me
I'm planning to develop a web application that targets the iPhone. I will use

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.