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

مشكله ارسلها لكم من وراء البحار

مغلق
بدأه ahmed996 في 31 يناير 2002 · 3 رد · 472 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

يا اخوان ساعدوني وهذه هي مشكلتي

انا طالب ادرس في امريكا وعندي مادة كمبيوتر جرافكس ، المهم استاذ المادة اعطانا برنامج على الفيجوال سي ++6 وطلب منا اضافة بعض التعديلات، وهي كالتالي:

يقوم البرنامج اصلا بتوليد اجسام صغيره "جزيئات" من اعلى الشاشة الى اسفل ،

طلب الاستاذ ان نقوم باضافة رسم شكل "مثال مربع دائرة الخ..." اسفل الشاشة بحيث تسقط الاجسام الصغيرة عليه ومن ثم تنعكس بانحراف يمينا او يسارا ،،،،

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

مرفق مع هذا الملف الكود الخاص بالبرنامج ، واذا اردت تنفيذه يجب ان يكون لديك مكتبة ملفات Open Gl

وهي موجودة عندي وهي

glut.h /glut32.dll/glut.dll/glut32.lib/glut.lib

احمد ahmed996@yahoo.com

هذا هو كود البرنامج

#include

#include

#include

const ParticleTotal = 250;

int ActiveParticles=0;

int NewOnes=5;

int Front=0;

struct Particle

{ int age;

double x,y,z; //location

double dx,dy,dz; // movement vector

};

Particle PSys[ParticleTotal];

void InitParticle (int X, int Y, int Z, int Age, int MaxAngle, int Radius,

int Speed, int Tilt, Particle &P)

{ int AgeMin = Age/2;

P.age=Age/2+rand()%AgeMin; // age--->.5*age to age

double R = 1.0-((rand()%200)*.01);

P.x= R* Radius + X;

P.y = 1.0*Y;

double Alpha = R*MaxAngle *0.0175; // times pi/180 --->radians

double Beta = Tilt *0.0175;

double CosB = cos(Beta);

P.dy = (CosB*Speed*-1)/10;

P.dx = -(tan(Alpha)*P.dy);}

void ProcessParticle (double Grav, Particle &P) //.003 works

{ P.age--;

P.x = P.x + P.dx;

P.y = P.y + P.dy;

P.dy = P.dy + Grav;}

void Retire (int Loc)

{ for (int i= Loc; i< ActiveParticles;i++)

PSys = PSys[i+1];

--ActiveParticles;}

void DoParticles ()

{ int A;

int Spot = ActiveParticles;;

if (ActiveParticles+NewOnes

{ for (int j=0; j

{ InitParticle(150,60,0,100,45,5,5,0,PSys[spot]);

// x y z age angle rad speed tilt

++ActiveParticles;

++Spot;}}

if (ActiveParticles>0)

{ for (int i=0; i< ActiveParticles;i++)

{ A=PSys.age;

if (A<1)

Retire(i);

else

{ ProcessParticle(0.1,PSys); //gravity

}}}

/// just to slow things down ******************

for (int i=0; i<32000;i++)

{ for (int j=0; j<200;j++){ }}

///********************************************

glutPostRedisplay();}

void display()

{ glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

int Spot= Front;

for (int i=0;i

{ glBegin(GL_POINTS);

glColor3f(1.0,0.0,0.0);

glVertex2f(PSys.x,PSys.y);

glEnd();

if (Spot=ParticleTotal)

Spot= 0;

else

++Spot;

}

glutSwapBuffers();}

void init()

{ gluOrtho2D(0.0,300,300,0.0); //1-r-b-t

glPointSize(1);}

void main (int argc, char**argv)

{ glutInit(&argc,argv);

glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);

glutInitWindowSize(300,300);

glutInitWindowPosition(100,100);

glutCreateWindow("Particle System");

init();

glutIdleFunc(DoParticles);

glutDisplayFunc(display);

glutMainLoop();}

#2

[l]Hi Ahmed,

I downloaded OpenGL-T and ran the program.. My experience in OpenGL is not good at all.

I can help you but to let the particles reflect you need to have some equations that do that..

I need to know the equations first..

Also, what kind of shape you need to put..?

Take care..[/l]

Coding on the Cloud and for the Cloud!

My Blog

#3

First of all the program you have contains some errors

here is a correct version of your code

#include 
#include 
#include 
#include 

const ParticleTotal = 250; 

int ActiveParticles=0; 
int NewOnes = 5; 

int Front=0; 

struct Particle 
{ 
	int age; 
	double x,y,z; //location 
	double dx,dy,dz; // movement vector 
}; 

Particle PSys[ParticleTotal]; 

void InitParticle(int X, int Y, int Z, 
				  int Age, 
				  int MaxAngle, int Radius, 
				  int Speed, 
				  int Tilt, Particle &P) 
{ 
	int AgeMin = Age/2; 
	P.age = Age/2 + rand() % AgeMin; // age--->.5*age to age 

	double R = 1.0 - ((rand() % 200) * .01);	// R = [-0.99, 1.0]
	P.x = R * Radius + X; 
	P.y = 1.0 * Y; 

	const float pi_180 = 3.14 / 180;
	double Alpha = R * MaxAngle * pi_180; // times pi/180 --->radians 
	double Beta = Tilt * pi_180; 
	P.dy = -(cos(Beta) * Speed)/10; 
	P.dx = -(tan(Alpha)* P.dy);
} 


void ProcessParticle (double Grav, Particle &P) //.003 works 
{ 
	P.age--; 
	P.x = P.x + P.dx; 
	P.y = P.y + P.dy; 
	P.dy = P.dy + Grav;
} 

void Retire(int Loc) 
{ 
	for (int i = Loc; i < ActiveParticles; i++) 
		PSys = PSys[i+1]; 
	--ActiveParticles;
} 

void DoParticles () 
{ 
	int A; 
	int Spot = ActiveParticles;
	if (ActiveParticles + NewOnes < ParticleTotal) 
	{ 
		for (int j=0; j < NewOnes;++j) 
		{ 
			// x y z age angle rad speed tilt 
			InitParticle(150,60,0,100,45,5,5,0,PSys[Spot]); 
			++ActiveParticles; 
			++Spot;
		}
	} 

	if (ActiveParticles > 0) 
	{ 
		for (int i=0; i< ActiveParticles;i++) 
		{ 
			A=PSys.age; 
			if (A<1) 
				Retire(i); 
			else 
			{ 
				ProcessParticle(0.1,PSys); //gravity 
			}
		}
	} 

	glutPostRedisplay();

	// Suspends the process for 60 milliseconds
	Sleep(60); // just to slow things down
} 

void display() 
{ 
	glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 

	int Spot = Front; 
	for (int i=0 ; i	{ 
		glBegin(GL_POINTS); 
		glColor3f(1.0, 0.0, 0.0); 
		glVertex2f(PSys.x,PSys.y); 
		glEnd(); 

		if (Spot == ParticleTotal) 
			Spot= 0; 
		else 
			++Spot; 
	} 
 	glutSwapBuffers();
} 

void init() 
{ 
	gluOrtho2D(0.0,300,300,0.0); //1-r-b-t 
	glPointSize(1);
} 

void main (int argc, char**argv) 
{ 
	srand(time(NULL));

	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
	glutInitWindowSize(300,300);
	glutInitWindowPosition(100,100);
	glutCreateWindow("Particle System");
	init(); 
	glutIdleFunc(DoParticles); 
	glutDisplayFunc(display); 
	glutMainLoop();
}

Coding on the Cloud and for the Cloud!

My Blog

#4

Sallam

Thank you for your quick response, the program works correctly , if you can give me your e-mail to send the code so you can run it again.

I have a handout from 3 pages, and it contains the equations that you ask about and code.

Could you tell me how I can send it to you? If you have fax number or another way to send it you let me know.

This homework is due to 2, February 2002, The shape could be any shape (ex triangle, circle, square..)

I looking for your response !

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

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

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

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

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

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