Beispiel #1
0
void SBVRGeogen2D::ComputeGeometry(bool bMeshOnly) {
  InitBBOX();

  if (bMeshOnly) {
    m_vSliceTrianglesX.clear();
    m_vSliceTrianglesY.clear();
    m_vSliceTrianglesZ.clear();

    SortMeshWithoutVolume(m_vSliceTrianglesX);
    m_vSliceTrianglesY = m_vSliceTrianglesX;
    m_vSliceTrianglesZ = m_vSliceTrianglesX;

    return;
  }

  // TODO handle mesh when the volume is not empty
 
  switch (m_eMethod) {
    case METHOD_REZK : ComputeGeometryRezk(); break;
    case METHOD_KRUEGER : ComputeGeometryKrueger(); break;
    default : ComputeGeometryKruegerFast(); break;
  }

  if(m_bClipPlaneEnabled && (m_bClipVolume || m_bClipMesh)) {
    PLANE<float> transformed = m_ClipPlane * m_matView;
    const FLOATVECTOR3 normal(transformed.xyz());
    const float d = transformed.d();
    m_vSliceTrianglesX = ClipTriangles(m_vSliceTrianglesX, normal, d);
    m_vSliceTrianglesY = ClipTriangles(m_vSliceTrianglesY, normal, d);
    m_vSliceTrianglesZ = ClipTriangles(m_vSliceTrianglesZ, normal, d);
  }

}
//#####################################################################
// Function Intersects
//#####################################################################
template<class T> bool Rectangle_Intersects(RAY<VECTOR<T,3> >& ray,const PLANE<T>& plane,const PLANE<T>& bounding_plane1,const PLANE<T>& bounding_plane2,const PLANE<T>& bounding_plane3,const PLANE<T>& bounding_plane4,const T thickness_over_two)
{
    RAY<VECTOR<T,3> > ray_temp;ray.Save_Intersection_Information(ray_temp);
    if(INTERSECTION::Intersects(ray,plane,thickness_over_two)){
        VECTOR<T,3> point=ray.Point(ray.t_max);
        if(!bounding_plane1.Outside(point,thickness_over_two) && !bounding_plane2.Outside(point,thickness_over_two) && !bounding_plane3.Outside(point,thickness_over_two)
            && !bounding_plane4.Outside(point,thickness_over_two)) return true;
        else ray.Restore_Intersection_Information(ray_temp);}
    return false;
}
Beispiel #3
0
//Classify by a single plane
int AA_BOUNDING_BOX::ClassifyByPlane(const PLANE & plane) const
{
	bool vertexInFront=false;
	bool vertexBehind=false;
	bool vertexOnPlane=false;

	//Loop through vertices
	for(int i=0; i<8; ++i)
	{
		int vertexClassification=plane.ClassifyPoint(vertices[i]);

		if(vertexClassification==POINT_IN_FRONT_OF_PLANE)
			vertexInFront=true;

		if(vertexClassification==POINT_ON_PLANE)
			vertexOnPlane=true;

		if(vertexClassification==POINT_BEHIND_PLANE)
			vertexBehind=true;
	}

	if(vertexInFront==true && vertexBehind==false && vertexOnPlane==false)
		return BOX_IN_FRONT_OF_PLANE;

	if(vertexBehind==true && vertexInFront==false && vertexOnPlane==false)
		return BOX_BEHIND_PLANE;

	return BOX_STRADDLING_PLANE;
}
Beispiel #4
0
void GLRaycaster::RenderBox(const RenderRegion& renderRegion,
                            const FLOATVECTOR3& vCenter,
                            const FLOATVECTOR3& vExtend,
                            const FLOATVECTOR3& vMinCoords,
                            const FLOATVECTOR3& vMaxCoords, bool bCullBack,
                            EStereoID eStereoID) const {
  
  m_pContext->GetStateManager()->SetCullState(bCullBack ? CULL_FRONT : CULL_BACK);

  FLOATVECTOR3 vMinPoint, vMaxPoint;
  vMinPoint = (vCenter - vExtend/2.0);
  vMaxPoint = (vCenter + vExtend/2.0);

  // \todo compute this only once per brick
  FLOATMATRIX4 m = ComputeEyeToTextureMatrix(renderRegion,
                                             FLOATVECTOR3(vMaxPoint.x, vMaxPoint.y, vMaxPoint.z),
                                             FLOATVECTOR3(vMaxCoords.x, vMaxCoords.y, vMaxCoords.z),
                                             FLOATVECTOR3(vMinPoint.x, vMinPoint.y, vMinPoint.z),
                                             FLOATVECTOR3(vMinCoords.x, vMinCoords.y, vMinCoords.z),
                                             eStereoID);

  m.setTextureMatrix();

  std::vector<FLOATVECTOR3> posData;
  MaxMinBoxToVector(vMinPoint, vMaxPoint, posData);

  if ( m_bClipPlaneOn ) {
    // clip plane is normaly defined in world space, transform back to model space
    FLOATMATRIX4 inv = (renderRegion.rotation * renderRegion.translation).inverse();
    PLANE<float> transformed = m_ClipPlane.Plane() * inv;

    const FLOATVECTOR3 normal(transformed.xyz().normalized());
    const float d = transformed.d();

    Clipper::BoxPlane(posData, normal, d);
  }

  m_pBBoxVBO->ClearVertexData();
  m_pBBoxVBO->AddVertexData(posData);

  m_pBBoxVBO->Bind();
  m_pBBoxVBO->Draw(GL_TRIANGLES);
  m_pBBoxVBO->UnBind();
}
void CollisionFace::SphereCollision(const VC3 &position, float radius, Storm3D_CollisionInfo &colinfo, bool accurate)
{
	VC3 closest;
	getClosestPoint(position, vertex0, vertex1, vertex2, closest);

	float sqRange = closest.GetSquareRangeTo(position);
	if(sqRange < radius * radius && sqRange < colinfo.range * colinfo.range)
	{
		colinfo.hit = true;
		colinfo.range = sqrtf(sqRange);
		colinfo.position = closest;
		colinfo.plane_normal = plane.planenormal;
		colinfo.inside_amount = radius - colinfo.range;

		float planeRange = plane.GetPointRange(position);
		if(planeRange < 0)
			colinfo.plane_normal = -colinfo.plane_normal;
	}
}
Beispiel #6
0
bool BOUNDING_SPHERE::IsPolygonInside(	const PLANE & planeEquation,
										int numVertices,
										const VECTOR3D * vertices) const
{
	//See if the sphere intersects the plane
	//if not, return false
	float distance=planeEquation.GetDistance(centre);

	if(distance>radius || distance<-radius)
		return false;

	//Project the sphere's centre onto the plane of the polygon
	VECTOR3D projectedCentre=centre-distance*planeEquation.normal;


	//See if this is inside the polygon
	double angle=0.0;

	//Loop through the vertices
	for(int i=0; i<numVertices; ++i)
	{
		//Calculate the vector from this vertex to the point
		const VECTOR3D & vA=vertices[i]-projectedCentre;

		//Calculate the vector from the next vertex to the point
		const VECTOR3D & vB=vertices[(i+1) % numVertices]-projectedCentre;

		//Get the angle between these vectors
		angle+=acos(vA.DotProduct(vB)/(vA.GetLength() * vB.GetLength()));
	}

	//If the sum of the angles is greater than 2*Pi (with an error factor) then the point is inside
	if(angle>=1.99*M_PI)
		return true;


	//Check if the sphere intersects any of the edges
	
	//Loop through the edges
	for(int i=0; i<numVertices; ++i)
	{
		//Get the closest point on the current edge to the centre of the sphere
		VECTOR3D closestPoint;

		//Get the 2 vertices on this edge
		const VECTOR3D & v1=vertices[i];
		const VECTOR3D & v2=vertices[(i+1) % numVertices];

		//Get the length of this edge, and a vector along it
		float edgeLength=(v2-v1).GetLength();
		VECTOR3D edgeDirection=v2-v1;
		edgeDirection.Normalize();

		//Get the vector from the first vertex to the centre
		VECTOR3D vertexToCentre=centre-v1;

		//Calculate a parameter for how far along the edge we are
		float t=vertexToCentre.DotProduct(edgeDirection);

		//If t<=0, closestPoint is v1
		//If t>=edgeLength, closestPoint is v2
		//Otherwise, lerp between the points
		if(t<=0)
			closestPoint=v1;
		else if(t>=edgeLength)
			closestPoint=v2;
		else
			closestPoint=v1.lerp(v2, t/edgeLength);

		//Calculate if this point is inside the sphere
		if((closestPoint-centre).GetSquaredLength()<radius*radius)
			return true;
	}

	return false;
}
//#####################################################################
// Function Filter_By_Slice_Planes
//#####################################################################
template<class T,class T_ARRAY> void OPENGL_POINTS_3D<T,T_ARRAY>::
Filter_By_Slice_Planes(const PLANE<T> &leftplane, const PLANE<T> &rightplane)
{
    Store_Draw_Mask(true);
    for(int i=1;i<=points.Size();i++) (*draw_mask)(i)=leftplane.Lazy_Inside(points(i)) && rightplane.Lazy_Inside(points(i));
}
Beispiel #8
0
Intersection intersectionLinePlane(const VEC3& P, const VEC3& Dir, const PLANE& Plane, VEC3& Inter)
{
	return intersectionLinePlane(P, Dir, Plane.normal()*Plane.d(), Plane.normal(), Inter);
}