void AzimuthZenithController::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { if((not m_isDragging) && (event->buttons().testFlag(Qt::LeftButton)) && (m_dragStart - event->scenePos()).manhattanLength() > 3) { qDebug() << (m_dragStart - event->scenePos()).manhattanLength(); m_isDragging = true; } if(not m_isDragging) return; m_azimuthAnimation.stop(); m_zenithAnimation.stop(); // for now, we're just gonna calculate current and // last to emulate the events we used to get. QPointF current = event->scenePos(); QPointF last = event->lastScenePos(); setAzimuth(azimuth() + (float)(current.x() - last.x())/2.0); setZenith(zenith() - (float)(current.y() - last.y())/2.0); m_targetAzimuth = m_azimuth; m_targetZenith = m_zenith; event->accept(); }
void a4_render(// What to render SceneNode* root, // Where to output the image const std::string& filename, // Image size int width, int height, // Viewing parameters const Point3D& eye, const Vector3D& view, const Vector3D& up, double fov, // Lighting parameters const Colour& ambient, const std::list<Light*>& lights, double fogDist ) { // Fill in raytracing code here. std::cerr << "Stub: a4_render(" << root << ",\n " << filename << ", " << width << ", " << height << ",\n " << eye << ", " << view << ", " << up << ", " << fov << ",\n " << ambient << ",\n {"; for (std::list<Light*>::const_iterator I = lights.begin(); I != lights.end(); ++I) { if (I != lights.begin()) std::cerr << ", "; std::cerr << **I; } std::cerr << "});" << std::endl; Vector3D viewVector = view; Vector3D upVector = up; Vector3D sideVector = viewVector.cross(upVector); viewVector.normalize(); upVector.normalize(); sideVector.normalize(); Image img(width, height, 3); int progress = 0; int numPixels = width*height; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int newProgress = (int)((double)(y*width + x)/numPixels*100); if(newProgress >= progress+5){ progress = newProgress; std::cerr << progress << std::endl; } double d = height/2.0/tan(toRadian(fov)/2); Vector3D dir = (x-(width/2.0))*sideVector + ((height/2.0)-y)*upVector + d*viewVector; dir.normalize(); Ray ray = Ray(eye, dir); bool fogOn = true; if(fogDist <= 0) fogOn = false; Colour* color = rayTrace(ambient, eye, ray, root, lights, 5, fogDist); Colour fog(1,1,1); if(color == NULL) { // sunset colours Colour horizon(0.94, 0.55, 0.05); Colour zenith(0.2, 0.27, 0.4); Colour bg = zenith*(1-(double)y/height) + horizon*((double)y/height); if(fogOn) color = new Colour(0.8,0.8,0.8); else color = new Colour(bg); } img(x, y, 0) = color->R(); img(x, y, 1) = color->G(); img(x, y, 2) = color->B(); } } img.savePng(filename); }
/***********************************************************************//** * @brief Return zenith angle in degrees * * @return zenith angle in degrees. ***************************************************************************/ inline double GHorizDir::zenith_deg() const { return (zenith() * gammalib::rad2deg); }