void StyleData::computeColors() { currentMainColor = calculateColor(mainColorData); current3DOverrideColor = _3dOverrideColor.a != 0 ? _3dOverrideColor : getMainColor(); currentColors.clear(); for(const auto& cd : colorDatas) currentColors.push_back(calculateColor(cd)); ssvu::rotate(currentColors, begin(currentColors) + currentSwapTime / (maxSwapTime / 2.f)); }
void setColors ( QColor start, QColor end, float value ) { this->_baseColor.setRed ( calculateColor ( start.red(), end.red(), value ) ); this->_baseColor.setGreen ( calculateColor ( start.green(), end.green(), value ) ); this->_baseColor.setBlue ( calculateColor ( start.blue(), end.blue(), value ) ); QString baseString = QString ( "#" ) + QString::number ( this->_baseColor.red(), 16 ).rightJustified(2, '0') + QString::number ( this->_baseColor.green(), 16 ).rightJustified(2, '0') + QString::number ( this->_baseColor.blue(), 16 ).rightJustified(2, '0'); this->_contents.replace ( "#000", baseString.toUtf8() ); }
ViewingGrid::ViewingGrid() { calculateFullGrid(); calculateColor(); calculatePartialGridFaces(); calculatePartialGrid(0, 0); gridType = VG_HALF_WIRE_FRAME; }
void RayTracer::raytrace(SetPixelFunction* putPixel, Resolution resolution) { if (resolution == 0) { raytrace(putPixel); } else { //Width and height of the image int width = _camera._w2D; int height = _camera._h2D; //Iterate over all the pixels of the screen/image for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { Color c = Color(0, 0, 0); for (double dx = -0.45; dx <= 0.45; dx += 0.9 / resolution) { for (double dy = -0.45; dy <= 0.45; dy += 0.9 / resolution) { //Create the ray from the observer point, passing through the pixel Ray r = Ray(_camera._observer, _camera.getPixel(x + dx, y + dy) - _camera._observer); c += calculateColor(r, NB_OF_INTERATIONS); } } //Set the pixel accoring to the calculated Color/Light Color newC = c / ((resolution + 1) * (resolution + 1)); newC.clamp(); putPixel->setPixel(x, y, newC); } } } }
void RayTracer::raytrace(SetPixelFunction* putPixel) { //Width and height of the image int width = _camera._w2D; int height = _camera._h2D; //Iterate over all the pixels of the screen/image for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { //Create the ray from the observer point, passing through the pixel Ray r = Ray(_camera._observer, _camera.getPixel(x, y) - _camera._observer); //Set the pixel accoring to the calculated Color/Light Color c = calculateColor(r, NB_OF_INTERATIONS); c.clamp(); putPixel->setPixel(x, y, c); } } }
// start to paint void SecondGantt::startPaint() { fst = true; memset(repairList, 0, sizeof(repairList)); memset(paintNumber, -1, sizeof(paintNumber)); getEarliest(); for(int i = 1; i <= jobVertexCount; ++i) jobVertex[i].current_time = topoVertex[i].earliestTime; currentT = topoVertex[jobVertexCount + 1].earliestTime; repaint(); prePix = this->grab(); fst = false; xRange = FPS * (50 + currentT + 200); yRange = FPS * (40 * machineNumber + 10); calculateColor(); paintCount = 0; repaint(); }
//**************************************** void repaint() {// function called to repaint the window GLfloat* pixelColor; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the screen buffer if(fracCount<6){ glBegin(GL_POINTS); // start drawing in single pixel mode for(GLfloat y = maxY; y >= minY; y -= stepY){ for(GLfloat x = minX+juliaSpecial; x <= maxX+juliaSpecial; x += stepX){ pixelColor=calculateColor(x,y); glColor3fv(pixelColor+color); // set color glVertex3f(x-juliaSpecial, y, 0.0f); // put pixel on screen (buffer) - [ 1 ] //printf("%d\t%d\n",stepX,stepY); } } glEnd(); // end drawing } else { switch(fracCount) { case 6: //glPushMatrix(); tetrahedron(5); //glPopMatrix(); break; } } if(fracCount==0){ drawFrontPage(); } else { glPushMatrix(); char title[25]=""; strcpy(title,titleSet[fracCount-1]); glColor3f(0.2,0.2,0.2); output(-1.1,1.2,0,GLUT_BITMAP_TIMES_ROMAN_24,title); printf("%s\n",title); glPopMatrix(); } glutSwapBuffers(); // swap the buffers - [ 2 ] }
Color ParticleColorManager::getNewColor(Particle* particle) { Color newColor(calculateColor(redColorCalculation, particle), calculateColor(greenColorCalculation, particle), calculateColor(blueColorCalculation, particle), particle->color.getAlpha()); if (trasitionRunnedSeconds < trasitionLength) { Color previousColor(calculateColor(previousRedColorCalculation, particle), calculateColor(previousGreenColorCalculation, particle), calculateColor(previousBlueColorCalculation, particle), particle->color.getAlpha()); return Gradient::getColorBetween(previousColor, newColor, trasitionLength, trasitionRunnedSeconds); } else return newColor; }
SDL_Color Renderer::raycast(float x, float y, float z, float* ray) { float startX = x; float startY = y; float startZ = z; int size = world->getSize(); // handle x out of bounds if ((x < 0.0f) && (ray[0] > 0.0f)) { float diff = -x; x += diff; // will never be division by zero because of our condition y += (ray[1] * diff) / ray[0]; z += (ray[2] * diff) / ray[0]; } else if ((x > size) && (ray[0] < 0.0f)) { float diff = size - x; x += diff; y += (ray[1] * diff) / ray[0]; z += (ray[2] * diff) / ray[0]; } // handle y out of bounds if ((y < 0.0f) && (ray[1] > 0.0f)) { float diff = -y; y += diff; x += (ray[0] * diff) / ray[1]; z += (ray[2] * diff) / ray[1]; } else if ((y > size) && (ray[1] < 0.0f)) { float diff = size - y; y += diff; x += (ray[0] * diff) / ray[1]; z += (ray[2] * diff) / ray[1]; } // handle z out of bounds if ((z < 0.0f) && (ray[2] > 0.0f)) { float diff = -z; z += diff; x += (ray[0] * diff) / ray[2]; y += (ray[1] * diff) / ray[2]; } else if ((z > size) && (ray[2] < 0.0f)) { float diff = size - z; z += diff; x += (ray[0] * diff) / ray[2]; y += (ray[1] * diff) / ray[2]; } // return skybox if we're still out of bounds if ((x < -0.1f) || (x > size + 0.1f) || (y < -0.1f) || (y > size + 0.1f) || (z < -0.1f) || (z > size + 0.1f)) { return skybox; } float dx = ray[0] * renderDistance; float dy = ray[1] * renderDistance; float dz = ray[2] * renderDistance; float rayMagnitude = sqrt(dx * dx + dy * dy + dz * dz); float ax, ay, az; int sx, sy, sz, n; float sv = numeric_limits<float>::min(); sx = (int) sgn(dx); sy = (int) sgn(dy); sz = (int) sgn(dz); ax = abs(dx) / rayMagnitude; ay = abs(dy) / rayMagnitude; az = abs(dz) / rayMagnitude; ax = ((ax > sv) ? ax : sv); ay = ((ay > sv) ? ay : sv); az = ((az > sv) ? az : sv); float tDeltaX = 1 / ax; float tDeltaY = 1 / ay; float tDeltaZ = 1 / az; float tMaxX = (float) abs((sx == 1) ? (1 - (fmod(x, 1.0f))) : (fmod(x, 1.0f))) / ax; float tMaxY = (float) abs((sy == 1) ? (1 - (fmod(y, 1.0f))) : (fmod(y, 1.0f))) / ay; float tMaxZ = (float) abs((sz == 1) ? (1 - (fmod(z, 1.0f))) : (fmod(z, 1.0f))) / az; n = (int) (abs(dx) + abs(dy) + abs(dz)); int face = -1; while (n-- != 0) { if (tMaxX < tMaxY) { if (tMaxX < tMaxZ) { face = 0; x += sx; tMaxX += tDeltaX; } else { face = 2; z += sz; tMaxZ += tDeltaZ; } } else { if (tMaxY < tMaxZ) { face = 1; y += sy; tMaxY += tDeltaY; } else { face = 2; z += sz; tMaxZ += tDeltaZ; } } Uint8 block = world->getBlock((int) x, (int) y, (int) z); if (block != 0) { SDL_Color c = world->getColor(block); return calculateColor(c, face, startX, x, startY, y, startZ, z); } } return skybox; }
/*! @note very important: color cubes of the children must already exist, otherwise there will be a segmentation fault */ void ColorCubeGenerator::processColorCube(FrameContext& context, Node * node, deque<Node*>& children) { const Geometry::Box box = node->getWorldBB(); ColorCube cc; // 1. case: current node's color cube should be processed by drawing Geometry < see processColorCubes(...) > if (children.empty()) { context.getRenderingContext().pushAndSetLighting(Rendering::LightingParameters(true)); context.getRenderingContext().applyChanges(); // render the six sides context.getRenderingContext().pushAndSetFBO(fbo.get()); for (uint8_t _side = 0; _side < 6; ++_side) { // determine the color for each of the 6 faces const Geometry::side_t side = static_cast<Geometry::side_t> (_side); if (!prepareCamera(context, box, side)) continue; context.getRenderingContext().clearScreen(Util::Color4f(0.0f, 0.0f, 0.0f, 0.0f)); context.displayNode(node, USE_WORLD_MATRIX); } context.getRenderingContext().popFBO(); colorTexture->downloadGLTexture(context.getRenderingContext()); //////////// debug // static uint32_t counter=0; // stringstream ss; // ss << "screens/colorcube_" << counter++ << ".png"; // Util::FileName filename(ss.str()); // Rendering::Serialization::saveTexture(context.getRenderingContext(), colorTexture.get(), filename); //////////// end debug // determine the color for each of the 6 faces for (uint8_t _side = 0; _side < 6; ++_side) { const Geometry::side_t side = static_cast<Geometry::side_t> (_side); if (prepareCamera(context, box, side)){ const Color4ub c = calculateColor(colorTexture.get(), camera->getViewport()); //calculate color from texture cc.colors[static_cast<uint8_t> (side)] = c; } else { cc.colors[static_cast<uint8_t> (side)] = Color4ub(0, 0, 0, 0); } } context.getRenderingContext().popLighting(); } else{ context.getRenderingContext().pushAndSetFBO(fbo.get()); // enable the fbo // 2. case: the node is not a closed GroupNode (inner node) for (uint8_t _side = 0; _side < 6; ++_side) { // for each of the six faces Geometry::side_t side = static_cast<Geometry::side_t> (_side); if (!prepareCamera(context, box, side)) continue; context.getRenderingContext().clearScreen(Util::Color4f(0.0f, 0.0f, 0.0f, 0.0f)); context.getRenderingContext().pushAndSetMatrix_modelToCamera( context.getRenderingContext().getMatrix_worldToCamera() ); // draw faces using blending context.getRenderingContext().pushAndSetBlending(Rendering::BlendingParameters(Rendering::BlendingParameters::ONE, Rendering::BlendingParameters::ONE_MINUS_SRC_ALPHA)); context.getRenderingContext().pushAndSetCullFace(Rendering::CullFaceParameters(Rendering::CullFaceParameters::CULL_BACK)); context.getRenderingContext().pushAndSetDepthBuffer(Rendering::DepthBufferParameters(true, false, Rendering::Comparison::LESS)); context.getRenderingContext().pushAndSetLighting(Rendering::LightingParameters(false)); context.getRenderingContext().applyChanges(); distanceQueue_t nodes(side); // distance queue used for sorting the children with color cubes // sort (back-to-front order) the children according to distance of current side to the camera for(const auto & child : children) { nodes.push(child); } // draw the faces in back-to-front order while (!nodes.empty()) { Node* child = nodes.top(); nodes.pop(); const ColorCube & childsColorCube = ColorCube::getColorCube(child); //cerr << "before drawing colored box " << endl; childsColorCube.drawColoredBox(context, child->getWorldBB()); //cerr << "after drawing colored box" << endl; } context.getRenderingContext().popLighting(); context.getRenderingContext().popDepthBuffer(); context.getRenderingContext().popCullFace(); context.getRenderingContext().popBlending(); context.getRenderingContext().popMatrix_modelToCamera(); } context.getRenderingContext().popFBO(); colorTexture->downloadGLTexture(context.getRenderingContext()); // determine the color for each of the 6 faces for (uint8_t _side = 0; _side < 6; ++_side) { Geometry::side_t side = static_cast<Geometry::side_t> (_side); if (!prepareCamera(context, box, side)) continue; //calculate color from texture cc.colors[static_cast<uint8_t> (side)] = calculateColor(colorTexture.get(), camera->getViewport()); } } ColorCube::attachColorCube(node, cc); }
/** * Implementation of algorithm given on P65 of the Script * (With the discussed modifications) */ Color RayTracer::calculateColor(Ray& r, int recursions) { //FIXME Initialize with the background color Color c = Color(0.0, 0.0, 0.0); //Get the first intersection with any shape Shape* closestShape = _scene._shapes[0]; double closestIP; bool hasIntersection = false; r[1].normalize(); Ray r_moved = Ray(r.getPoint(1), r[1]); for (unsigned i = 0; i < _scene._shapes.size(); i++) { std::vector<double> intersections = _scene._shapes[i]->ensIntersect(r_moved); if (!hasIntersection && !intersections.empty()) { closestShape = _scene._shapes[i]; closestIP = intersections[0]; hasIntersection = true; } else if (hasIntersection && !intersections.empty() && intersections[0] < closestIP) { closestShape = _scene._shapes[i]; closestIP = intersections[0]; } } //if there are any intersections if (hasIntersection) { //Get the Point of the first intersection Vector3 intersection = r_moved.getPoint(closestIP); //P := intersection //The normal at the point of intersection Vector3 n = closestShape->normal(intersection).normalize(); //Make sure the normal points into the right direction //FIXME is this correct?? Vector3 r_dir_op = -r[1]; if (dot_product(r_dir_op, n) < 0) { //if (dot_product(V, n) < 0) { n = -n; } Ray normal = Ray(intersection, n); //The reflected ray at the point of intersection //FIXME Move to the shape class, as it is the same for all the shapes Ray reflected = Ray(intersection, (2 * n * (dot_product(n, r_dir_op)) - r_dir_op)); /* * Calculate the light compartments using the lightmodel */ //Ambient color //FIXME: Take L_a of scene instead of 1 c = 1 * _lightModel.getAmbient(closestShape->_material) * closestShape->getColor(intersection); for (unsigned i = 0; i < _scene._lightSources.size(); i++) { LightSource* l = _scene._lightSources[i]; if (!isHidden(l, intersection)) { double diffuse = _lightModel.getDiffuse(normal, l, closestShape->_material); double specular = _lightModel.getSpecular(reflected, l, closestShape->_material); c += diffuse * closestShape->getColor(intersection) * l->_intensity; c += specular * l->_color * l->_intensity; } } //Recursive call if (recursions > 0) { c += closestShape->_material.k_reflex * calculateColor(reflected, --recursions); } } return c; }