Ray Fisheye::_getRay(const double x, const double y) { double phi, theta; // TODO: Force into a circle of radius = min(width,height) // Map x and y to [-1,1] double _x = 2.0 * x - 1.0; double _y = 2.0 * y - 1.0; double r = _x*_x + _y*_y; if (r > 1.0) { return Ray(); } r = sqrt(r); if (IS_ZERO(r)) { phi = 0.0; } else { phi = asin(_y / r); if (_x < 0.0) { phi = M_PI - phi; } } theta = r * getFieldOfView() / 2.0 ; Vector dir = Vector(sin(theta)*cos(phi), sin(theta)*sin(phi), cos(theta)); dir = basis * dir; dir.normalize(); // TODO: Necessary? return Ray(position, dir, 1.0); }
void TransformState::getProjMatrix(mat4& projMatrix, uint16_t nearZ) const { if (size.isEmpty()) { return; } // Find the distance from the center point [width/2, height/2] to the // center top point [width/2, 0] in Z units, using the law of sines. // 1 Z unit is equivalent to 1 horizontal px at the center of the map // (the distance between[width/2, height/2] and [width/2 + 1, height/2]) const double halfFov = getFieldOfView() / 2.0; const double groundAngle = M_PI / 2.0 + getPitch(); const double topHalfSurfaceDistance = std::sin(halfFov) * getCameraToCenterDistance() / std::sin(M_PI - groundAngle - halfFov); // Calculate z distance of the farthest fragment that should be rendered. const double furthestDistance = std::cos(M_PI / 2 - getPitch()) * topHalfSurfaceDistance + getCameraToCenterDistance(); // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance` const double farZ = furthestDistance * 1.01; matrix::perspective(projMatrix, getFieldOfView(), double(size.width) / size.height, nearZ, farZ); const bool flippedY = viewportMode == ViewportMode::FlippedY; matrix::scale(projMatrix, projMatrix, 1, flippedY ? 1 : -1, 1); matrix::translate(projMatrix, projMatrix, 0, 0, -getCameraToCenterDistance()); using NO = NorthOrientation; switch (getNorthOrientation()) { case NO::Rightwards: matrix::rotate_y(projMatrix, projMatrix, getPitch()); break; case NO::Downwards: matrix::rotate_x(projMatrix, projMatrix, -getPitch()); break; case NO::Leftwards: matrix::rotate_y(projMatrix, projMatrix, -getPitch()); break; default: matrix::rotate_x(projMatrix, projMatrix, getPitch()); break; } matrix::rotate_z(projMatrix, projMatrix, getAngle() + getNorthOrientationAngle()); matrix::translate(projMatrix, projMatrix, pixel_x() - size.width / 2.0f, pixel_y() - size.height / 2.0f, 0); matrix::scale(projMatrix, projMatrix, 1, 1, 1.0 / Projection::getMetersPerPixelAtLatitude(getLatLng(LatLng::Unwrapped).latitude(), getZoom())); }
void ViewpointNode::outputContext(ostream& printStream, const char *indentString) { SFVec3f *position = getPositionField(); SFRotation *orientation = getOrientationField(); SFBool *jump = getJumpField(); SFString *description = getDescriptionField(); printStream << indentString << "\t" << "fieldOfView " << getFieldOfView() << endl; printStream << indentString << "\t" << "jump " << jump << endl; printStream << indentString << "\t" << "position " << position << endl; printStream << indentString << "\t" << "orientation " << orientation << endl; printStream << indentString << "\t" << "description " << description << endl; }
void CX3DViewpointNode::print(int indent) { FILE *fp = CX3DParser::getDebugLogFp(); char *nodeName = getNodeName(); if (nodeName) { float x, y, z, rot; CX3DParser::printIndent(indent); fprintf(fp, "%s (%s)\n", nodeName, CX3DNode::getNodeTypeString(getNodeType())); CX3DParser::printIndent(indent+1); fprintf(fp, "fieldOfView : (%f)\n", getFieldOfView()->getValue()); CX3DParser::printIndent(indent+1); fprintf(fp, "jump : %s\n", getJump()->getValue() ? "TRUE" : "FALSE"); CX3DParser::printIndent(indent+1); fprintf(fp, "retainUserOffsets : %s\n", getRetainUserOffsets()->getValue() ? "TRUE" : "FALSE"); getOrientation()->getValue(x, y, z, rot); CX3DParser::printIndent(indent+1); fprintf(fp, "orientation : (%f %f %f)(%f)\n", x, y, z, rot); getPosition()->getValue(x, y, z); CX3DParser::printIndent(indent+1); fprintf(fp, "position : (%f %f %f)\n", x, y, z); getCenterOfRotation()->getValue(x, y, z); CX3DParser::printIndent(indent+1); fprintf(fp, "centerOfRotation : (%f %f %f)\n", x, y, z); CX3DParser::printIndent(indent+1); fprintf(fp, "description : (%s)\n", getDescription()->getValue()); } }
vector<Vec2> Level::getVisibleTiles(Vec2 pos, VisionId vision) const { return filter(getFieldOfView(vision).getVisibleTiles(pos), [&](Vec2 v) { return isWithinVision(pos, v, vision); }); }
vector<Vec2> Level::getVisibleTilesNoDarkness(Vec2 pos, VisionId vision) const { return getFieldOfView(vision).getVisibleTiles(pos); }
bool Level::canSee(Vec2 from, Vec2 to, VisionId vision) const { return isWithinVision(from, to, vision) && getFieldOfView(vision).canSee(from, to); }
void TransformState::getProjMatrix(mat4& projMatrix, uint16_t nearZ, bool aligned) const { if (size.isEmpty()) { return; } // Find the distance from the center point [width/2, height/2] to the // center top point [width/2, 0] in Z units, using the law of sines. // 1 Z unit is equivalent to 1 horizontal px at the center of the map // (the distance between[width/2, height/2] and [width/2 + 1, height/2]) const double halfFov = getFieldOfView() / 2.0; const double groundAngle = M_PI / 2.0 + getPitch(); const double topHalfSurfaceDistance = std::sin(halfFov) * getCameraToCenterDistance() / std::sin(M_PI - groundAngle - halfFov); // Calculate z distance of the farthest fragment that should be rendered. const double furthestDistance = std::cos(M_PI / 2 - getPitch()) * topHalfSurfaceDistance + getCameraToCenterDistance(); // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance` const double farZ = furthestDistance * 1.01; matrix::perspective(projMatrix, getFieldOfView(), double(size.width) / size.height, nearZ, farZ); const bool flippedY = viewportMode == ViewportMode::FlippedY; matrix::scale(projMatrix, projMatrix, 1, flippedY ? 1 : -1, 1); matrix::translate(projMatrix, projMatrix, 0, 0, -getCameraToCenterDistance()); using NO = NorthOrientation; switch (getNorthOrientation()) { case NO::Rightwards: matrix::rotate_y(projMatrix, projMatrix, getPitch()); break; case NO::Downwards: matrix::rotate_x(projMatrix, projMatrix, -getPitch()); break; case NO::Leftwards: matrix::rotate_y(projMatrix, projMatrix, -getPitch()); break; default: matrix::rotate_x(projMatrix, projMatrix, getPitch()); break; } matrix::rotate_z(projMatrix, projMatrix, getAngle() + getNorthOrientationAngle()); const double dx = pixel_x() - size.width / 2.0f, dy = pixel_y() - size.height / 2.0f; matrix::translate(projMatrix, projMatrix, dx, dy, 0); if (axonometric) { // mat[11] controls perspective projMatrix[11] = 0; // mat[8], mat[9] control x-skew, y-skew projMatrix[8] = xSkew; projMatrix[9] = ySkew; } matrix::scale(projMatrix, projMatrix, 1, 1, 1.0 / Projection::getMetersPerPixelAtLatitude(getLatLng(LatLng::Unwrapped).latitude(), getZoom())); // Make a second projection matrix that is aligned to a pixel grid for rendering raster tiles. // We're rounding the (floating point) x/y values to achieve to avoid rendering raster images to fractional // coordinates. Additionally, we adjust by half a pixel in either direction in case that viewport dimension // is an odd integer to preserve rendering to the pixel grid. We're rotating this shift based on the angle // of the transformation so that 0°, 90°, 180°, and 270° rasters are crisp, and adjust the shift so that // it is always <= 0.5 pixels. if (aligned) { const float xShift = float(size.width % 2) / 2, yShift = float(size.height % 2) / 2; const double angleCos = std::cos(angle), angleSin = std::sin(angle); double devNull; const float dxa = -std::modf(dx, &devNull) + angleCos * xShift + angleSin * yShift; const float dya = -std::modf(dy, &devNull) + angleCos * yShift + angleSin * xShift; matrix::translate(projMatrix, projMatrix, dxa > 0.5 ? dxa - 1 : dxa, dya > 0.5 ? dya - 1 : dya, 0); } }
GLfloat CC3Camera::getEffectiveFieldOfView() { return (GLfloat)MIN(getFieldOfView() / getUniformScale(), kMaxEffectiveFOV); }
glm::mat4 Camera::calculateProjectionMatrix(){ // Use all of the intrinsic values to create the projection matrix return glm::perspective(getFieldOfView(), getViewport().getAspectRatio(), getNearClip(), getFarClip()); }