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

An Array in VC++

مغلق
بدأه نحلة نشيطة في 17 ديسمبر 2003 · 7 رد · 1,044 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

AA

Well, maybe it will be a silly question but I have to know what is the way to define an array which can hold x , y , state where x,y are floats or integer or whatever , and STATE is bolean initaly set to 0.. ? .

Anybody can show me the code of the above ..?

Thank you in advance

كما أريد أن أكون .. بأمر الله أكون

#2

we can't define array with two types

لا يمكن تعريف جزء من المصفوفة من نوع معين و الجزء الاخر من نوع اخر لابد ان يكون جميع عناصر المصفوفة من نفس النوع

#3

السلام عليكم ,,

اقتباس
Well, maybe it will be a silly question

بالعكس السؤال مهم فعلا ,,

كما ذكر أخي م.غسان لايمكن انشاء مصفوفة فطرية تحمل أكثر من نوع بصورة مباشرة ,, لكننا في لغة المعجزات سي++ حيث كل شيء ممكن :) اليك الحل :

هنا تأتي ميزة ال Struct وز ال class ,, لانحتاج لأكثر من struct في مثالنا الحالي واليكي تصريحه :

بداية

اقتباس
where x,y are floats or integer or whatever

في هذه الحال لو جعلتي المتغيرات double أو float ستفي بالنتيجة ,, لأن ال flaot يكون int لكن العكس ,, لا ,,

اقتباس
and STATE is bolean initaly set to 0.. ? .

بالطبع ضعي المتغير STATE من النوع bool والتمهيد للقيمة صفر ستكون مهمة ال Constructor كالتلي :

struct Array
{
	float x,y;
	bool STATE;

	Array() : STATE(false)
	{}
};

الان من ال main كل ماعليك هو :

void main()
{

	Array a[100];

	a[3].x =10;
	a[3].y=8;
	a[3].STATE = true;

}

وتستعملينها كما المصفوفات الفطرية ,, بالتوفيق ,,

banner_60_468.gif

NOTHING IS IMPOSSIBLE

#4

AA ..

Thank you Ghassan .. HGB got my point ..

Yeah .. that's what I mean Brother HGB.. lets me explain what I've did so far to use this "structure" ..

The idea is to generate two rows of balls,, When a bouncing ball (hits) each of these balls ( the hitted ball will disapear) as an illustrated image shown :

array.gif

the matter here is not opengl code because I already did that ( I mean the drawing of the two rows and coding the bouncing ball ..) the matter here is programming .. a pure programming .. since I don't know deeply about vc++ .. I faced difficulties in programming the above ,, but let me show you where am I so far and I apprciated if you could help ..

Here is the declaration :

struct My_balls
{
	float x,y;
	int state; // state =0 the ball not drawn, state =1 the ball is drawn
};

My_balls balls_init[26] = { {0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},
     	 {0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},
     	 {0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},
     	 {0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},
     	 {0,0,1},{0,0,1},{0,0,1} }; 

My_balls balls_store[26];

In my main routine:

   int gh;
   for (gh=0; gh<26;gh++)
   { balls_store[gh]= balls_init[gh];} // reset balls to inital state

Drawing ball routine ( which I think something must cahnge here !! ) :

void drawcirclesrows (void)
{
 int row;
  glEnable(GL_LIGHTING);

  for (row=0; row<13; row++)
	{
       glPushMatrix(); //save matrix 
       glTranslatef(-55.0f+10*row,66.0f,0.0f);   
       glColor3f(1.0f, 1.0f, 0.0f);            
       glutSolidSphere( 4.5,20,20);                    
       glPopMatrix(); //restore matrix}
	}

  for (row=0; row<13; row++)
	{
       glPushMatrix(); //save matrix 
       glTranslatef(-55.0f+10*row,55.0f,0.0f);   
       glColor3f(1.0f, 1.0f, 0.0f);            
       glutSolidSphere( 4.5,20,20);                    
       glPopMatrix(); //restore matrix}
	}


}

And , lastly .. my display routine :

int gh;
for (gh=0; gh<26; gh++)
{
      float ddx = Ball1x - balls_store[gh].x;
      float ddy = Ball1y - balls_store[gh].y;

      if ( sqrt(dx*dx +dy*dy) <= 9.5f) { balls_store[gh].state=0 ; vx=-vx; angle=-angle;vy=-vy;}

// Draw only the ball with state is one 
if (balls_store[gh].state) Draw_ball(balls_store[gh].x,balls_store[gh].y); 
	}

what is underlined is suppose to be the same of my drawing rotine but because I'm not sure whether my drawing rotine is right or wrong so I cahnge the name here. It does not work yet .. I'm just thinking how the drawing routine must be and I'm sharing you my thoghts :) ..

Any ideas .. ?

كما أريد أن أكون .. بأمر الله أكون

#5

السلام عليكم,

أريد أن أقول للأخت نحلة أن في مثل هده الأمثلة تظهر قوة OOP .

فيمكنك صنع Class للكرة بدل struct وتضعين فيها كل مميزات الكرة وحتى الدوال التي ستضهر أو تخفي الكرة.وهكدا سيكون عندنا كائن مستقل يمكن أن يقوم بكل ما يريد بوحده وسترين أن البرمجة سترجع أسهل وأسهل.وإدا زدنا ميزة اللون للكلاس فيمكن أن نأخد أيضا الكرة السوداء.

وإدا كنت تستعملين MFC فهي توجد فيها ما يعادل Linked Lists والمعروفة ب Objects arrays وهي متعددة الأنواع حسب ما نريد وهي تسهل كثيرا عملية زيادة أو حدف كائن ما من جملة مجموعة .

على العموم هده بداية متوفقة إن شاء الله وأتمنى لك السير إلى الأمام.

إلى اللقاء.

#6

WAA brother chik,

Yeah , you are 100% right .. but my problem that I'm brand new to both opengl and VC++ .. Eventhough I'm in course now but it is theortical one .. all my implemntation is self-learning which make me slow .. but ALLAH KAREEM :)

Hope me luck

كما أريد أن أكون .. بأمر الله أكون

#7

I fixed the problem ..

Thank you all :)

كما أريد أن أكون .. بأمر الله أكون

#8

اريد تعليم لغه ++C

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

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