From: Lee Newsgroups: comp.os.msdos.djgpp Subject: HELP : Scaling Date: Mon, 22 Feb 1999 21:49:58 +0800 Organization: Singapore Telecommunications Ltd Lines: 146 Message-ID: <36D16086.F3CB5E2@mbox4.removethis.singnet.com.sg> NNTP-Posting-Host: qtns02348.singnet.com.sg Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.04 [en] (Win95; I) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com hi, i have a question regarding scaling in allegro. how do i make an "object" shrink or stretch while keeping it at its original position? for example, in the demo program below, the plane will shrink and grow, but because the coordinates are multiplied by 1.1 / 0.9, it also moves. how can i keep it from moving? /* Fragments of C++ code within. Compile with "gxx" */ #include #include #include #include #include #define MAXPOINTS 50 #define XSTEP 10 #define YSTEP 10 #define SHRINK 0.9 #define STRETCH 1.1 #define TRANSLATEMODE 0 #define SCALEMODE 1 typedef struct object { int NumOfVerts; float Coord[MAXPOINTS][2]; } Object; void LoadObj(Object *); void TransformObj(int, float, float, Object *); void DrawObj(Object *); void main() { int Done = 0, Action; Object MyObject; allegro_init(); install_keyboard(); LoadObj(&MyObject); if (!set_gfx_mode(GFX_AUTODETECT, 640, 400, 0, 0)) { while (!Done) { DrawObj(&MyObject); Action = readkey() >> 8; if (Action != KEY_ESC) { switch(Action) { case KEY_LEFT: //TransformObj(TRANSLATEMODE, -XSTEP, 0, &MyObject); TransformObj(SCALEMODE, SHRINK, 1, &MyObject); break; case KEY_RIGHT: //TransformObj(TRANSLATEMODE, XSTEP, 0, &MyObject); TransformObj(SCALEMODE, STRETCH, 1, &MyObject); break; case KEY_UP: //TransformObj(TRANSLATEMODE, 0, -YSTEP, &MyObject); TransformObj(SCALEMODE, 1, SHRINK, &MyObject); break; case KEY_DOWN: //TransformObj(TRANSLATEMODE, 0, YSTEP, &MyObject); TransformObj(SCALEMODE, 1, STRETCH, &MyObject); break; default: break; } clear(screen); } else { Done = 1; } } } else { printf("Graphics init failed! Press any key to quit ..."); readkey(); } } void LoadObj(Object *MyObject) { ifstream infile("d3.dat"); int counter; infile >> MyObject->NumOfVerts; for (counter = 0; counter < (MyObject->NumOfVerts * 2); counter++) { infile >> MyObject->Coord[counter][0]; infile >> MyObject->Coord[counter][1]; } infile.close(); } void TransformObj(int mode, float x, float y, Object *MyObject) { int counter; float dummy; // use to hold useless z coordinate output, since 2d (x, y) involve only MATRIX_f TransMatrix; // Transformation Matrix switch(mode) { case 0: get_translation_matrix_f(&TransMatrix, x, y, 0); break; case 1: get_scaling_matrix_f(&TransMatrix, x, y, 1); break; } for (counter = 0; counter < MyObject->NumOfVerts; counter++) { apply_matrix_f(&TransMatrix, MyObject->Coord[counter][0], MyObject->Coord[counter][1], 0, &MyObject->Coord[counter][0], &MyObject->Coord[counter][1], &dummy); } } void DrawObj(Object *MyObject) { int counter, temp[50]; for (counter = 0; counter < MyObject->NumOfVerts; counter++) { temp[counter * 2] = (float) MyObject->Coord[counter][0]; temp[counter * 2 + 1] = (float) MyObject->Coord[counter][1]; } polygon(screen, MyObject->NumOfVerts, temp, 2); } -- regards, lee. =========================================================== figure out what to remove in email address. i tire of spam. =========================================================== Suppose you were an idiot. And suppose you were a member of Congress. But I repeat myself. -- Mark Twain ===========================================================