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

  • SEARCH
  • Home
  • 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 7756557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:51:16+00:00 2026-06-01T12:51:16+00:00

I wrote the following code to rotate a cube on x axis an entire

  • 0

I wrote the following code to rotate a cube on x axis an entire revolution, then the y axis, and back and forth. The code generates the desired result.

- (void)update
{
if (_x_axis) {
    if (i >= 6.28) {
        i = 0;
        _x_axis = false;
    } else {
        float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height);
        GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, 0.1f, 100.0f);
        self.effect.transform.projectionMatrix = projectionMatrix;
        GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -3.0f);
        modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, i, 0.0f, 1.0f, 0.0f);
        self.effect.transform.modelviewMatrix = modelViewMatrix;
        i += .01;
    }
} else {
    if (i >= 6.28) {
        i = 0;
        _x_axis = true;
    } else {
        float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height);
        GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, 0.1f, 100.0f);
        self.effect.transform.projectionMatrix = projectionMatrix;
        GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -3.0f);
        modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, i, 1.0f, 0.0f, 0.0f);
        self.effect.transform.modelviewMatrix = modelViewMatrix;
        i += .01;
    }
}

My question is, when I change the increment to i to something such as .02 or .2 or .3, why does the cube still rotate exactly one revolution?

If i is incremented by .2, the last value of i used in the transformation would be 6.2 before it would be reset and the rotation axis was changed. Basically, what is keeping the cube level? I would think with the larger increment of i, the cube wouldn’t make an entire revolution before switching axis.

  • 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-06-01T12:51:17+00:00Added an answer on June 1, 2026 at 12:51 pm

    6.28 = 2*M_PI, with the code given a full rotation. The parameter i is straight given to GLKMatrix4Rotate. If you want different lengths, you can vary this constants in the conditions, or map the parameter i before calling GLKMatrix4Rotate.

    For the the second approach, modify the code:

    1. Change the interval of i to [0;1], and make the step width a bit smaller.
    2. Call GLKMatrix4Rotate with i*2*M_PI.

    Now the animtion generally runs as previous, however, you can twist this with easing functions.

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

Sidebar

Related Questions

i wrote the following code for drawing a rotate rectangle var s:UIComponent = new
I wrote following code: void *produce(void* arg) { buffer* buff = (buffer *) arg;
I wrote the following code: void buildArrays(char *pLastLetter[],int length[], int size, const char str[])
i wrote following code to create a linkbutton programmatically, but its showing like lable
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':
if wrote the following code and do not understand why the trace returns false:
I wrote the following code: import java.lang.*; import DB.*; private Boolean validateInvoice(String i) {
I wrote the following code snippet in VS2010: #pragma once #include stdafx.h #ifndef SECURITY_WIN32
I wrote the following code to count the node of an XML file: private
In C++Builder, I wrote the following code (in Button1Click handler), When I run in

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.