示例#1
0
  void renderWireframe(Renderer& renderer, const VolumeTest& volume) const
  {
    m_contained.renderWireframe(renderer, volume, Instance::localToWorld(), getSelectable().isSelected());

    m_curveNURBS.renderComponentsSelected(renderer, volume, localToWorld());
    m_curveCatmullRom.renderComponentsSelected(renderer, volume, localToWorld());
  }
示例#2
0
void LightNode::renderInactiveComponents(RenderableCollector& collector, const VolumeTest& volume, const bool selected) const
{
	// greebo: We are not in component selection mode (and the light is still selected),
	// check if we should draw the center of the light anyway
	if (selected
		&& GlobalSelectionSystem().ComponentMode() != SelectionSystem::eVertex
		&& EntitySettings::InstancePtr()->alwaysShowLightVertices())
	{
		if (_light.isProjected())
		{
			EntitySettings& settings = *EntitySettings::InstancePtr();
			const Vector3& colourStartEndInactive = settings.getLightVertexColour(EntitySettings::VERTEX_START_END_DESELECTED);
			const Vector3& colourVertexInactive = settings.getLightVertexColour(EntitySettings::VERTEX_DESELECTED);

			const_cast<Light&>(_light).colourLightStart() = colourStartEndInactive;
			const_cast<Light&>(_light).colourLightEnd() = colourStartEndInactive;
			const_cast<Light&>(_light).colourLightTarget() = colourVertexInactive;
			const_cast<Light&>(_light).colourLightRight() = colourVertexInactive;
			const_cast<Light&>(_light).colourLightUp() = colourVertexInactive;

			// Render the projection points
			_light.renderProjectionPoints(collector, volume, localToWorld());
		}
		else
		{
			const Vector3& colourVertexInactive = EntitySettings::InstancePtr()->getLightVertexColour(
				EntitySettings::VERTEX_INACTIVE);

			const_cast<Light&>(_light).getDoom3Radius().setCenterColour(colourVertexInactive);
			_light.renderLightCentre(collector, volume, localToWorld());
		}
	}
}
示例#3
0
// Function checks if a point is inside a polygon using the point-polygon
// collision detection discussed in class
unsigned int pointPolygonCollide(object *o, vector *v) {

	// cols = number of edge collisions
	int cols = 0, i;
	vector *pv = o->verts; 
	vector v1, v2;

	// iterate through all polygon vertices
	for (i = 0; i < o->size-1; i++) {

		v1 = localToWorld(pv+i, o);
		v2 = localToWorld(pv+i+1, o);

		// Ensure v1.y < v.y < v2.y or skip this edge
		if (v->y > v1.y && v->y < v2.y) {
		} else if (v->y < v1.y && v->y > v2.y) {
			v1 = v2; v2 = localToWorld(pv+i, o);
		} else continue;

		// Ensure the edge is to the right of v and if so, increment cols
		if ((v->y - v1.y) / (v2.y - v1.y) * v2.x +
		    (v2.y - v->y) / (v2.y - v1.y) * v1.x > v->x) {
			cols++;
		}
	}

	// If there is an odd number of collisions return true, else return false
	return cols%2;
}
示例#4
0
 void renderComponents(Renderer& renderer, const VolumeTest& volume) const
 {
   if(GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex)
   {
     m_curveNURBS.renderComponents(renderer, volume, localToWorld());
     m_curveCatmullRom.renderComponents(renderer, volume, localToWorld());
   }
 }
示例#5
0
void RotateGizmoRing::render(IViewer* viewer) const {
  GraphicsInterface::beginPerformanceEvent("Ring");

  GraphicsInterface::resetRenderTarget(true);
  GraphicsInterface::setViewport(GraphicsInterface::backBufferSize());
  GraphicsInterface::setBlendState(IGraphicsInterface::NOBLEND);
  GraphicsInterface::setRenderState(CULL_MODE_NONE, true);

  if (drawBounds_)
  {
    effect_->beginDraw();

    BoundingBox bounds = boundingBox();

    Vector4 scale(bounds.max.x - bounds.min.x, bounds.max.y - bounds.min.y, bounds.max.z - bounds.min.z, 2.0f);
    scale /= 2.0f;

    Vector4 translation(bounds.max.x + bounds.min.x, bounds.max.y + bounds.min.y, bounds.max.z + bounds.min.z, 2.0f);
    translation /= 2.0f;

    Matrix4x4 model = localToWorld() * Matrix4x4::translation(translation) * Matrix4x4::scale(scale);
    Matrix4x4 modelViewProjection = viewer->projection() * viewer->viewTransform() * model * Matrix4x4::scale(1.0001f);

    effect_->setUniform(modelViewProjection, "ModelViewProj");
    effect_->setUniform(ringColor_, "Color");

    effect_->commitBuffers();
    GraphicsInterface::drawVertexBuffer(Geometry::UNIT_CUBE_VERTEX_BUFFER, Geometry::UNIT_CUBE_VERTEX_COUNT, Geometry::UNIT_CUBE_VERTEX_FORMAT);
    effect_->endDraw();
  }

  // ring
  { 
    effect_->beginDraw();

    Color3 color = ringColor_;

    if (isHighlighted_) {
      color = Color3::YELLOW;
    }

    effect_->setUniform(color, "Color");

    Matrix4x4 modelViewProjection = viewer->projection() * viewer->viewTransform() * localToWorld();
    effect_->setUniform(modelViewProjection, "ModelViewProj");
    
    Matrix4x4 model = localToWorld();
    effect_->setUniform(model, "Model");

    effect_->commitBuffers();
    GraphicsInterface::drawVertexBuffer(Geometry::UNIT_CIRCLE_VERTEX_BUFFER, Geometry::UNIT_CIRCLE_VERTEX_COUNT, Geometry::UNIT_CIRCLE_VERTEX_FORMAT);
    effect_->endDraw();
  }

  GraphicsInterface::endPerformanceEvent();
}
示例#6
0
void Node::evaluateBounds() const
{
	if (_boundsChanged)
	{
		ASSERT_MESSAGE(!_boundsMutex, "re-entering bounds evaluation");
		_boundsMutex = true;

		_bounds = childBounds();

		_bounds.includeAABB(
			AABB::createFromOrientedAABBSafe(localAABB(), localToWorld())
		);

		_boundsMutex = false;
		_boundsChanged = false;

		// Now that our bounds are re-calculated, notify the scenegraph
		GraphPtr sceneGraph = _sceneGraph.lock();

		if (sceneGraph)
		{
			sceneGraph->nodeBoundsChanged(const_cast<Node*>(this)->shared_from_this());
		}
	}
}
示例#7
0
void BrushInstance::testSelectComponents (Selector& selector, SelectionTest& test, SelectionSystem::EComponentMode mode)
{
	test.BeginMesh(localToWorld());

	switch (mode) {
	case SelectionSystem::eVertex: {
		for (VertexInstances::iterator i = m_vertexInstances.begin(); i != m_vertexInstances.end(); ++i) {
			(*i).testSelect(selector, test);
		}
	}
		break;
	case SelectionSystem::eEdge: {
		for (EdgeInstances::iterator i = m_edgeInstances.begin(); i != m_edgeInstances.end(); ++i) {
			(*i).testSelect(selector, test);
		}
	}
		break;
	case SelectionSystem::eFace: {
		if (test.getVolume().fill()) {
			for (FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i) {
				(*i).testSelect(selector, test);
			}
		} else {
			for (FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i) {
				(*i).testSelect_centroid(selector, test);
			}
		}
	}
		break;
	default:
		break;
	}
}
示例#8
0
文件: glutils.cpp 项目: krafczyk/AMS
void GLMatrix::Rotate(const GLVertex3 & pivot, const GLVector3 & axis, double angle)
{
   // Update martix so resulting transform has been rotated about 'pivot'
   // (in parent frame), round vector 'axis', through 'angle' (radians)
   // Equivalent to glRotate function, but with addition of translation
   // and compounded on top of existing.
   GLVector3 nAxis = axis;
   nAxis.Normalise();
   double x = nAxis.X();
   double y = nAxis.Y();
   double z = nAxis.Z();
   double c = TMath::Cos(angle);
   double s = TMath::Sin(angle);

   // Calculate local rotation, with pre-translation to local pivot origin
   GLMatrix rotMat;
   rotMat[ 0] = x*x*(1-c) + c;   rotMat[ 4] = x*y*(1-c) - z*s; rotMat[ 8] = x*z*(1-c) + y*s; rotMat[12] = pivot[0];
   rotMat[ 1] = y*x*(1-c) + z*s; rotMat[ 5] = y*y*(1-c) + c;   rotMat[ 9] = y*z*(1-c) - x*s; rotMat[13] = pivot[1];
   rotMat[ 2] = x*z*(1-c) - y*s; rotMat[ 6] = y*z*(1-c) + x*s; rotMat[10] = z*z*(1-c) + c;   rotMat[14] = pivot[2];
   rotMat[ 3] = 0.0;             rotMat[ 7] = 0.0;             rotMat[11] = 0.0;             rotMat[15] = 1.0;
   GLMatrix localToWorld(-pivot);

   // TODO: Ugly - should use quaternions to avoid compound rounding errors and
   // triple multiplication
   *this = rotMat * localToWorld * (*this);
}
示例#9
0
GfMatrix4d
UsdGeomConstraintTarget::ComputeInWorldSpace(
    UsdTimeCode time,
    UsdGeomXformCache *xfCache) const
{
    if (not IsDefined()) {
        TF_CODING_ERROR("Invalid constraint target.");
        return GfMatrix4d(1);
    }

    const UsdPrim &modelPrim = GetAttr().GetPrim();

    GfMatrix4d localToWorld(1);
    if (xfCache) {
        xfCache->SetTime(time);
        localToWorld = xfCache->GetLocalToWorldTransform(modelPrim);
    } else {
        UsdGeomXformCache cache;
        cache.SetTime(time);
        localToWorld = cache.GetLocalToWorldTransform(modelPrim);
    }

    GfMatrix4d localConstraintSpace(1.);
    if (not Get(&localConstraintSpace, time)) {
        TF_WARN("Failed to get value of constraint target '%s' at path <%s>.",
                GetIdentifier().GetText(), GetAttr().GetPath().GetText());
        return localConstraintSpace;
    }

    return localConstraintSpace * localToWorld;
}
示例#10
0
// Renders the components of this light instance
void LightNode::renderComponents(RenderableCollector& collector, const VolumeTest& volume) const
{
	// Render the components (light center) as selected/deselected, if we are in the according mode
	if (GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex)
	{
		if (_light.isProjected())
		{
			// A projected light
			
			EntitySettings& settings = *EntitySettings::InstancePtr();

			const Vector3& colourStartEndSelected = settings.getLightVertexColour(EntitySettings::VERTEX_START_END_SELECTED);
			const Vector3& colourStartEndDeselected = settings.getLightVertexColour(EntitySettings::VERTEX_START_END_DESELECTED);
			const Vector3& colourVertexSelected = settings.getLightVertexColour(EntitySettings::VERTEX_SELECTED);
			const Vector3& colourVertexDeselected = settings.getLightVertexColour(EntitySettings::VERTEX_DESELECTED);

			// Update the colour of the light center dot
			const_cast<Light&>(_light).colourLightTarget() = (_lightTargetInstance.isSelected()) ? colourVertexSelected : colourVertexDeselected;
			const_cast<Light&>(_light).colourLightRight() = (_lightRightInstance.isSelected()) ? colourVertexSelected : colourVertexDeselected;
			const_cast<Light&>(_light).colourLightUp() = (_lightUpInstance.isSelected()) ? colourVertexSelected : colourVertexDeselected;

			const_cast<Light&>(_light).colourLightStart() = (_lightStartInstance.isSelected()) ? colourStartEndSelected : colourStartEndDeselected;
			const_cast<Light&>(_light).colourLightEnd() = (_lightEndInstance.isSelected()) ? colourStartEndSelected : colourStartEndDeselected;

			// Render the projection points
			_light.renderProjectionPoints(collector, volume, localToWorld());
		}
		else
		{
			// A point light

			// Update the colour of the light center dot
			if (_lightCenterInstance.isSelected())
			{
				const_cast<Light&>(_light).getDoom3Radius().setCenterColour(
					EntitySettings::InstancePtr()->getLightVertexColour(EntitySettings::VERTEX_SELECTED));
				_light.renderLightCentre(collector, volume, localToWorld());
			}
			else
			{
				const_cast<Light&>(_light).getDoom3Radius().setCenterColour(
					EntitySettings::InstancePtr()->getLightVertexColour(EntitySettings::VERTEX_DESELECTED));
				_light.renderLightCentre(collector, volume, localToWorld());
			}
		}
	}
}
示例#11
0
void MD5ModelNode::renderSolid(RenderableCollector& collector, const VolumeTest& volume) const
{
	_lightList->calculateIntersectingLights();

	assert(_renderEntity);

	render(collector, volume, localToWorld(), *_renderEntity);
}
示例#12
0
void BrushInstance::renderWireframe (Renderer& renderer, const VolumeTest& volume) const
{
	m_brush.evaluateBRep();

	renderClipPlane(renderer, volume);

	renderWireframe(renderer, volume, localToWorld());
}
示例#13
0
void EclassModelNode::renderWireframe(RenderableCollector& collector, const VolumeTest& volume) const
{
	EntityNode::renderWireframe(collector, volume);

	if (isSelected())
	{
		_renderOrigin.render(collector, volume, localToWorld());
	}
}
示例#14
0
void Doom3GroupNode::renderWireframe(RenderableCollector& collector, const VolumeTest& volume) const
{
	EntityNode::renderWireframe(collector, volume);

	_d3Group.renderWireframe(collector, volume, localToWorld(), isSelected());

	_nurbsEditInstance.renderComponentsSelected(collector, volume, Matrix4::getIdentity());
	_catmullRomEditInstance.renderComponentsSelected(collector, volume, Matrix4::getIdentity());
}
示例#15
0
void Doom3GroupNode::renderWireframe(RenderableCollector& collector, const VolumeTest& volume) const
{
	EntityNode::renderWireframe(collector, volume);

	m_contained.renderWireframe(collector, volume, localToWorld(), isSelected());

	m_curveNURBS.renderComponentsSelected(collector, volume, Matrix4::getIdentity());
	m_curveCatmullRom.renderComponentsSelected(collector, volume, Matrix4::getIdentity());
}
示例#16
0
 void testSelectComponents(Selector& selector, SelectionTest& test, SelectionSystem::EComponentMode mode)
 {
   if(mode == SelectionSystem::eVertex)
   {
     test.BeginMesh(localToWorld());
     m_curveNURBS.testSelect(selector, test);
     m_curveCatmullRom.testSelect(selector, test);
   }
 }
示例#17
0
void MD5ModelNode::insertLight(const RendererLight& light) {
	const Matrix4& l2w = localToWorld();

	_surfaceLightLists.resize(_model->size());

	SurfaceLightLists::iterator j = _surfaceLightLists.begin();
	for (MD5Model::const_iterator i = _model->begin(); i != _model->end(); ++i) {
		Surface_addLight(*i->surface, *j++, l2w, light);
	}
}
示例#18
0
void Doom3GroupNode::renderSolid(RenderableCollector& collector, const VolumeTest& volume) const
{
	EntityNode::renderSolid(collector, volume);

	_d3Group.renderSolid(collector, volume, localToWorld(), isSelected());

	// Render curves always relative to the absolute map origin
	_nurbsEditInstance.renderComponentsSelected(collector, volume, Matrix4::getIdentity());
	_catmullRomEditInstance.renderComponentsSelected(collector, volume, Matrix4::getIdentity());
}
示例#19
0
void LightNode::renderWireframe(RenderableCollector& collector, const VolumeTest& volume) const
{
	EntityNode::renderWireframe(collector, volume);

	const bool lightIsSelected = isSelected();
	_light.renderWireframe(
		collector, volume, localToWorld(), lightIsSelected
	);

	renderInactiveComponents(collector, volume, lightIsSelected);
}
示例#20
0
void BrushInstance::testSelect (Selector& selector, SelectionTest& test)
{
	test.BeginMesh(localToWorld());

	SelectionIntersection best;
	for (FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i) {
		(*i).testSelect(test, best);
	}
	if (best.valid()) {
		selector.addIntersection(best);
	}
}
示例#21
0
void Doom3GroupNode::testSelectComponents(Selector& selector, SelectionTest& test, SelectionSystem::EComponentMode mode)
{
	if (mode == SelectionSystem::eVertex)
	{
		test.BeginMesh(localToWorld());

		_originInstance.testSelect(selector, test);

		_nurbsEditInstance.testSelect(selector, test);
		_catmullRomEditInstance.testSelect(selector, test);
	}
}
示例#22
0
// Add a light to this model instance
void PicoModelNode::insertLight(const RendererLight& light)
{
    // Calculate transform from the superclass
    const Matrix4& l2w = localToWorld();

    // If the light's AABB intersects the oriented AABB of this model instance,
    // add the light to our light list
    if (light.intersectsAABB(AABB::createFromOrientedAABB(_picoModel->localAABB(), l2w)))
    {
        _lights.addLight(light);
    }
}
示例#23
0
  void testSelect(Selector& selector, SelectionTest& test)
  {
    test.BeginMesh(localToWorld());
    SelectionIntersection best;

    m_contained.testSelect(selector, test, best);

    if(best.valid())
    {
      Selector_add(selector, getSelectable(), best);
    }
  }
示例#24
0
KRNode::LodVisibility KRLODGroup::calcLODVisibility(const KRViewport &viewport)
{
    if(m_min_distance == 0 && m_max_distance == 0) {
        return LOD_VISIBILITY_VISIBLE;
    } else {
        float lod_bias = viewport.getLODBias();
        lod_bias = pow(2.0f, -lod_bias);
        
        // Compare using squared distances as sqrt is expensive
        float sqr_distance;
        float sqr_prestream_distance;
        
        KRVector3 world_camera_position = viewport.getCameraPosition();
        KRVector3 local_camera_position = worldToLocal(world_camera_position);
        KRVector3 local_reference_point = m_reference.nearestPoint(local_camera_position);
        
        if(m_use_world_units) {
            KRVector3 world_reference_point = localToWorld(local_reference_point);
            sqr_distance = (world_camera_position - world_reference_point).sqrMagnitude() * (lod_bias * lod_bias);
            sqr_prestream_distance = getContext().KRENGINE_PRESTREAM_DISTANCE * getContext().KRENGINE_PRESTREAM_DISTANCE;
        } else {
            sqr_distance = (local_camera_position - local_reference_point).sqrMagnitude() * (lod_bias * lod_bias);
            
            KRVector3 world_reference_point = localToWorld(local_reference_point);
            sqr_prestream_distance = worldToLocal(KRVector3::Normalize(world_reference_point - world_camera_position) * getContext().KRENGINE_PRESTREAM_DISTANCE).sqrMagnitude(); // TODO, FINDME - Optimize with precalc?
            
        }
        
        float sqr_min_visible_distance = m_min_distance * m_min_distance;
        float sqr_max_visible_distance = m_max_distance * m_max_distance;
        if((sqr_distance >= sqr_min_visible_distance || m_min_distance == 0) && (sqr_distance < sqr_max_visible_distance || m_max_distance == 0)) {
            return LOD_VISIBILITY_VISIBLE;
        } else if((sqr_distance >= sqr_min_visible_distance - sqr_prestream_distance || m_min_distance == 0) && (sqr_distance < sqr_max_visible_distance + sqr_prestream_distance || m_max_distance == 0)) {
            return LOD_VISIBILITY_PRESTREAM;
        } else {
            return LOD_VISIBILITY_HIDDEN;
        }
    }
}
示例#25
0
void Doom3GroupNode::testSelect(Selector& selector, SelectionTest& test)
{
	test.BeginMesh(localToWorld());
	SelectionIntersection best;

	// Pass the selection test to the Doom3Group class
	m_contained.testSelect(selector, test, best);

	// If the selectionIntersection is non-empty, add the selectable to the SelectionPool
	if (best.valid()) {
		Selector_add(selector, getSelectable(), best);
	}
}
示例#26
0
void Doom3GroupNode::renderComponents(RenderableCollector& collector, const VolumeTest& volume) const
{
	if (GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex)
	{
		_nurbsEditInstance.renderComponents(collector, volume, Matrix4::getIdentity());

		_catmullRomEditInstance.renderComponents(collector, volume, Matrix4::getIdentity());

		// Register the renderable with OpenGL
		if (!_d3Group.isModel()) {
			_originInstance.render(collector, volume, localToWorld());
		}
	}
}
示例#27
0
void BrushInstance::selectPlanes (Selector& selector, SelectionTest& test, const PlaneCallback& selectedPlaneCallback)
{
	test.BeginMesh(localToWorld());

	PlanePointer brushPlanes[c_brush_maxFaces];
	PlanesIterator j = brushPlanes;

	for (Brush::const_iterator i = m_brush.begin(); i != m_brush.end(); ++i) {
		*j++ = &(*i)->plane3();
	}

	for (FaceInstances::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i) {
		(*i).selectPlane(selector, Line(test.getNear(), test.getFar()), brushPlanes, j, selectedPlaneCallback);
	}
}
示例#28
0
//Index to...
void GridMapping::indexToWorld(int i,int j,int k, double &w_x, double &w_y,double &w_z) const{
    double l_x,l_y,l_z;
    indexToLocal(i, j, k, l_x, l_y, l_z);
    localToWorld(l_x, l_y, l_z, w_x, w_y, w_z);
    
    /*
     l_x = ((double)i)/((double)xdim());
     l_y = ((double)j)/((double)ydim());
     l_z = ((double)k)/((double)zdim());
     
     w_x = l_x*_trans[0][0]+l_y*_trans[1][0]+l_z*_trans[2][0]+_trans[3][0];
     w_y = l_x*_trans[0][1]+l_y*_trans[1][1]+l_z*_trans[2][1]+_trans[3][1];
     w_z = l_x*_trans[0][2]+l_y*_trans[1][2]+l_z*_trans[2][2]+_trans[3][2];
     
    */
    
}
示例#29
0
void Node::evaluateBounds() const
{
	if (_boundsChanged)
	{
		ASSERT_MESSAGE(!_boundsMutex, "re-entering bounds evaluation");
		_boundsMutex = true;

		_bounds = childBounds();

		_bounds.includeAABB(
		    aabb_for_oriented_aabb_safe(localAABB(), localToWorld())
		);

		_boundsMutex = false;
		_boundsChanged = false;

		// Now that our bounds are re-calculated, notify the scenegraph
		GlobalSceneGraph().nodeBoundsChanged(const_cast<Node*>(this)->shared_from_this());
	}
}
示例#30
0
void Doom3GroupNode::renderSolid(RenderableCollector& collector, const VolumeTest& volume) const
{
	EntityNode::renderSolid(collector, volume);

	// greebo: Check if the skin needs updating before rendering.
	if (_updateSkin) {
		if (m_contained.isModel()) {
			// Instantiate a walker class equipped with the new value
			SkinChangedWalker walker(_entity.getKeyValue("skin"));
			// Update all children
			traverse(walker);
		}

		_updateSkin = false;
	}

	m_contained.renderSolid(collector, volume, localToWorld(), isSelected());

	// Render curves always relative to the absolute map origin
	m_curveNURBS.renderComponentsSelected(collector, volume, Matrix4::getIdentity());
	m_curveCatmullRom.renderComponentsSelected(collector, volume, Matrix4::getIdentity());
}