Esempio n. 1
0
btScalar TRACK::RayTestProcessor::addSingleResult(
	btCollisionWorld::LocalRayResult & rayResult,
	bool normalInWorldSpace)
{
	// We only support static mesh collision shapes
	if (!(rayResult.m_collisionObject->getCollisionFlags() & btCollisionObject::CF_STATIC_OBJECT) &&
		(rayResult.m_collisionObject->getCollisionShape()->getShapeType() != TRIANGLE_MESH_SHAPE_PROXYTYPE))
	{
		return 1.0;
	}
	//std::cerr << rayResult.m_hitFraction << "    ";

	// Road bezier patch ray test
	assert(m_ray);
	btVector3 rayFrom = m_ray->m_rayFrom;
	btVector3 rayTo = m_ray->m_rayTo;
	btScalar rayLen = m_ray->m_rayLen;
	btVector3 rayVec = rayTo - rayFrom;

	// patch space
	MATHVECTOR<float, 3> from(rayFrom[1], rayFrom[2], rayFrom[0]);
	MATHVECTOR<float, 3> to(rayTo[1], rayTo[2], rayTo[0]);
	MATHVECTOR<float, 3> dir(rayVec[1], rayVec[2], rayVec[0]);
	dir = dir / rayLen;

	int patchId = m_ray->m_patchid;
	const BEZIER * colBez = 0;
	MATHVECTOR<float, 3> colPoint;
	MATHVECTOR<float, 3> colNormal;
	for (std::list<ROADSTRIP>::const_iterator i = m_data.roads.begin(); i != m_data.roads.end(); ++i)
	{
		const BEZIER * bez(0);
		MATHVECTOR<float, 3> norm;
		MATHVECTOR<float, 3> point(to);
		if (i->Collide(from, dir, rayLen, patchId, point, bez, norm) &&
			((point - from).MagnitudeSquared() < (colPoint - from).MagnitudeSquared()))
		{
			colPoint = point;
			colNormal = norm;
			colBez = bez;
		}
	}

	if (colBez)
	{
		btVector3 hitPoint(colPoint[2], colPoint[0], colPoint[1]);
		btVector3 hitNormal(colNormal[2], colNormal[0], colNormal[1]);
		btScalar dist_p = hitNormal.dot(hitPoint);
		btScalar dist_a = hitNormal.dot(rayFrom);
		btScalar dist_b = hitNormal.dot(rayTo);
		btScalar fraction = (dist_a - dist_p) / (dist_a - dist_b);
		rayResult.m_hitFraction = fraction;
		rayResult.m_hitNormalLocal = hitNormal;
		m_ray->m_patch = colBez;
		m_ray->m_patchid = patchId;
	}
	//std::cerr << rayResult.m_hitFraction << "    ";

	return m_ray->addSingleResult(rayResult, true);
}
 TEST(HitPointInterval, ShouldComputeIntersectionOfEmptyAndNonEmptyIntervals) {
   HitPointInterval interval1, interval2;
   HitPoint hitPoint(box, 5, Vector3d(), Vector3d());
   interval2.add(hitPoint);
   HitPointInterval intersectionInterval = interval1 & interval2;
   ASSERT_TRUE(intersectionInterval.min() == HitPoint::undefined());
   ASSERT_TRUE(intersectionInterval.max() == HitPoint::undefined());
 }
 TEST(HitPointInterval, ShouldComputeUnionOfEmptyAndNonEmptyIntervals) {
   HitPointInterval interval1, interval2;
   HitPoint hitPoint(box, 5, Vector3d(), Vector3d());
   interval2.add(hitPoint);
   HitPointInterval unionInterval = interval1 | interval2;
   
   ASSERT_TRUE(unionInterval.min() == hitPoint);
   ASSERT_TRUE(unionInterval.max() == hitPoint);
 }
Esempio n. 4
0
	VOVERRIDE void OnClick(VMenuEventDataObject *pEvent) 
	{
		VDialog::OnClick(pEvent);

 		hkvVec2 vMousePos = GetContext()->GetCurrentMousePos();
 		hkvVec3 vDir;
 		Vision::Contexts.GetCurrentContext()->GetTraceDirFromScreenPos(vMousePos.x, vMousePos.y, vDir, 10000.f);
 		hkvVec3 vFrom = Vision::Camera.GetCurrentCameraPosition();
 		hkvVec3 vTo = vFrom + vDir;

		const float v2h = vHavokConversionUtils::GetVision2HavokScale();
		hkVector4 from; from.set( vFrom.x*v2h, vFrom.y*v2h, vFrom.z*v2h );
		hkVector4 to; to.set( vTo.x*v2h, vTo.y*v2h, vTo.z*v2h );

		hkaiNavMeshQueryMediator::HitDetails hit;
		hit.m_hitFaceKey = HKAI_INVALID_PACKED_KEY;
		hit.m_hitFraction = -1.f;
		if (vHavokAiModule::GetInstance()->GetAiWorld()->getDynamicQueryMediator()->castRay(from, to, hit))
		{
			hkVector4 hitPoint; hitPoint.setInterpolate(from, to, hit.m_hitFraction);
			hitPoint.mul4( vHavokConversionUtils::GetHavok2VisionScale() );
			if (pEvent->m_iButtons & BUTTON_LMOUSE)
			{
				vStartPoint.set( hitPoint(0), hitPoint(1), hitPoint(2) );				
			}
			else
			{
				vEndPoint.set( hitPoint(0), hitPoint(1), hitPoint(2) );
			}
		}
	}
Esempio n. 5
0
void CTrashCleanCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
	int iCount;
	CPoint hitPoint(point);

    SetFocus();

    if (!m_bEnbale)
        goto Clear0;

	hitPoint.y = point.y + LONG((m_rcRealClient.Height() - m_rcClient.Height()) * (m_nPos * 1.0) / (m_rcRealClient.Height()));

	for (iCount = 0; iCount < (int)m_vecTrashItems.size(); ++iCount)
	{
		if (m_vecTrashItems[iCount].rcBox.PtInRect(hitPoint)||m_vecTrashItems[iCount].rcIcon.PtInRect(hitPoint))
		{
			m_vecTrashItems[iCount].bShowDetail = !m_vecTrashItems[iCount].bShowDetail;
            m_nSelectedIndex = m_vecTrashItems[iCount].uItemId;
			
            _RangeItems();
			
            Invalidate();
			
            goto Clear0;
		}
		if (m_vecTrashItems[iCount].bShowDetail)
		{		
            if (_CheckInCheckDetail(hitPoint, &m_vecTrashItems[iCount]))
            {
                Invalidate();
                goto Clear0;
            }
			else if (_CheckInCheckBox(hitPoint, &m_vecTrashItems[iCount]) ||
                     _CheckInSelectArea(hitPoint, &m_vecTrashItems[iCount]))
			{
                Invalidate();
				goto Clear0;
			}
// 			if (m_vecTrashItems[iCount].rcIcon.PtInRect(hitPoint))
// 			{
// 				_CheckItemAll(&m_vecTrashItems[iCount]);
// 				Invalidate(FALSE);
// 				goto Clear0;
// 			}
		}
	}

    m_nSelectedIndex = -1;

Clear0:
	SetMsgHandled(FALSE);
}
Esempio n. 6
0
bool
HdxIntersector::Result::_ResolveHit(int index, int x, int y, float z,
                                    HdxIntersector::Hit* hit) const
{
    unsigned char const* primIds = _primIds.get();
    unsigned char const* instanceIds = _instanceIds.get();
    unsigned char const* elementIds = _elementIds.get();

    GfVec3d hitPoint(0,0,0);
    gluUnProject(x, y, z,
                 _params.viewMatrix.GetArray(),
                 _params.projectionMatrix.GetArray(),
                 &_viewport[0],
                 &((hitPoint)[0]),
                 &((hitPoint)[1]),
                 &((hitPoint)[2]));

    int idIndex = index*4;

    int primId = HdxRenderSetupTask::DecodeIDRenderColor(&primIds[idIndex]);
    hit->objectId = _index->GetRprimPathFromPrimId(primId);

    if (!hit->IsValid()) {
        return false;
    }

    int instanceIndex = HdxRenderSetupTask::DecodeIDRenderColor(
            &instanceIds[idIndex]);
    int elementIndex = HdxRenderSetupTask::DecodeIDRenderColor(
            &elementIds[idIndex]);

    bool rprimValid = _index->GetSceneDelegateAndInstancerIds(hit->objectId,
                                                           &(hit->delegateId),
                                                           &(hit->instancerId));

    if (!TF_VERIFY(rprimValid, "%s\n", hit->objectId.GetText())) {
        return false;
    }

    hit->worldSpaceHitPoint = GfVec3f(hitPoint);
    hit->ndcDepth = float(z);
    hit->instanceIndex = instanceIndex;
    hit->elementIndex = elementIndex; 

    if (TfDebug::IsEnabled(HDX_INTERSECT)) {
        std::cout << *hit << std::endl;
    }

    return true;
}
Esempio n. 7
0
bool RenderSVGText::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, int _x, int _y, int _tx, int _ty, HitTestAction hitTestAction)
{
    PointerEventsHitRules hitRules(PointerEventsHitRules::SVG_TEXT_HITTESTING, style()->svgStyle()->pointerEvents());
    bool isVisible = (style()->visibility() == VISIBLE);
    if (isVisible || !hitRules.requireVisible) {
        if ((hitRules.canHitStroke && (style()->svgStyle()->hasStroke() || !hitRules.requireStroke))
            || (hitRules.canHitFill && (style()->svgStyle()->hasFill() || !hitRules.requireFill))) {
            AffineTransform totalTransform = absoluteTransform();
            double localX, localY;
            totalTransform.inverse().map(_x, _y, &localX, &localY);
            FloatPoint hitPoint(_x, _y);
            return RenderBlock::nodeAtPoint(request, result, (int)localX, (int)localY, _tx, _ty, hitTestAction);
        }
    }
    return false;
}
Intersection Ring::SampleOnGeometrySurface(const float &u, const float &v, const glm::vec3 &point)
{
    float r =  0.5f + u * 0.5f;
    float theta = v * 2.0f * PI;

    glm::vec3 hitPoint(r * cos(theta),
                       r * sin(theta),
                       0.0f);

    Intersection result;
    result.point = glm::vec3(transform.T() * glm::vec4(hitPoint, 1.0f));
    result.object_hit = this;
    result.texture_color = Material::GetImageColorInterp(GetUVCoordinates(hitPoint), material->texture);

    //Store the tangent and bitangent
    SetNormalTangentBitangent(hitPoint,result);

    result.t = 1.0f;

    return result;
}
Esempio n. 9
0
bool
HdxIntersector::Result::_ResolveHit(int index, int x, int y, float z,
                                    HdxIntersector::Hit* hit) const
{
    unsigned char const* primIds = _primIds.get();
    unsigned char const* instanceIds = _instanceIds.get();
    unsigned char const* elementIds = _elementIds.get();

    GfVec3d hitPoint(0,0,0);
    gluUnProject(x, y, z,
                 _params.viewMatrix.GetArray(),
                 _params.projectionMatrix.GetArray(),
                 &_viewport[0],
                 &((hitPoint)[0]),
                 &((hitPoint)[1]),
                 &((hitPoint)[2]));

    int idIndex = index*4;

    GfVec4i primIdColor(
        primIds[idIndex+0],
        primIds[idIndex+1],
        primIds[idIndex+2],
        primIds[idIndex+3]);

    GfVec4i instanceIdColor(
        instanceIds[idIndex+0],
        instanceIds[idIndex+1],
        instanceIds[idIndex+2],
        instanceIds[idIndex+3]);

    int instanceIndex = 0;
    hit->objectId = _index->GetPrimPathFromPrimIdColor(primIdColor,
                        instanceIdColor, &instanceIndex);

    if (not hit->IsValid()) {
        return false;
    }

    // XXX: either this should be done in the render index or all render index
    // logic should be moved here. If moved here, the shader logic should move
    // into Hdx as well.
    int elemIndex = ((elementIds[idIndex+0] & 0xff) <<  0) |
                    ((elementIds[idIndex+1] & 0xff) <<  8) |
                    ((elementIds[idIndex+2] & 0xff) << 16);

    HdRprimSharedPtr const& rprim = _index->GetRprim(hit->objectId);
    if (not TF_VERIFY(rprim, "%s\n", hit->objectId.GetText())) {
        return false;
    }

    hit->delegateId = rprim->GetDelegate()->GetDelegateID();
    hit->instancerId = rprim->GetInstancerId();
    hit->worldSpaceHitPoint = GfVec3f(hitPoint);
    hit->ndcDepth = float(z);
    hit->instanceIndex = instanceIndex;
    hit->elementIndex = elemIndex; 

    if (TfDebug::IsEnabled(HDX_INTERSECT)) {
        std::cout << *hit << std::endl;
    }

    return true;
}
Esempio n. 10
0
void CTrashCleanCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
	BOOL bIn = FALSE;
	int iCount, jCount;
	CPoint hitPoint(point);

	hitPoint.y = point.y + LONG((m_rcRealClient.Height() - m_rcClient.Height()) * (m_nPos * 1.0) / (m_rcRealClient.Height()));
	SetFocus();	
	for (iCount = 0; iCount < (int)m_vecTrashItems.size(); ++iCount)
	{
		if (m_vecTrashItems[iCount].rcBox.PtInRect(hitPoint))
		{
			bIn = TRUE;
			CString des = m_vecTrashItems[iCount].strItemDes;
			if (m_strTip.CompareNoCase(des) != 0 || !m_bToolTipActive)
			{
                m_bToolTipActive = TRUE;
				m_strTip = des;
				m_wndToolTip.Activate(FALSE);
				m_wndToolTip.UpdateTipText((_U_STRINGorID)des, m_hWnd);
				m_wndToolTip.Activate(TRUE);	
			}
            if (m_nHoverIndex != m_vecTrashItems[iCount].uItemId)
            {
                m_nHoverIndex = m_vecTrashItems[iCount].uItemId;
                InvalidateRect(NULL);
            }
            goto Clear0;
		}
        if (m_vecTrashItems[iCount].bShowDetail)
        {
            for (jCount = 0; jCount < (int)m_vecTrashItems[iCount].vecItems.size(); ++jCount)
            {

                if (m_vecTrashItems[iCount].vecItems[jCount].rcCheck.PtInRect(hitPoint) ||
                    m_vecTrashItems[iCount].vecItems[jCount].rcSelected.PtInRect(hitPoint))
                {                
                    if (m_nSelectedIndex == m_vecTrashItems[iCount].vecItems[jCount].nItemId)
                    {
                        if (m_vecTrashItems[iCount].vecItems[jCount].rcDetail.PtInRect(hitPoint))
                        {
                            m_vecTrashItems[iCount].vecItems[jCount].bInDetail = TRUE;
                        }
                        else
                        {
                            m_vecTrashItems[iCount].vecItems[jCount].bInDetail = FALSE;
                        }

                        InvalidateRect(NULL);
                    }
                    if (m_nHoverIndex != m_vecTrashItems[iCount].vecItems[jCount].nItemId)
                    {
                        m_nHoverIndex = m_vecTrashItems[iCount].vecItems[jCount].nItemId;
                        InvalidateRect(NULL);
                    } 
                    goto Clear0;
                }
            }
        }
	}

    if (m_nHoverIndex != -1)
    {
        InvalidateRect(NULL);
    }
    m_nHoverIndex = -1;

Clear0:
	if (!bIn)
	{
		m_wndToolTip.Activate(FALSE);
        m_bToolTipActive = FALSE;
	}
    SetMsgHandled(FALSE);
}
Esempio n. 11
0
bool VortexSprite::hitPoint(sf::Vector2f point) {
	return hitPoint(point.x, point.y);
}
Esempio n. 12
0
BOOL BoundsTree::HitQuadTree(IPoint2 m, int &nindex, DWORD &findex, Point3 &p, Point3 &norm, Point3 &bary, float &finalZ, Matrix3 &toWorldTm)
{
//int nindex = 0;
Leaf *l = head;
BOOL hit = FALSE;
Point3 hitPoint(0.0f,0.0f,0.0f);
DWORD smgroup;

hitPoint.x = (float) m.x;
hitPoint.y = (float) m.y;
float z = 0.0f;
Point3 bry;
if (l == NULL) 
	{
	z = 0.0f;
	return FALSE;
	}
int ct = 0;
while ( (l!=NULL) && (l->IsBottom() == FALSE))
	{
	int id = l->InWhichQuad(hitPoint);
	l = l->GetQuad(id);
	ct++;
	}
if (l)
	{
	if (l->faceIndex.Count() == 0) 
		return FALSE;
	else
		{
		for (int i = 0; i < l->faceIndex.Count(); i++)
			{
			int faceIndex = l->faceIndex[i].faceIndex;
			int nodeIndex = l->faceIndex[i].nodeIndex;

			LightMesh *lmesh = meshList[nodeIndex];

			Point3 *tempVerts = lmesh->vertsViewSpace.Addr(0);
			Face *tempFaces = lmesh->faces.Addr(faceIndex);

			Box2D b = lmesh->boundingBoxList[faceIndex];
			if ( (hitPoint.x >= b.min.x) && (hitPoint.x <= b.max.x) &&
				 (hitPoint.y >= b.min.y) && (hitPoint.y <= b.max.y) )
				{
//now check bary coords
				Point3 a,b,c;
				a = tempVerts[tempFaces->v[0]];
				b = tempVerts[tempFaces->v[1]];
				c = tempVerts[tempFaces->v[2]];
				Point3 az,bz,cz,hitPointZ;
				az = a;
				bz = b;
				cz = c;
				az.z = 0.0f;
				bz.z = 0.0f;
				cz.z = 0.0f;
				hitPointZ = hitPoint;
				hitPointZ.z = 0.0f;
	
				Point3 bry;
				bry = BaryCoords(az, bz, cz, hitPointZ);
//if inside bary find the the z point			
				if (!( (bry.x<0.0f || bry.x>1.0f || bry.y<0.0f || bry.y>1.0f || bry.z<0.0f || bry.z>1.0f) ||
					(fabs(bry.x + bry.y + bry.z - 1.0f) > EPSILON) ))
					{
					float tz = a.z * bry.x + b.z * bry.y + c.z * bry.z; 
					if ( (tz > z ) || (hit == FALSE) )  
						{
						z = tz;
						findex = faceIndex;
						nindex = nodeIndex;
						bary = bry;
						finalZ = z;
						smgroup = tempFaces->getSmGroup();
						}
					hit = TRUE;
					}
				}
			}
		}	
	}
if (hit)
	{
	Point3 a,b,c;
	int ia,ib,ic;
	LightMesh *lmesh = meshList[nindex];
	Point3 *tempVerts = lmesh->vertsWorldSpace.Addr(0);
	Face *tempFaces = lmesh->faces.Addr(findex);

	ia = tempFaces->v[0];
	ib = tempFaces->v[1];
	ic = tempFaces->v[2];
	a = tempVerts[ia];
	b = tempVerts[ib];
	c = tempVerts[ic];

	ViewExp *vpt = GetCOREInterface()->GetActiveViewport();

	Ray worldRay;
//	vpt->GetAffineTM(tm);
	vpt->MapScreenToWorldRay((float) m.x, (float) m.y, worldRay);
	GetCOREInterface()->ReleaseViewport(vpt);

//intersect ray with the hit face

		// See if the ray intersects the plane (backfaced)
	norm = Normalize((b-a)^(c-b));

	float rn = DotProd(worldRay.dir,norm);
		
	// Use a point on the plane to find d
	float d = DotProd(a,norm);

	// Find the point on the ray that intersects the plane
	float ta = (d - DotProd(worldRay.p,norm)) / rn;


		// The point on the ray and in the plane.
	p = worldRay.p + ta*worldRay.dir;

		// Compute barycentric coords.
	bary = BaryCoords(a, b, c, p);

	finalZ  = ta;

//	p = a * bary.x +  b * bary.y +  c * bary.z;
	p = p * meshList[nindex]->toLocalSpace;

	norm = VectorTransform(meshList[nindex]->toLocalSpace,norm);
	toWorldTm = meshList[nindex]->toWorldSpace;

	


	}

return hit;

}
Esempio n. 13
0
 TEST(HitPointInterval, ShouldSetClosestAndFarthestHitPointWhenOnlyOneHitPointIsAdded) {
   HitPointInterval interval;
   HitPoint hitPoint(box, 5, Vector3d(), Vector3d());
   interval.add(hitPoint);
   ASSERT_TRUE(interval.min() == interval.max());
 }
Esempio n. 14
0
 TEST(HitPointInterval, ShouldReturnFarthestHitPoint) {
   HitPointInterval interval;
   HitPoint hitPoint(box, 5, Vector3d(), Vector3d());
   interval.add(hitPoint);
   ASSERT_TRUE(hitPoint == interval.max());
 }