void GameObject::setClipping(const Extents& extents) { _clipULX = extents.getMinX(); _clipULY = extents.getMinY(); _clipWidth = extents.getWidth(); _clipHeight = extents.getHeight(); }
void Screen::set_ortho_viewport(const Extents& extents) { int screenHeight = m_extents->bottom() - m_extents->top(); const int& x1 = extents.left(), y1 = extents.top(), x2 = extents.right(), y2 = extents.bottom(); glViewport(x1, screenHeight - y2, x2-x1, y2-y1); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-1, x2+1-x1, y2+1-y1, -1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
/** Fits the components to the specified container extents and returns them. @param extents The extents of the container for which this object is the layout @return A collection of laid-out components to be put into the container */ std::vector<LaidOutGUIComponent> ExplicitLayout::fit(const Extents& extents) const { std::vector<LaidOutGUIComponent> components(m_components); for(std::vector<LaidOutGUIComponent>::iterator it=components.begin(), iend=components.end(); it!=iend; ++it) { // TODO: Check that the component fits within the container's extents, and clip // its own extents if not. it->extents = it->extents.translate(extents.left(), extents.top()); } return components; }
AABox EntityItem::getAABox() const { // _position represents the position of the registration point. glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint; glm::vec3 unrotatedMinRelativeToEntity = glm::vec3(0.0f, 0.0f, 0.0f) - (_dimensions * _registrationPoint); glm::vec3 unrotatedMaxRelativeToEntity = _dimensions * registrationRemainder; Extents unrotatedExtentsRelativeToRegistrationPoint = { unrotatedMinRelativeToEntity, unrotatedMaxRelativeToEntity }; Extents rotatedExtentsRelativeToRegistrationPoint = unrotatedExtentsRelativeToRegistrationPoint.getRotated(getRotation()); // shift the extents to be relative to the position/registration point rotatedExtentsRelativeToRegistrationPoint.shiftBy(_position); return AABox(rotatedExtentsRelativeToRegistrationPoint); }
Way::Extents Way::extents() const { Extents extents; for ( Nodes::const_iterator iter = _nodes.begin(); iter != _nodes.end(); ++iter ) { Node::RefPtr node ( *iter ); if ( node.valid() ) { extents.expand ( Extents::Vertex ( node->location()[0], node->location()[1] ) ); } } return extents; }
void ModelOverlay::render() { if (!_visible) { return; } if (_model.isActive()) { if (_model.isRenderable()) { _model.render(_alpha); } bool displayModelBounds = Menu::getInstance()->isOptionChecked(MenuOption::DisplayModelBounds); if (displayModelBounds) { glm::vec3 unRotatedMinimum = _model.getUnscaledMeshExtents().minimum; glm::vec3 unRotatedMaximum = _model.getUnscaledMeshExtents().maximum; glm::vec3 unRotatedExtents = unRotatedMaximum - unRotatedMinimum; float width = unRotatedExtents.x; float height = unRotatedExtents.y; float depth = unRotatedExtents.z; Extents rotatedExtents = _model.getUnscaledMeshExtents(); rotatedExtents.rotate(_rotation); glm::vec3 rotatedSize = rotatedExtents.maximum - rotatedExtents.minimum; const glm::vec3& modelScale = _model.getScale(); glPushMatrix(); { glTranslatef(_position.x, _position.y, _position.z); // draw the rotated bounding cube glColor4f(0.0f, 0.0f, 1.0f, 1.0f); glPushMatrix(); { glScalef(rotatedSize.x * modelScale.x, rotatedSize.y * modelScale.y, rotatedSize.z * modelScale.z); glutWireCube(1.0); } glPopMatrix(); // draw the model relative bounding box glm::vec3 axis = glm::axis(_rotation); glRotatef(glm::degrees(glm::angle(_rotation)), axis.x, axis.y, axis.z); glScalef(width * modelScale.x, height * modelScale.y, depth * modelScale.z); glColor3f(0.0f, 1.0f, 0.0f); glutWireCube(1.0); } glPopMatrix(); } } }
void Screen::set_persp_viewport(const Extents& extents, double fovY, double zNear, double zFar) { int screenHeight = m_extents->bottom() - m_extents->top(); const int& x1 = extents.left(), y1 = extents.top(), x2 = extents.right(), y2 = extents.bottom(); glViewport(x1, screenHeight - y2, x2-x1, y2-y1); double width = x2 - x1, height = y2 - y1; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(fovY, width / height, zNear, zFar); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }
void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) { // compute default joint transforms int numStates = _rig->getJointStateCount(); QVector<glm::mat4> transforms; transforms.fill(glm::mat4(), numStates); // compute bounding box that encloses all shapes Extents totalExtents; totalExtents.reset(); totalExtents.addPoint(glm::vec3(0.0f)); for (int i = 0; i < numStates; i++) { // compute the default transform of this joint const JointState& state = _rig->getJointState(i); int parentIndex = state.getParentIndex(); if (parentIndex == -1) { transforms[i] = _rig->getJointTransform(i); } else { glm::quat modifiedRotation = state.getPreRotation() * state.getDefaultRotation() * state.getPostRotation(); transforms[i] = transforms[parentIndex] * glm::translate(state.getTranslation()) * state.getPreTransform() * glm::mat4_cast(modifiedRotation) * state.getPostTransform(); } // Each joint contributes a sphere at its position glm::vec3 axis(state.getBoneRadius()); glm::vec3 jointPosition = extractTranslation(transforms[i]); totalExtents.addPoint(jointPosition + axis); totalExtents.addPoint(jointPosition - axis); } // compute bounding shape parameters // NOTE: we assume that the longest side of totalExtents is the yAxis... glm::vec3 diagonal = totalExtents.maximum - totalExtents.minimum; // ... and assume the radius is half the RMS of the X and Z sides: _boundingCapsuleRadius = 0.5f * sqrtf(0.5f * (diagonal.x * diagonal.x + diagonal.z * diagonal.z)); _boundingCapsuleHeight = diagonal.y - 2.0f * _boundingCapsuleRadius; glm::vec3 rootPosition = _rig->getJointState(geometry.rootJointIndex).getPosition(); _boundingCapsuleLocalOffset = 0.5f * (totalExtents.maximum + totalExtents.minimum) - rootPosition; _boundingRadius = 0.5f * glm::length(diagonal); }
/// The minimum bounding cube for the entity accounting for it's rotation. /// This accounts for the registration point (upon which rotation occurs around). /// AACube EntityItem::getMinimumAACube() const { // _position represents the position of the registration point. glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint; glm::vec3 unrotatedMinRelativeToEntity = glm::vec3(0.0f, 0.0f, 0.0f) - (_dimensions * _registrationPoint); glm::vec3 unrotatedMaxRelativeToEntity = _dimensions * registrationRemainder; Extents unrotatedExtentsRelativeToRegistrationPoint = { unrotatedMinRelativeToEntity, unrotatedMaxRelativeToEntity }; Extents rotatedExtentsRelativeToRegistrationPoint = unrotatedExtentsRelativeToRegistrationPoint.getRotated(getRotation()); // shift the extents to be relative to the position/registration point rotatedExtentsRelativeToRegistrationPoint.shiftBy(_position); // the cube that best encompasses extents is... AABox box(rotatedExtentsRelativeToRegistrationPoint); glm::vec3 centerOfBox = box.calcCenter(); float longestSide = box.getLargestDimension(); float halfLongestSide = longestSide / 2.0f; glm::vec3 cornerOfCube = centerOfBox - glm::vec3(halfLongestSide, halfLongestSide, halfLongestSide); // old implementation... not correct!!! return AACube(cornerOfCube, longestSide); }
void Dataset::createGeoTransform ( GeoTransform &transfrom, const Extents& extents, unsigned int width, unsigned int height ) { // Get the extents lower left and upper right. Extents::Vertex ll ( extents.minimum() ); Extents::Vertex ur ( extents.maximum() ); // Get the length in x and y. const double xLength ( ur[0] - ll[0] ); const double yLength ( ur[1] - ll[1] ); // Figure out the pixel resolution. const double xResolution ( xLength / width ); const double yResolution ( yLength / height ); // Make sure there is enough room. transfrom.resize ( 6 ); transfrom[0] = ll[0]; // top left x transfrom[1] = xResolution; // w-e pixel resolution transfrom[2] = 0; // rotation, 0 if image is "north up" transfrom[3] = ur[1]; // top left y transfrom[4] = 0; // rotation, 0 if image is "north up" transfrom[5] = -yResolution; // n-s pixel resolution }
void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) { // compute default joint transforms int numStates = _jointStates.size(); assert(numStates == _shapes.size()); QVector<glm::mat4> transforms; transforms.fill(glm::mat4(), numStates); // compute bounding box that encloses all shapes Extents totalExtents; totalExtents.reset(); totalExtents.addPoint(glm::vec3(0.0f)); for (int i = 0; i < numStates; i++) { // compute the default transform of this joint JointState& state = _jointStates[i]; const FBXJoint& joint = state.getFBXJoint(); int parentIndex = joint.parentIndex; if (parentIndex == -1) { transforms[i] = _jointStates[i].getTransform(); } else { glm::quat modifiedRotation = joint.preRotation * joint.rotation * joint.postRotation; transforms[i] = transforms[parentIndex] * glm::translate(joint.translation) * joint.preTransform * glm::mat4_cast(modifiedRotation) * joint.postTransform; } // Each joint contributes its point to the bounding box glm::vec3 jointPosition = extractTranslation(transforms[i]); totalExtents.addPoint(jointPosition); Shape* shape = _shapes[i]; if (!shape) { continue; } // Each joint with a shape contributes to the totalExtents: a box // that contains the sphere centered at the end of the joint with radius of the bone. // TODO: skip hand and arm shapes for bounding box calculation int type = shape->getType(); if (type == CAPSULE_SHAPE) { // add the two furthest surface points of the capsule CapsuleShape* capsule = static_cast<CapsuleShape*>(shape); float radius = capsule->getRadius(); glm::vec3 axis(radius); Extents shapeExtents; shapeExtents.reset(); shapeExtents.addPoint(jointPosition + axis); shapeExtents.addPoint(jointPosition - axis); totalExtents.addExtents(shapeExtents); } else if (type == SPHERE_SHAPE) { float radius = shape->getBoundingRadius(); glm::vec3 axis(radius); Extents shapeExtents; shapeExtents.reset(); shapeExtents.addPoint(jointPosition + axis); shapeExtents.addPoint(jointPosition - axis); totalExtents.addExtents(shapeExtents); } } // compute bounding shape parameters // NOTE: we assume that the longest side of totalExtents is the yAxis... glm::vec3 diagonal = totalExtents.maximum - totalExtents.minimum; // ... and assume the radius is half the RMS of the X and Z sides: float capsuleRadius = 0.5f * sqrtf(0.5f * (diagonal.x * diagonal.x + diagonal.z * diagonal.z)); _boundingShape.setRadius(capsuleRadius); _boundingShape.setHalfHeight(0.5f * diagonal.y - capsuleRadius); glm::vec3 rootPosition = _jointStates[geometry.rootJointIndex].getPosition(); _boundingShapeLocalOffset = 0.5f * (totalExtents.maximum + totalExtents.minimum) - rootPosition; _boundingRadius = 0.5f * glm::length(diagonal); }
void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) { // compute default joint transforms int numStates = _jointStates.size(); QVector<glm::mat4> transforms; transforms.fill(glm::mat4(), numStates); QVector<VerletPoint>& ragdollPoints = _ragdoll->getPoints(); // compute the default transforms and slam the ragdoll positions accordingly // (which puts the shapes where we want them) for (int i = 0; i < numStates; i++) { JointState& state = _jointStates[i]; const FBXJoint& joint = state.getFBXJoint(); int parentIndex = joint.parentIndex; if (parentIndex == -1) { transforms[i] = _jointStates[i].getTransform(); ragdollPoints[i].initPosition(extractTranslation(transforms[i])); continue; } glm::quat modifiedRotation = joint.preRotation * joint.rotation * joint.postRotation; transforms[i] = transforms[parentIndex] * glm::translate(joint.translation) * joint.preTransform * glm::mat4_cast(modifiedRotation) * joint.postTransform; // setting the ragdollPoints here slams the VerletShapes into their default positions ragdollPoints[i].initPosition(extractTranslation(transforms[i])); } // compute bounding box that encloses all shapes Extents totalExtents; totalExtents.reset(); totalExtents.addPoint(glm::vec3(0.0f)); for (int i = 0; i < _shapes.size(); i++) { Shape* shape = _shapes[i]; if (!shape) { continue; } // TODO: skip hand and arm shapes for bounding box calculation Extents shapeExtents; shapeExtents.reset(); glm::vec3 localPosition = shape->getTranslation(); int type = shape->getType(); if (type == CAPSULE_SHAPE) { // add the two furthest surface points of the capsule CapsuleShape* capsule = static_cast<CapsuleShape*>(shape); glm::vec3 axis; capsule->computeNormalizedAxis(axis); float radius = capsule->getRadius(); float halfHeight = capsule->getHalfHeight(); axis = halfHeight * axis + glm::vec3(radius); shapeExtents.addPoint(localPosition + axis); shapeExtents.addPoint(localPosition - axis); totalExtents.addExtents(shapeExtents); } else if (type == SPHERE_SHAPE) { float radius = shape->getBoundingRadius(); glm::vec3 axis = glm::vec3(radius); shapeExtents.addPoint(localPosition + axis); shapeExtents.addPoint(localPosition - axis); totalExtents.addExtents(shapeExtents); } } // compute bounding shape parameters // NOTE: we assume that the longest side of totalExtents is the yAxis... glm::vec3 diagonal = totalExtents.maximum - totalExtents.minimum; // ... and assume the radius is half the RMS of the X and Z sides: float capsuleRadius = 0.5f * sqrtf(0.5f * (diagonal.x * diagonal.x + diagonal.z * diagonal.z)); _boundingShape.setRadius(capsuleRadius); _boundingShape.setHalfHeight(0.5f * diagonal.y - capsuleRadius); glm::vec3 rootPosition = _jointStates[geometry.rootJointIndex].getPosition(); _boundingShapeLocalOffset = 0.5f * (totalExtents.maximum + totalExtents.minimum) - rootPosition; _boundingRadius = 0.5f * glm::length(diagonal); }