/**
 * @brief CoordinateTransform::init_clkwise_mat
    根据顺时针航向角求转换矩阵
* @param heading_angle
 * @return
 */
cv::Mat CoordinateTransform::init_clkwise_mat(double heading_angle){

    clkwise_mat_ = cv::Mat::zeros(2,2,CV_64FC1);
    clkwise_mat_.at<double>(0,0) = cos(AngleToRadian(heading_angle));
    clkwise_mat_.at<double>(0,1) = sin(AngleToRadian(heading_angle));
    clkwise_mat_.at<double>(1,0) = -sin(AngleToRadian(heading_angle));
    clkwise_mat_.at<double>(1,1) = cos(AngleToRadian(heading_angle));
    return clkwise_mat_;
}
Ejemplo n.º 2
0
CPoint CCoordinate::GetRotatedPoint(const CPoint& ptOrg, int distance, int angle)
{
	CPoint ptRtd;
	double sina = sin(AngleToRadian(angle));
	double cosa = cos(AngleToRadian(angle)); 
	double xx = distance * cosa;
	double yy = distance * sina;
	ptRtd.x = ptOrg.x + static_cast<int>(xx);
	ptRtd.y = ptOrg.y + static_cast<int>(yy);
	return ptRtd;
}
Ejemplo n.º 3
0
bool W_Cannon::Fire(int mnplt)
{
	//应该发送一个事件给Battlefield,让其生成一个炮弹
	//低级一点的就是用传入一个指向Battlefield的指针来操作(这样总觉得Robot类与Battlefield类紧耦合了又)
	if(General_Fire(mnplt))
	{
		double p=inaccuracy*(Random0_1()-0.5);//偏移角度
		//double r=AnglePlus(AnglePlus(rotation,engineRotation),p);//角度
		double r=AnglePlus(rotation,p);
		double a=AngleToRadian(r);//弧度


		bullettypename bt = (bullettypename)type;
		//bullettypename bt = BT_Cannonball;
		//if(type == WT_Apollo)
		//{
		//	bt = BT_ApolloBall;
		//}


		pDispatcher->DispatchEvent(ID,pBattlefield->GetID(),
			Add_Bullet,
			new B_Cannonball(circle.r*cos(a)+circle.x,circle.r*sin(a)+circle.y,r,pRobot->GetBattlefieldID(),bt)  );
		
		pRobot->GetAchievementData().Add_Fire();

		return true;
	}
	return false;
}
Ejemplo n.º 4
0
int DirectXDraw9::DrawRegularPolygon( double cx, double cy, unsigned int n, int drawnum, double r, double rad, unsigned long color )
{
	double arad;
	//  CreatePolygon( pvmax-3, n + 1, D3DPT_TRIANGLEFAN );
	//  CreatePolygon( pvmax, n, D3DPT_TRIANGLEFAN );
	unsigned int i;
	//  drawnum;

	if ( rpv && rpvmax < n + 2 )
	{
		free( rpv );
		rpv = NULL;
	}
	if ( rpv == NULL )
	{
		rpvmax = n + 2;
		rpv = ( struct CUSTOMVERTEX * )calloc( rpvmax, sizeof( struct CUSTOMVERTEX ) );
	}
	// 中央座標
	//  SetPolygonVertex( pvmax-3, cx, cy, 0.5, color );
	rpv[ 0 ].x = (float)cx;
	rpv[ 0 ].y = (float)cy;
	rpv[ 0 ].z = 0.5f;
	rpv[ 0 ].color = color;
#ifdef USERHW
	rpv[ 0 ].rhw = 1.0f;
#endif
	rpv[ 0 ].u = 0.0f;
	rpv[ 0 ].v = 0.0f;

	arad = AngleToRadian( 360.0 / (double)n );

	for ( i = 0; i <= n; ++i )
	{
		//SetPolygonVertex( pvmax, cx + cos( arad * n ) * r, cy + sin( arad * n ) * r, 0.5, color );
		rpv[ i + 1 ].x = (float)( cx + cos( rad + arad * i ) * r );
		rpv[ i + 1 ].y = (float)( cy + sin( rad + arad * i ) * r );
		rpv[ i + 1 ].z = 0.5f;
		rpv[ i + 1 ].color = color;
#ifdef USERHW
		rpv[ i + 1 ].rhw = 1.0f;
#endif
		rpv[ i + 1 ].u = 0.0f;
		rpv[ i + 1 ].v = 0.0f;
	}

	//  return DrawPolygonVertex( pvmax );
	D3DDev->SetTexture( 0, NULL );
	D3DDev->SetFVF( MIKAN_CUSTOMVERTEX_2D/*D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1*/ );
	if ( FAILED( D3DDev->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, drawnum, rpv, sizeof( CUSTOMVERTEX ) ) ) )
	{
		return -1;
	}

	//DX_FREE( cv );
	return 0;
}
Ejemplo n.º 5
0
	void Clipping(const VertexBuffer& vertexBuffer, const Camera& camera,  OUTPUT VertexBuffer& output)
	{
		std::vector<VertexList*>::const_iterator bufferIt = vertexBuffer.lists.begin();
		std::vector<VertexList*>::const_iterator bufferItEnd = vertexBuffer.lists.end();
		for(; bufferIt != bufferItEnd; bufferIt++) {
			const VertexList& vertexList = **bufferIt;

			bool isInFrustum = false;
			std::vector<Vertex>::const_iterator it = vertexList.vertices.begin();
			std::vector<Vertex>::const_iterator itEnd = vertexList.vertices.end();
			for(; it != itEnd; it++) {
				const Vertex& vertex = *it;

				float xTest = camera.GetAspectRatio()*vertex.xyz.z;

				float halfVFov = camera.GetFov() / 2;
				float tanHalfvFov = tan(AngleToRadian(halfVFov));
				float yTest = tanHalfvFov*vertex.xyz.z;

				if(	vertex.xyz.x > -xTest && vertex.xyz.x < xTest &&
					vertex.xyz.y > -yTest && vertex.xyz.y < yTest &&
					vertex.xyz.z > camera.GetNearClipZ() && vertex.xyz.z < camera.GetFarClipZ()
				   ) {
					isInFrustum = true;
					break;
				}
			}


			if(isInFrustum) {
				VertexList* newVertices = new VertexList;

				std::vector<Vertex>::const_iterator it = vertexList.vertices.begin();
				std::vector<Vertex>::const_iterator itEnd = vertexList.vertices.end();
				for(; it != itEnd; it++) {
					const Vertex& vertex = *it;
					newVertices->vertices.push_back(vertex);
				}

				std::vector<int>::const_iterator indexIt = vertexList.indices.begin();
				std::vector<int>::const_iterator indexItEnd = vertexList.indices.end();
				for(; indexIt != indexItEnd; indexIt++) {
					newVertices->indices.push_back(*indexIt);
				}

				newVertices->pos = vertexList.pos;

				output.lists.push_back(newVertices);
			}

		}
	}
Ejemplo n.º 6
0
/*!
@brief テクスチャを回転描画する(角度)
@par   関数説明
テクスチャを描画する。始点は中央。
@param txnum テクスチャ番号。
@param dx 描画x座標。
@param dy 描画y座標。
@param rx 読み込みx座標。
@param ry 読み込みy座標。
@param w 読み込み幅。
@param h 読み込み高さ。
@param angle 角度。時計回り。
@return 0=成功。
@return 1=テクスチャ番号が不正。
@return 2=テクスチャがない。
@return 3=テクスチャセットに失敗。
@return 4=テクスチャ設定に失敗。
@return 5=頂点ストリームの設定に失敗。
@return 6=レンダリングに失敗。
*/
int DirectXDraw9::DrawTextureRotationAngleC( unsigned int txnum, int dx, int dy, int rx, int ry, int w, int h, double angle, int flag )
{
	if ( txnum >= texmax )//if( txnum >= texmax )
	{
		//テクスチャ番号が不正
		return 1;
	}

	_SetUV( (float)dxtex[ txnum ].width, (float)dxtex[ txnum ].height, rx, ry, w, h, flag );
	_SetColor( dxtex[ txnum ].vcolor );
	_DrawTextureRotationC( (float)dx, (float)dy, (float)w, (float)h, AngleToRadian( angle ) );
	return EndDrawTexture( dxtex[ txnum ].tex );
}
Ejemplo n.º 7
0
bool E_AFV::Run(int mnplt)
{
	//9-6 这里现在似乎没有速度上限?

	//装甲车(AFV)
	//最正常的游戏中的vehicle, vr正比于当前速度
	//acceleration为加速比例,(0,1)
	//m>0加速,<=0刹车
	double speed=sqrt(vx*vx+vy*vy);
	double tempr=AngleToRadian(rotation);
	if(mnplt>0)
	{
		speed*=(acceleration+1);

		if(speed>=maxSpeed)
		{
			speed=maxSpeed;
		}
		else if(speed<0.1)
		{
			speed=0.1;
		}

		vx=speed*cos(tempr);
		vy=speed*sin(tempr);



		return true;
		//pDispatcher->DispatchEvent(GetID(),pRecordManager->GetID(),R_Run,//myid)
	}
	else
	{
		//暂未考虑friction,后期版本可考虑地形差异(沙地,柏油,冰面等)
		speed*=(1-acceleration);

		if(speed<=0.1)
		{
			speed=0;
		}

		vx=speed*cos(tempr);
		vy=speed*sin(tempr);

		return false;
	}
}
Ejemplo n.º 8
0
//テクスチャを回転拡大描画する
int DirectXDraw9::DrawTextureRotateScaleAngleC( unsigned int txnum, int dx, int dy, int rx, int ry, int w, int h, int sw, int sh, double angle, int flag )
{
	if ( txnum >= texmax )
	{
		//テクスチャ番号が不正
		return 1;
	}

	_SetUV( (float)dxtex[ txnum ].width, (float)dxtex[ txnum ].height, rx, ry, w, h, flag );
	_SetColor( dxtex[ txnum ].vcolor );
	_DrawTextureRotateScale( (float)( sw * 0.5 ), (float)( sh * 0.5 ), (float)dx, (float)dy, AngleToRadian( angle ), (float)sw, (float)sh );
	return EndDrawTexture( dxtex[ txnum ].tex );
}