The program runs, but the mouse is not drawn according to the points and lines i gave it. Sadly i am completely stuck. Realx/y are all related to the maze and works perfectly. Realx/ym1 is related to the mouse. The first sub routine is converting the coordinates to be displayed on a 18 by 18 canvas.
If any of you could shed some light i would be very grateful.
#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <dos.h>
#include <stdio.h>
#include <iostream.h>
/*Define global variables*/
const int np = 274, nl = 137; /* np - number of points. */ /* nl - number of lines. */
const int npm1 = 6, nlm1 = 6;
const int transanp = 10, transbnp = 10;
float realx[np] = {2, 13, 0, 2, 3, 7, 8, 12, 13, 17, 0, 1, 3, 5, 9, 11, 13, 14, 16, 17, 2, 4, 5, 7, 10, 12, 14, 15, 16, 18, 5, 7, 8, 9, 11, 12, 13, 15, 17, 18, 2, 4, 5, 7, 9, 10, 11, 16, 1, 2, 4, 8, 9, 13, 14, 16, 1, 2, 11, 12, 14, 16, 1, 3, 4, 5, 14, 17, 1, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 1, 2, 3, 5, 6, 7, 8, 15, 4, 5, 6, 10, 13, 15, 2, 3, 5, 7, 8, 12, 14, 16, 4, 7, 8, 11, 16, 17, 4, 10, 12, 14, 15, 16, 4, 5, 7, 9, 11, 14, 4, 5, 7, 13, 14, 15, 1, 3, 4, 5, 6, 9, 2, 4, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 17, 17};
float realy[np] = {18, 18, 17, 17, 17, 17, 17, 17, 17, 17, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 0, 0, 17, 12, 11, 10, 9, 8, 1, 0, 18, 16, 15, 13, 12, 11, 8, 6, 17, 16, 13, 11, 10, 9, 6, 1, 15, 13, 12, 11, 10, 8, 7, 5, 3, 2, 1, 0, 16, 15, 14, 7, 3, 2, 1, 0, 11, 10, 9, 7, 1, 0, 17, 15, 14, 13, 11, 9, 8, 7, 6, 5, 3, 2, 17, 15, 14, 12, 11, 9, 8, 7, 6, 5, 16, 14, 13, 12, 9, 8, 1, 0, 16, 13, 12, 9, 4, 0, 14, 13, 11, 9, 8, 6, 5, 3, 16, 15, 14, 13, 11, 9, 6, 4, 18, 17, 16, 15, 12, 9, 7, 5, 2, 0, 15, 14, 12, 11, 10, 9, 6, 4, 2, 0, 17, 14, 8, 7, 4, 2, 16, 11, 9, 5, 4, 0, 17, 15, 14, 10, 5, 0};
int linebegin[nl] = {0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200, 202, 204, 206, 208, 210, 212, 214, 216, 218, 220, 222, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 254, 256, 258, 260, 262, 264, 266, 268, 270, 272};
int lineend[nl] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, 223, 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255, 257, 259, 261, 263, 265, 267, 269, 271, 273};
float realxm1[npm1] = {0.3, 0.1, 0.1, 0.3, 1, 0.3}; /*Initial points for mouse*/
float realym1[npm1] = {16.1, 16.2, 16.3, 16.4, 16.3, 16.2};
int linebeginm1[nlm1] = {0, 1, 2, 3, 4, 5}; /*Lines for mouse*/
int lineendm1[nlm1] = {1, 2, 3, 4, 5, 2};
float a[transanp] = {1, 0, 1, 1, 1, 0, 1, 1, 1, 1}; /*Array for translation*/
float b[transbnp] = {0, 1, 0, 0, 0, 1, 0, 0, 0, 0};
void draw(int pcolour, int lcolour, int lstyle, int lwidth)
{
int i, screenx[np], screeny[np];
float screenxm1[npm1], screenym1[npm1];
setcolor(pcolour);
setlinestyle(lstyle,EMPTY_FILL,lwidth);
for (i=0; i<np; i++)
{
screenx[i] = (realx[i])/18*639; /*Conversion of real coords to screen coords (18 by 18)*/
screeny[i] = 479-(realy[i])/18*479;
}
for (i=0; i<npm1; i++)
{
screenxm1[i] = (realxm1[i])/18*639; /*Conversion of mouse coords*/
screenym1[i] = 479-(realym1[i])/18*479;
}
setcolor(lcolour);
for (i=0; i<nl; i++)
{
line(screenx[linebegin[i]],screeny[linebegin[i]],screenx[lineend[i]],screeny[lineend[i]]);
}
for (i=0; i<nlm1; i++)
{
line(screenxm1[linebegin[i]],screenym1[linebegin[i]],screenxm1[lineend[i]],screenym1[lineend[i]]);
}
}
void trans(float xt, float yt) /* Translation routine. */
{
int i;
for (i=0; i<npm1; i++) /* Transform (translate) the object. */
{
realxm1[i] = realxm1[i] + xt;
realym1[i] = realym1[i] + yt;
}
}
int main(void)
{
int graphdriver=DETECT, graphmode;
initgraph(&graphdriver, &graphmode, "");
draw(WHITE, RED, SOLID_LINE, NORM_WIDTH);
int i;
float a[transanp], b[transbnp];
for (i=0; i>10; i++)
{
delay(100);
cleardevice();
trans(a[i],b[i]);
draw(WHITE, RED, SOLID_LINE, NORM_WIDTH);
}
getch();
closegraph();
return 0;
}
Edited by WingedPanther, 23 January 2010 - 08:58 AM.
Adding more comments


Sign In
Create Account

Back to top









