Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Opengl Rotate from and to a certain point


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Hachaso77   Members   -  Reputation: 231

Like
0Likes
Like

Posted 19 March 2013 - 06:26 PM

Hi!

 

I'm playing around with rotations and would like to know how this could be solve in a good way.

 

I would like to rotate something from a starting angle to a and angle.

Let's say from 120 degrees to 360 degrees. So when I reach 360 it should stop rotating.

Probably simple but I can't get it right.

 

void update(float elapsedTime)
{
  //my rotation goes here

}

 

 



Sponsor:

#2 jellyfishchris   Members   -  Reputation: 300

Like
0Likes
Like

Posted 19 March 2013 - 07:31 PM

Wrote this at work, no idea if it compiles or if my logic is even close to correct (spent like 5minutes on it lol)

 

#ifndef ROTATE_H
#define ROTATE_H

class PerformRotate
{
public:
	PerformRotate(float start, float goal);
	bool Update(float dt);
	

	float GetCurrent(){return m_current;}
private:
	float m_start;
	float m_goal;
	float m_current;
};
#endif


#include "Rotate.h"

PerformRotate::PerformRotate(float start, float goal)
{
	m_start = start;
	m_goal = goal;
	m_current = start;
}
bool PerformRotate::Update(float dt)
{
	float difference = m_goal - start;
	float other = 360 - abs(difference);
	
	if(abs(other) > abs(difference))
	{
		m_current += difference * dt;
		
		if((m_current >= m_goal) && (difference * dt > 0))
			return true;
		else if((m_current <= m_goal) && (difference * dt < 0))
			return true;
	}
	else
	{
		m_current += other * dt;
		
		if((m_current >= m_goal) && (other * dt > 0))
			return true;
		else if((m_current <= m_goal) && (other * dt < 0))
			return true;
	}
	return false;
}



#3 hikarihe   Members   -  Reputation: 243

Like
0Likes
Like

Posted 19 March 2013 - 07:45 PM

can you explain more clearly? I could help you but I don't really understand what you need to do

 

what does your code look like now?

 

in most cases you can use glRotatef( [your rotation value], [x coordinate], [y coordinate], [z coordinate] ) before you draw 

 

> where xyz are the coordinates of the point to rotate around & rotation value is in degrees


Edited by hikarihe, 19 March 2013 - 07:46 PM.


#4 incertia   Crossbones+   -  Reputation: 779

Like
1Likes
Like

Posted 19 March 2013 - 09:19 PM

So this is going to be pretty general, but I'm sure you can find out a way to do it in code.

You want to rotate from an angle, say theta, to a different angle, say phi, in a direction d (1 for CCW, -1 for CW) in a given time, say t, along the axis of your choice about a point (x, y, z). Your angular velocity then has to be about that axis, which gives you the angle you must rotate per frame to reach your goal in your goal time. However, FPS can change so you must recalculate omega accordingly.

So you now know how fast you're rotating the object, but you're not quite sure how to get to rotate about a certain point. What you do know is that OpenGL provides support for rotating about the origin, so you can subtract (x, y, z) from your point P to center your rotation around the origin, rotate, and then add back (x, y, z). As such, we our transform becomes P = Rotate(P - (x, y, z), omega) + (x, y, z), and you're done.
what




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS