Exemple #1
0
void MxCore::orthonormalize()
{
    const osg::Vec3d c = getCross();
    _viewUp = c ^ _viewDir;
    _viewDir.normalize();
    _viewUp.normalize();
}
Exemple #2
0
//射线与线段的交点
bool SightLightScene::getIntersection(const Line& ray,const Line& segment,cocos2d::Point &point,float& distance)
{
    Vec2 v1(ray.p2 - ray.p1);
    Vec2 v2(segment.p2 - segment.p1);
    float cross = getCross(v1, v2);
    if(cross == 0) {
        return false;
    }
    
    Vec2 u(ray.p1 - segment.p1);
    float t1 = getCross(v2,u) / cross;
    float t2 = getCross(v1, u) / cross;
    if (t1 < 0 || t2 < 0 || t2 > 1) {
        return  false;
    }
    point = v1 * t1 + ray.p1;
    distance = t1;
    return true;
}
Exemple #3
0
int main()	{
	int T, i, x1, y1, x2, y2, r1, r2;

	scanf(" %d", &T);
	for(i = 0; i < T; i++)	{
		scanf(" %d %d %d %d %d %d", &x1, &y1, &r1, &x2, &y2, &r2);
		printf("%d\n", getCross(x1, y1, x2, y2, r1, r2));
	}

	return 0;
}
Exemple #4
0
void MxCore::level()
{
    _viewUp = _initialUp;

    // Check for vurrent view dir coincident with initial up vector. If so,
    // we can't preserve the current view dir and need to set it to the
    // initial view dir.
    if( osg::absolute< double >( _initialUp * _viewDir ) > 0.99 )
        _viewDir = _initialDir;
    else
        _viewDir = _viewUp ^ getCross();
    orthonormalize();
}
Exemple #5
0
osg::Matrixd MxCore::getOrientationMatrix() const
{
    const osg::Vec3d c = getCross();
    const osg::Vec3d& u = _viewUp;
    const osg::Vec3d& d = _viewDir;

    const osg::Matrixd m = osg::Matrixd(
        c[0], c[1], c[2], 0.0,
        u[0], u[1], u[2], 0.0,
        -d[0], -d[1], -d[2], 0.0,
        0.0, 0.0, 0.0, 1.0 );
    return( m );
}
Exemple #6
0
osg::Matrixd MxCore::getMatrix() const
{
    const osg::Vec3d c = getCross();
    const osg::Vec3d& u = _viewUp;
    const osg::Vec3d& d = _viewDir;
    const osg::Vec3d p = _position;

    const osg::Matrixd m = osg::Matrixd(
        c[0], c[1], c[2], 0.0,
        u[0], u[1], u[2], 0.0,
        -d[0], -d[1], -d[2], 0.0,
        p[0], p[1], p[2], 1.0 );
    return( m );
}
Exemple #7
0
void MxCore::moveConstrained( const osg::Vec3d& delta )
{
    const osg::Vec3d c = getCross();
    const osg::Vec3d& u = _initialUp;
    const osg::Vec3d back = c ^ u;
    const osg::Matrixd orient(
        c[ 0 ], c[ 1 ], c[ 2 ], 0.,
        u[ 0 ], u[ 1 ], u[ 2 ], 0.,
        back[ 0 ], back[ 1 ], back[ 2 ], 0.,
        0., 0., 0., 1. );

    const osg::Vec3d scaledDelta( delta[0] * _moveScale[0],
        delta[1] * _moveScale[1], delta[2] * _moveScale[2] );
    _position += ( scaledDelta * orient );
    _orbitCenter += ( scaledDelta * orient );
}
Exemple #8
0
osg::Matrixd MxCore::getInverseMatrix() const
{
    const osg::Vec3d c = getCross();
    const osg::Vec3d& u = _viewUp;
    const osg::Vec3d& d = _viewDir;

    const osg::Matrixd m = osg::Matrixd(
        c[0], u[0], -d[0], 0.0,
        c[1], u[1], -d[1], 0.0,
        c[2], u[2], -d[2], 0.0,
        0.0, 0.0, 0.0, 1.0 );
    return( osg::Matrixd::translate( -_position ) * m );

    // Old code, for a sanity check.
    //osg::Matrixd m;
    //m.invert( getMatrix() );
    //return( m );
}
Exemple #9
0
void GLvlPlaneCam::generate()
{
	if(showCross)
	{
		SGLVektor Vert[2],Horiz[2];
		getCross(Horiz,Vert);
		glBegin(GL_LINES);
			Vert[1].DrawPureVertex();Vert[0].DrawPureVertex();
			Horiz[1].DrawPureVertex();Horiz[0].DrawPureVertex();
		glEnd();
	}

	recalcEcken();
	myPlane->resetTexKoord();

	// prevent nvidia from optimizing out the setting
	// 	glLineWidth(1); glColor3f(0,0,0);

	glLineWidth(2);
	glBegin(GL_LINES);
		glColor3f(1,0,0);
		Ecken[0]->DrawPureVertex();
		Ecken[1]->DrawPureVertex();

		glColor3f(0,1,0);
		Ecken[1]->DrawPureVertex();
		Ecken[2]->DrawPureVertex();

		glColor3f(0,0,0);
		Ecken[2]->DrawPureVertex();
		Ecken[3]->DrawPureVertex();

		glColor3f(0,0,1);
		Ecken[3]->DrawPureVertex();
		Ecken[0]->DrawPureVertex();
	glEnd();

	glLineWidth(1);
}
void FirstReflection::buildingCross(float shootingStartX,float shootingStartY,float shootingStartZ,float shootingDirectionX,float shootingDirectionY,float shootingDirectionZ,vector<BuildingPoint> BPoint,float buildingHeight)
{
	line line1;
	line line2;
	TwoDimPoint CointP;
	TwoDimPoint vertex;

	int sideFlag=0;
	//int roofFlag;
	float X,Y,Z;
	float x,y,z;

	for(int k=0;k<BPoint.size();k++)
	{
		TwoDimPoint temp;
		temp.x=BPoint[k].getPx();
		temp.y=BPoint[k].getPy();
		polyPoint.push_back(temp);

	//polyPoint[k].x=BPoint[k].px;
	//polyPoint[k].y=BPoint[k].py;
	}
	line1.point1.x = shootingStartX;
	line1.point1.y = shootingStartY;
	line1.point2.x = shootingStartX + shootingDirectionX;
	line1.point2.y = shootingStartY + shootingDirectionY;

	//float buildingHeight=15;
/*
	printf("请输入建筑物高度:");                      //这里应该调用建筑物高度的vector
	scanf_s("%f", &h);
*/

	//求射线与建筑物侧面的交点
	refPolyPoint[0].x = 0;
	refPolyPoint[0].y = 0;
	refPolyPoint[1].x = 0;
	refPolyPoint[1].y = 0;
	float little = 9999999999;
	//因为给的点的向量中第一个点和最后一个点是重复的
	for (int i = 0; i < polyPoint.size()-1; i++)
	{
		if (i != polyPoint.size() - 2)
		{
			line2.point1.x = polyPoint[i].x;
			line2.point1.y = polyPoint[i].y;
			line2.point2.x = polyPoint[i + 1].x;
			line2.point2.y = polyPoint[i + 1].y;
		}
		else
		{
			line2.point1.x = polyPoint[i].x;
			line2.point1.y = polyPoint[i].y;
			line2.point2.x = polyPoint[0].x;
			line2.point2.y = polyPoint[0].y;
		}
		CointP = getCross(line1, line2);

			if (min(line2.point1.x, line2.point2.x) <= CointP.x && CointP.x <= max(line2.point1.x, line2.point2.x))
			{

				float distant;
				
				z = shootingStartZ + shootingDirectionZ / shootingDirectionX *(CointP.x - shootingStartX);
				if (z < buildingHeight)
				{
					sideFlag=1;
					distant = sqrt(pow(CointP.x - line1.point1.x, 2) + pow(CointP.y - line1.point1.y, 2) + pow(z - shootingStartZ, 2));
					if (distant <= little)
					{
						little = distant;
						X = CointP.x;
						Y = CointP.y;
						Z = z;

						refPolyPoint[0].x = line2.point1.x;
						refPolyPoint[0].y = line2.point1.y;
						refPolyPoint[1].x = line2.point2.x;
						refPolyPoint[1].y = line2.point2.y;
					}
				}
			}
		
	}

	//求射线与建筑物顶面的交点
	if (shootingDirectionZ != 0)
	{
		z = buildingHeight;
		float t = (z - shootingStartZ) / shootingDirectionZ;
		x = shootingStartX + shootingDirectionX*t;
		y = shootingStartY + shootingDirectionY*t;
		vertex.x = x;
		vertex.y = y;

		if (vertex_polygon(vertex) == 1)
		{
			//cout<<"射线与建筑物顶面交点为:"<< x<<'\t'<< y<<'\t'<< z<<endl;
			roofFlag=1;
			
		}

		else
		{
			//cout<<"射线与建筑物侧顶面无交点!"<<'\n';
			//sideFlag = 0;
			roofFlag=0;
		}
	}
	else
	{
		//cout<<"射线与建筑物顶面无交点!"<<'\n';
		//sideFlag = 0;
		roofFlag=0;
	}
	
	//综合侧面和顶面,判断射线与建筑物是否相交,若相交给出交点。同时给出标志位的值。

	if (sideFlag == 1 && roofFlag == 1)
	{
		float L1 = sqrt(pow((X - shootingStartX), 2) + pow((Y - shootingStartY), 2) + pow((Z - shootingStartZ), 2));
		float L2 = sqrt(pow((x - shootingStartX), 2) + pow((y - shootingStartY), 2) + pow((z - shootingStartZ), 2));
		if (L1 < L2)
		{
			crossX = X;
			crossY = Y;
			crossZ = Z;
			//cout<<"射线与建筑物的交点为:"<< crossX<<'\t'<< crossY<<'\t'<< crossZ<<endl;
			//cout<<refPolyPoint[0].x<<'\t'<<refPolyPoint[0].y<<'\t'<<refPolyPoint[1].x<<'\t'<<refPolyPoint[1].y<<endl;
			roofFlag=0;
			buildingCrossFlag=1;
		}
		else
		{
			crossX = x;
			crossY = y;
			crossZ = z;
			//cout<<"射线与建筑物的交点为:"<< crossX<<'\t'<< crossY<<'\t'<< crossZ<<endl;
			roofFlag=1;
			sideFlag=0;
			buildingCrossFlag=1;
		}
	}
	else if (sideFlag == 1 && roofFlag == 0)
	{
		crossX = X;
		crossY = Y;
		crossZ = Z;
		//cout<<"射线与建筑物的交点为:"<< crossX<<'\t'<< crossY<<'\t'<< crossZ<<endl;
		//cout<<refPolyPoint[0].x<<refPolyPoint[0].y<<refPolyPoint[1].x<<refPolyPoint[1].y<<endl;
		buildingCrossFlag=1;
	}

	else if (sideFlag == 0 && roofFlag == 1)
	{
		crossX = x;
		crossY = y;
		crossZ = z;
	//	cout<<"射线与建筑物的交点为:"<< crossX<<'\t'<< crossY<<'\t'<< crossZ<<endl;
		buildingCrossFlag=1;
	}
	else 
		{
	 		//cout<<"射线与建筑物无交点!"<<'\n';
	        buildingCrossFlag=0;
	    }

}
Exemple #11
0
	Vector3 getNormal(Point3 a, Point3 b, Point3 c) {  
		Vector3 u = a-b, v = b-c;
		Vector3 k = getCross(u, v);
		return k / getLength(k);
	}