الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

تحريك شكل ما في مسار بيضاوي [تم تعديل العنو

مغلق
بدأه Flower-5 في 2 يناير 2007 · 2 رد · 767 مشاهدة · في قسم برمجة الألعاب و الرسوميات العام
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته

ماعليه ممكن تساعدوني في تعديل هذا الكود ليدور الشكل في مسار بيضاوي

#include <GL/glut.h>
#include <math.h>
#include <stdlib.h>

const double TWO_PI = 6.2831853;

GLsizei winWidth = 500, winHeight = 500;	// Initial display window size.
GLuint regHex;							//  Define name for display list.
static GLfloat rotTheta = 0.0;

class scrPt {
public:
	GLint x, y;
};

static void init (void)
{
   scrPt hexVertex;
   GLdouble hexTheta;
   GLint k;

   glClearColor (1.0, 1.0, 1.0, 0.0);

   /*  Set up a display list for a red regular hexagon.
	*  Vertices for the hexagon are six equally spaced
	*  points around the circumference of a circle.
	*/
   regHex = glGenLists (1);
   glNewList (regHex, GL_COMPILE);
	  glColor3f (1.0, 0.0, 0.0);
	  glBegin (GL_POLYGON);
		 for (k = 0; k < 6; k++) {
			hexTheta = TWO_PI * k / 6;
			hexVertex.x = 150 + 100 * cos (hexTheta);
			hexVertex.y = 150 + 100 * sin (hexTheta);
			glVertex2i (hexVertex.x, hexVertex.y);
		 }
	  glEnd ( );
   glEndList ( );
}

void displayHex (void)
{
   glClear (GL_COLOR_BUFFER_BIT);

   glPushMatrix ( );
   glRotatef (rotTheta, 0.0, 0.0, 1.0);
   glCallList (regHex);
   glPopMatrix ( );

   glutSwapBuffers ( );

   glFlush ( );
}

void rotateHex (void)
{
   rotTheta += 3.0;
   if (rotTheta > 360.0)
	  rotTheta -= 360.0;

   glutPostRedisplay ( );
}
void winReshapeFcn (int newWidth, int newHeight)
{
   glViewport (0, 0, (GLsizei) newWidth, (GLsizei) newHeight);

   glMatrixMode (GL_PROJECTION);
   glLoadIdentity ( );
   gluOrtho2D (-320.0, 320.0, -320.0, 320.0);

   glMatrixMode (GL_MODELVIEW);
   glLoadIdentity ( );

   glClear (GL_COLOR_BUFFER_BIT);
}
void mouseFcn (int button, int action, int x, int y)
{
   switch (button) {
	  case GLUT_LEFT_BUTTON:		   //  Start the rotation.
		 if (action == GLUT_DOWN)
			glutIdleFunc (rotateHex);
		 break;
	  case GLUT_RIGHT_BUTTON:			//  Stop the rotation.
		 if (action == GLUT_DOWN)
			glutIdleFunc (NULL);
		 break;
	  default:
		 break;
   }
}

void main (int argc, char** argv)
{
   glutInit (&argc, argv);
   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
   glutInitWindowPosition (150, 150);
   glutInitWindowSize (winWidth, winHeight);
   glutCreateWindow ("Animation Example");

   init ( );
   glutDisplayFunc (displayHex); 
   glutReshapeFunc (winReshapeFcn);
   glutMouseFunc (mouseFcn);

   glutMainLoop ( );
}

يعطيكم ألف عافيه ...

دمتم بخير ...

تم تعديل هذه المشاركة بواسطة احمد صالح في 3 يناير 2007 في 03:05

#2

شكل بيضاوي هل دائرة ام ellipse ؟

For Every Frame 
// Circle
x = r  * Cos(theta) 
y = r * sin ( theta) 

theta = 0.001 * Elapased Time 

calculate the elapsed time using timeGetTime(); 

Ellipse movement 

x^2 / a2  + y^2 / b2 = 1 // cartesian

 x = a sin theta, y = b cos theta, theta = [0, 2pi]
// polar

تم تعديل هذه المشاركة بواسطة احمد صالح في 3 يناير 2007 في 03:22

BEng , Electronics and communications.

Embedded systems engineer.

Graphics Programmer

عالم الكومبيوتر هو من لديه المعرفة في علوم الكومبيوتر ، الرياضيات ، هندسة الالكترونيات -احمد صالح

#3

ماعليه المطلوب غير كذا

مومهم عندي الشكل أهم شي الحركه بدل ماتكون في مسار دائري أبغاها في مسار بيضاوي

يعطيك العافيه على المساعده

دمتم بخير

هذا الموضوع مغلق.

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…