inline int32_t hsb2rgb(double h, double s, double b) { double cr = 0, cg = 0, cb = 0; int32_t i = doubleToInt(h / 60) % 6; double f = (h / 60) - i; double p = b * (1 - s); double q = b * (1 - f * s); double t = b * (1 - (1 - f) * s); switch (i) { case 0: cr = b; cg = t; cb = p; break; case 1: cr = q; cg = b; cb = p; break; case 2: cr = p; cg = b; cb = t; break; case 3: cr = p; cg = q; cb = b; break; case 4: cr = t; cg = p; cb = b; break; case 5: cr = b; cg = p; cb = q; break; default: break; } return gdTrueColor(doubleToInt (cr * 255.0), doubleToInt (cg * 255.0), doubleToInt (cb * 255.0)); }
int funkce(double vzorek,double pocet_vzorku ,double start, double stop) { double jeden_vzorek = (stop-start)/pocet_vzorku; double x = vzorek*jeden_vzorek; // tady nadefinuj nejakou tu funkci return doubleToInt(FUNKCE(x)); }
result_t gd_base::hsba(double hue, double saturation, double brightness, double alpha, int32_t& retVal) { if (hue < 0 || hue > 360 || saturation < 0 || saturation > 1 || brightness < 0 || brightness > 1 || alpha < 0 || alpha > 1) return CHECK_ERROR(CALL_E_INVALIDARG); retVal = (doubleToInt(alpha * 127) << 24) | hsb2rgb(hue, saturation, brightness); return 0; }
result_t Image::colorResolveAlpha(int32_t red, int32_t green, int32_t blue, double alpha, int32_t &retVal) { if (!m_image) return CHECK_ERROR(CALL_E_INVALID_CALL); if (red < 0 || red > 255 || green < 0 || green > 255 || blue < 0 || blue > 255 || alpha < 0 || alpha > 1) return CHECK_ERROR(CALL_E_INVALIDARG); retVal = gdImageColorResolveAlpha(m_image, red, green, blue, doubleToInt(alpha * 127)); return 0; }
// SOMETHING DOES NOT WORK IF IT MOVES LEFT AND UP // This one makes me move coherently the antagonists, enemyfleet[index]. void Engine::moveEnemyOnMap(double directangle, double speed, Spaceship* enemy) { // for moving double tmpX = (*enemy).getX(); double tmpY = (*enemy).getY(); if (cos(directangle) > 0) { tmpX += SPRITE_WIDTH; } if (sin(directangle) < 0) { tmpY += SPRITE_HEIGHT; } tmpX += cos(directangle) * speed; tmpY -= sin(directangle) * speed; if (tmpX < 780 && tmpY < 580 && tmpX > 20 && tmpY > 20) // Not moving through walls! { // No control is needed here, I Tink (tinker tailor soldier sailor) double plusX = cos(directangle); double plusY = -(sin(directangle)); plusX *= speed; plusY *= speed; int addendX = doubleToInt(plusX); int addendY = doubleToInt(plusY); (*enemy).teleport((*enemy).getX() + addendX, (*enemy).getY() + addendY); } }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if(nrhs!=1){ printf("Invalid number of inputs.\n"); return; } if(nlhs!=1){ printf("Invalid number of outputs.\n"); return; } Matrixf _gsize(const_cast<mxArray*>(prhs[0])); int *gsize = doubleToInt(_gsize.ptr, _gsize.length); // calculate the size int n = 1; for(int k=0; k<_gsize.length; k++){ n *= gsize[k]; } // fill grid int gmsize[] = {n, _gsize.length}; Matrixf grid(2, gmsize); int d = 1; for(int k=0; k<_gsize.length; k++){ for(int i=0; i<n; i++){ grid.at(i, k) = (i/d) % gsize[k] + 1; } d *= gsize[k]; } plhs[0] = grid.arr; delete [] gsize; }
int main() { IOWR_RAM_DATA(NIOSINTERFACE_1_0_BASE, 0, 0); int dir = 0; int posX = doubleToInt(21.5), posY = doubleToInt(11.5); //x and y start position // int posX = 22, posY = 11; //x and y start position int x =0; int p, q; IOSKYWR_RAM_DATA(SKYGEN_0_BASE, 262143, 0x0000); for(p = 0; p < 480; p++){ for(q = 0; q < 512; q++) { IOSKYWR_RAM_DATA(SKYGEN_0_BASE, p*512+q, (sky[p*1024+q*2+1]<<8) + (sky[p*1024+q*2])); } } IOSKYWR_RAM_DATA(SKYGEN_0_BASE, 262143, 0x000F); double sine_temp; double cosine_temp; for(x = 0; x < lookupLength ; x++) { //calculate ray position and direction sine_temp = sin(x*RAD + HALF_RAD); cosine_temp = cos(x*RAD + HALF_RAD); dirsine[x] = doubleToInt(sin(x*RAD)); dircosine[x] = doubleToInt(cos(x*RAD)); sine[x] = doubleToInt(sine_temp); cosine[x] = doubleToInt(cosine_temp); } int angle; int fish_angle; int move; int rayDirX; int rayDirY; int count_step; int k; int k2; int forward = 0; int backward = 0; int left = 0; int right = 0; //char key[] = { 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d', // 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d'}; unsigned char code = 0; //char key[] = {'d'}; k2 = 0; //start the main loop //for (k2 = 0; k2 < sizeof(key); k2++) int hardwareData = 0; while(1) { code = 0; //while (!IORD_8DIRECT(DE2_PS2_0_BASE, 0)) ; /* Poll the status */ // code = IORD_8DIRECT(DE2_PS2_0_BASE, 0); // if (code) //printf("%c, %x, %d\n", code, code, code); /* Get received byte */ //code = 'k'; //hardwareData = IORD_RAM_DATA(NIOSINTERFACE_1_0_BASE, 1); //printf("%d\n", hardwareData >> 4); code = IORD_8DIRECT(DE2_PS2_1_BASE, 1); switch(code) { case 'u': forward = 1; backward = 0; break; case 'r': forward = 0; backward = 1; break; case 't': right = 1; left = 0; break; case 'k': left = 1; right = 0; break; case 'U': forward = 0; break; case 'R': backward = 0; break; case 'T': right = 0; break; case 'K': left = 0; break; case ')': forward = 0; backward = 0; right = 0; left = 0; break; } x = 0; for(k = -halfScreenWidth; k < halfScreenWidth; k++) { angle = dir + k; if ( angle < 0) angle += lookupLength; if (angle >= lookupLength) angle -= lookupLength; fish_angle = k; if ( fish_angle < 0) fish_angle += lookupLength; if (fish_angle >= lookupLength) fish_angle -= lookupLength; //calculate ray position and direction //double cameraX = 2*x/double(w)-1; //x-coordinate in camera space rayDirX = cosine[angle]>>extensionFactor; rayDirY = sine[angle]>>extensionFactor; count_step = cosine[fish_angle]>>extensionFactor; //using a happy medium between 1/32 and 1/64 ray extension increment // rayDirX = (cosine[angle]>>6)+(cosine[angle]>>7); // rayDirY = (sine[angle]>>6) +(sine[angle]>>7); // count_step = (cosine[fish_angle]>>6) +(cosine[fish_angle]>>7); // hardwareData = IORD_32DIRECT(NIOSINTERFACE_1_0_BASE, 1); // printf("%d\n", hardwareData); DrawAccelerate(angle, posX, posY, count_step, rayDirX, rayDirY, x); IOWR_RAM_DATA(NIOSINTERFACE_1_0_BASE, 0, 0); hardwareData = IORD_32DIRECT(NIOSINTERFACE_1_0_BASE, 1); while (!(hardwareData & 1)){ hardwareData = IORD_32DIRECT(NIOSINTERFACE_1_0_BASE, 1); } //IOWR_RAM_DATA(NIOSINTERFACE_1_0_BASE, 0, 0); IOWR_RAM_DATA(NIOSINTERFACE_1_0_BASE, 0, 0xFFFFFFFF); // printf("out of loop\n"); //IOWR_RAM_DATA(NIOSINTERFACE_0_BASE, 0, 0); // int rayPosX = posX; // int rayPosY = posY; // int count = 0; // int mapX; // int mapY; // // //what direction to step in x or y-direction (either +1 or -1) // int stepX; // int stepY; // // int hit = 0; //was there a wall hit? // unsigned int side = 0; //was a NS or a EW wall hit? // // //calculate step and initial sideDist // if (rayDirX < 0) // stepX = -1; // else // stepX = 1; // // if (rayDirY < 0) // stepY = -1; // else // stepY = 1; // // // while ( worldMap[rayPosX>>posShift][rayPosY>>posShift] == 0) // { // count += count_step; // // //jump to next map square, OR in x-direction, OR in y-direction // rayPosX += rayDirX; // rayPosY += rayDirY; // // //Check if ray has hit a wall // } // // hit = 1; // //////////////////////////////////////////////////////////////////////// // /////LOOOP BACK CODE FOR SMOOTHER EDGES AND FASTER SPEEDS/////////////// // // count_step = count_step>>4; // rayDirX = rayDirX>>4; // rayDirY = rayDirY>>4; // // while(hit == 1) // { // // count -= count_step; // // //jump to next map square, OR in x-direction, OR in y-direction // rayPosX -= rayDirX; // rayPosY -= rayDirY; // // //Check if ray has hit a wall // if (worldMap[rayPosX>>posShift][rayPosY>>posShift] == 0) hit = 0; // // } // // count += count_step; // rayPosX += rayDirX; // rayPosY += rayDirY; // // //////////////////////////////////////////////////////////////////////// // //////////////////////////////////////////////////////////////////////// // // mapX = ((rayPosX>>posShift) + ((1 - stepX)>>1))<<posShift; // mapY = ((rayPosY>>posShift) + ((1 - stepY)>>1))<<posShift; // // //Calculate distance of perpendicular ray (oblique distance will give fisheye effect!) // if ( absVal(mapX - rayPosX) < absVal(mapY - rayPosY) ) // side = 1; // // // //Calculate height of line to draw on screen // //int lineHeight = abs( (screenHeight<<posShift) /count); // int lineHeight = (screenHeight<<posShift) /count; // //printf("lineHeight= %d", lineHeight); //// if (lineHeight >= screenHeight){ //// lineHeight = 0x1FF; //// //printf(" lineHeight= %d", lineHeight); //// } // //printf("\n"); // // //calculate lowest and highest pixel to fill in current stripe // int drawStart = (-lineHeight >> 1) + (screenHeight >> 1); // if(drawStart < 0) drawStart = 0; // int drawEnd = (lineHeight >> 1) + (screenHeight >> 1); // if(drawEnd >= screenHeight) drawEnd = screenHeight - 1; // // ///////////////////////////////////////////////// // ////texturing calculations // ///////////////////////////////////////////////// // unsigned int texNum = worldMap[rayPosX>>posShift][rayPosY>>posShift] - 1; //1 subtracted from it so that texture 0 can be used! // // //calculate value of wallX // int wallX; //where exactly the wall was hit // // if (side == 0) wallX = rayPosX; // else wallX = rayPosY; // // // wallX -= (wallX>>posShift)<<posShift; // // //x coordinate on the texture // unsigned int texX = (wallX * texWidth)>>posShift; // if(side == 1 && rayDirX > 0) texX = texWidth - texX - 1; // if(side == 0 && rayDirY < 0) texX = texWidth - texX - 1; // // unsigned int invLineHeight = (texHeight << 16)/lineHeight; // int line_minus_h = lineHeight - screenHeight; // // // // DrawTexture(x, texX, drawStart, drawEnd, side, texNum, invLineHeight , line_minus_h); // unsigned int color; // switch(worldMap[rayPosX>>posShift][rayPosY>>posShift]) // { // case 1: color = RED_8BIT; break; //red // case 2: color = GREEN_8BIT; break; //green // case 3: color = BLUE_8BIT; break; //blue // case 4: color = WHITE_8BIT; break; //white // default: color = YELLOW_8BIT; break; //yellow // } //draw the pixels of the stripe as a vertical line //DrawColumn(x, color, drawStart, drawEnd, side); //DrawColumn(x, color, lineHeight, side); //verLine(x, drawStart, drawEnd, color); x++; } //move forward if no wall in front of you if (forward == 1) { move = dircosine[dir]>>4; if(worldMap[(posX + move)>>posShift][posY>>posShift] == 0) posX += move; move = dirsine[dir]>>4; if(worldMap[posX>>posShift][(posY+move)>>posShift] == 0) posY += move; } //move backwards if no wall behind you if (backward == 1) { move = dircosine[dir]>>4; if(worldMap[(posX - move)>>posShift][posY>>posShift] == 0) posX -= move; move = dirsine[dir]>>4; if(worldMap[posX>>posShift][(posY - move)>>posShift] == 0) posY -= move; }