示例#1
0
void VertexArray::SetTo2DButton(float x, float y, float w, float h, float sidewidth, bool flip)
{
	float vcorners[12*3];
	float uvs[8*3];
	int bfaces[6*3];

	//y1 = 1.0 - y1;
	//y2 = 1.0 - y2;

	Vec2 corner1;
	Vec2 corner2;
	Vec2 dim;
	dim.Set(w,h);
	Vec2 center;
	center.Set(x,y);
	corner1 = center - dim*0.5;
	corner2 = center + dim*0.5;

	float x1 = corner1[0];
	float y1 = corner1[1];
	float x2 = corner2[0];
	float y2 = corner2[1];

	if (flip)
	{
		float y3 = y1;
		y1 = y2;
		y2 = y3;
	}

	//left
	SetVertexData2DQuad(x1-sidewidth,y1,x1,y2, 0,0,0.5,1, vcorners, uvs, bfaces);

	//center
	SetVertexData2DQuad(x1,y1,x2,y2, 0.5,0,0.5,1, &(vcorners[12]), &(uvs[8]), &(bfaces[6]), 4);

	//right
	SetVertexData2DQuad(x2,y1,x2+sidewidth,y2, 0.5,0,1,1, &(vcorners[12*2]), &(uvs[8*2]), &(bfaces[6*2]), 8);

	SetFaces(bfaces, 6*3);
	SetVertices(vcorners, 12*3);
	SetTexCoordSets(1);
	SetTexCoords(0, uvs, 8*3);
}
示例#2
0
/*
=============
  CalculateRect
=============
*/
void RenderableQuad::CalculateRect( Vec2 &leftTop, Vec2 &rightBottom )
{
  Vec2 resSize = Vec2( this->size.x * this->scale.x, this->size.y * this->scale.y ) * 0.5f;
  leftTop.Set( this->position.x - resSize.x, this->position.y - resSize.y );
  rightBottom.Set( this->position.x + resSize.x, this->position.y + resSize.y );
}//CalculateRect
示例#3
0
void VertexArray::SetTo2DBox(float x, float y, float w, float h, float marginwidth, float marginheight, float clipx)
{
	const unsigned int quads = 9;
	float vcorners[12*quads];
	float uvs[8*quads];
	int bfaces[6*quads];

	//y1 = 1.0 - y1;
	//y2 = 1.0 - y2;

	Vec2 corner1;
	Vec2 corner2;
	Vec2 dim;
	dim.Set(w,h);
	Vec2 center;
	center.Set(x,y);
	corner1 = center - dim*0.5;
	corner2 = center + dim*0.5;
	Vec2 margin;
	margin.Set(marginwidth, marginheight);

	float lxmax = std::max((corner1-margin)[0],std::min(clipx,corner1[0]));
	float cxmax = std::max(corner1[0],std::min(clipx,corner2[0]));
	float rxmax = std::max(corner2[0],std::min(clipx,(corner2+margin)[0]));
	float lumax = (lxmax-(corner1-margin)[0])/(corner1[0]-(corner1-margin)[0])*0.5;
	float rumax = (rxmax-corner2[0])/((corner2+margin)[0]-corner2[0])*0.5+0.5;

	//upper left
	SetVertexData2DQuad((corner1-margin)[0],(corner1-margin)[1],lxmax,corner1[1],
			    0,0,lumax,0.5, vcorners,uvs,bfaces);

	//upper center
	SetVertexData2DQuad(corner1[0],(corner1-margin)[1],cxmax,corner1[1],
			     0.5,0,0.5,0.5,
			     &(vcorners[12*1]),&(uvs[8*1]),&(bfaces[6*1]),4*1);

	//upper right
	SetVertexData2DQuad(corner2[0],(corner1-margin)[1],rxmax,corner1[1],
			    0.5,0,rumax,0.5,
			    &(vcorners[12*2]),&(uvs[8*2]),&(bfaces[6*2]),4*2);

	//center left
	SetVertexData2DQuad((corner1-margin)[0],corner1[1],lxmax,corner2[1],
			    0,0.5,lumax,0.5,
			    &(vcorners[12*3]),&(uvs[8*3]),&(bfaces[6*3]),4*3);

	//center center
	SetVertexData2DQuad(corner1[0],corner1[1],cxmax,corner2[1],
			    0.5,0.5,0.5,0.5,
			    &(vcorners[12*4]),&(uvs[8*4]),&(bfaces[6*4]),4*4);

	//center right
	SetVertexData2DQuad(corner2[0],corner1[1],rxmax,corner2[1],
			    0.5,0.5,rumax,0.5,
			    &(vcorners[12*5]),&(uvs[8*5]),&(bfaces[6*5]),4*5);

	//lower left
	SetVertexData2DQuad((corner1-margin)[0],corner2[1],lxmax,(corner2+margin)[1],
			    0,0.5,lumax,1,
			    &(vcorners[12*6]),&(uvs[8*6]),&(bfaces[6*6]),4*6);

	//lower center
	SetVertexData2DQuad(corner1[0],corner2[1],cxmax,(corner2+margin)[1],
			    0.5,0.5,0.5,1,
			    &(vcorners[12*7]),&(uvs[8*7]),&(bfaces[6*7]),4*7);

	//lower right
	SetVertexData2DQuad(corner2[0],corner2[1],rxmax,(corner2+margin)[1],
			    0.5,0.5,rumax,1,
			    &(vcorners[12*8]),&(uvs[8*8]),&(bfaces[6*8]),4*8);

	SetFaces(bfaces, 6*quads);
	SetVertices(vcorners, 12*quads);
	SetTexCoordSets(1);
	SetTexCoords(0, uvs, 8*quads);
}
示例#4
0
/*
=============
  SetPointList
  Точки необходимо задавать обходя по часовой стрелке
=============
*/
void CollisionElementPolygon::SetPointList( const PointList &setPoints ) {
  if( setPoints.size() < 3 ) {
    __log.PrintInfo( Filelevel_ERROR, "CollisionElementPolygon::SetPointList => not enough points" );
    return;
  }
  this->pointsSource = setPoints;
  this->pointsResult.clear();
  this->pointsResult.resize( setPoints.size() + 1 );

  //copy src to result
  int num = 0;
  PointList::iterator iter, iterEnd = this->pointsSource.end();
  for( iter = this->pointsSource.begin(); iter != iterEnd; ++iter, ++num ) {
    this->pointsResult[ num ] = *iter;
  }
  this->pointsResult[ this->pointsResult.size() - 1 ] = this->pointsSource[ 0 ];

  Vec2 radiusVector( Vec2Null );
  Vec2 edge0, edge1, edge2;
  num = 0;
  iterEnd = this->pointsResult.end();
  for( iter = this->pointsResult.begin(); iter != iterEnd; ++iter, ++num ) {
    Point *point = &( *iter );
    radiusVector.Set( max( fabs( point->x ), radiusVector.x ), max( fabs( point->y ), radiusVector.y ) );
    if( num > 1 ) {
      //нормальзовать не нужно т.к. нужно не значение, а только знак
      edge0 = this->pointsResult[ num - 1 ] - this->pointsResult[ num - 2 ];
      edge1 = this->pointsResult[ num ] - this->pointsResult[ num - 2 ];
      edge1.Rotate90CW();
      float sign = edge0.Dot( edge1 );
      if( sign > 0 ) {
        __log.PrintInfo( Filelevel_ERROR, "CollisionElementPolygon::SetPointList => points[%d] is not clockwise", num );
        this->pointsResult.clear();
        this->pointsSource.clear();
        return;
      }
    }
  }//for
  this->_rect->radius2 = Square( radiusVector.Length() );

  //формирования списка разделающих осей
  Vec2 axis;
  Vec2 tmpVec2;
  iterEnd = this->pointsResult.end();
  iter = this->pointsResult.begin();
  num = 1;
  for( ++iter; iter != iterEnd; ++iter, ++num ) {
    tmpVec2 = this->pointsResult[ num ] - this->pointsResult[ num - 1 ];
    axis.Set( tmpVec2.x, tmpVec2.y );
    axis.Rotate90CW();
    if( axis.x < 0 ) {
      axis *= -1.0f;
    } else if( axis.y < 0.0f ) {
      axis *= -1.0f;
    }
    axis.Normalize();
    if( !this->_IsAxisExists( axis ) ) {
      this->axes.push_back( axis );
    }
  }//foreach pointsSource
}//SetPointList
示例#5
0
//Vec2 offset;//((float)(uWidth / 2), (float)(uHeight / 5));
void DrawJoint(Joint* joint)
{
    float factor = 10.0f;
    iS32 Point[2][2];
//iLog("Start DrawJoint ");
    switch ( demoIndex )
    {
    case 2:
        factor = 12.0f;
        break;
    case 6:
        factor = 15.0f;
        break;
    default:
        return;
    }

    Body* b1 = joint->body1;
    Body* b2 = joint->body2;

    R1.Mat22_1(b1->rotation);
    R2.Mat22_1(b2->rotation);

    x1 = b1->position;
    p1 = x1 + R1 * joint->localAnchor1;

    x2 = b2->position;
    p2 = x2 + R2 * joint->localAnchor2;
//#if 1

    iU16 *pScrBuffer;
    iU16 uWidth=240, uHeight=320;
	if( i51AdeMmiGetScreenScale ( &uWidth , &uHeight ) == 0 ) return;
    //GetFullScreenBuffer( &pScrBuffer, &uWidth, &uHeight );

    offset.Set((float)(uWidth / 2), (float)(uHeight / 5));

    x1 *= factor;
    p1 *= factor;
    x2 *= factor;
    p2 *= factor;

    x1 += offset;
    p1 += offset;
    x2 += offset;
    p2 += offset;

    x1.y = uHeight - x1.y;
    p1.y = uHeight - p1.y;
    x2.y = uHeight - x2.y;
    p2.y = uHeight - p2.y;


// 	GUI_BEGIN(pScrBuffer, uWidth, uHeight);
// 	DrawLine((int16)x1.x, (int16)x1.y, (int16)p1.x, (int16)p1.y, MEX_COLOR_RED);
// 	DrawLine((int16)x2.x, (int16)x2.y, (int16)p2.x, (int16)p2.y, MEX_COLOR_RED);
// 	GUI_END();
//#endif
	Point[0][0] = (iS32)x1.x;
	Point[0][1] = (iS32)x1.y;
	Point[1][0] = (iS32)p1.x;
	Point[1][1] = (iS32)p1.y;
	i51KitG2DrawLine(Point, 0XFF00);
	Point[0][0] = (iS32)x2.x;
	Point[0][1] = (iS32)x2.y;
	Point[1][0] = (iS32)p2.x;
	Point[1][1] = (iS32)p2.y;
	i51KitG2DrawLine(Point, 0XFF00);
//iLog("End DrawJoint ");
}
示例#6
0
void DrawBody(Body* body)
{
// 	uint16 *pScrBuffer;
// 	uint16 uWidth, uHeight;
// 	GetFullScreenBuffer( &pScrBuffer, &uWidth, &uHeight );
	iU16 *pScrBuffer;
	iU16 uWidth=0, uHeight=0;
	iS32 Point[2][2];
	if( i51AdeMmiGetScreenScale ( &uWidth , &uHeight ) == 0 ) return;

//	GetFullScreenBuffer( &pScrBuffer, &uWidth, &uHeight );

//iLog("Start DrawBody ");
    R.Mat22_1(body->rotation);
    x = body->position;
    h = 0.5f * body->width;

    offset.Set((float)(uWidth / 2), (float)(uHeight / 5));

    v1 = x + R * Vec2(-h.x, -h.y);
    v2 = x + R * Vec2( h.x, -h.y);
    v3 = x + R * Vec2( h.x,  h.y);
    v4 = x + R * Vec2(-h.x,  h.y);
//#if 1
    float factor = 10.0f;
    switch ( demoIndex )
    {
    case 1:
        factor = 30.0f;
        break;
    case 2:
        factor = 12.0f;
        break;
    case 5:
        factor = 15.0f;
        break;
    case 6:
        factor = 15.0f;
        break;
    case 9:
        factor = 6.0f;
        break;
    default:
        factor = 10.0f;
        break;
    }

    v1 *= factor;
    v2 *= factor;
    v3 *= factor;
    v4 *= factor;

    v1 += offset;
    v2 += offset;
    v3 += offset;
    v4 += offset;

    v1.y = uHeight - v1.y;
    v2.y = uHeight - v2.y;
    v3.y = uHeight - v3.y;
    v4.y = uHeight - v4.y;

    //log(MEX_LOG_APP0, "(%d, %d), (%d, %d)", (int16)v1.x, (int16)v1.y, (int16)v2.x, (int16)v2.y);
    //log(MEX_LOG_APP0, "(%d, %d), (%d, %d)", (int16)v2.x, (int16)v2.y, (int16)v3.x, (int16)v3.y);
    //log(MEX_LOG_APP0, "(%d, %d), (%d, %d)", (int16)v3.x, (int16)v3.y, (int16)v4.x, (int16)v4.y);
    //log(MEX_LOG_APP0, "(%d, %d), (%d, %d)", (int16)v4.x, (int16)v4.y, (int16)v1.x, (int16)v1.y);
// 
// 	GUI_BEGIN(pScrBuffer, uWidth, uHeight);
// 	DrawLine((int16)v1.x, (int16)v1.y, (int16)v2.x, (int16)v2.y, MEX_COLOR_WHITE);
// 	DrawLine((int16)v2.x, (int16)v2.y, (int16)v3.x, (int16)v3.y, MEX_COLOR_WHITE);
// 	DrawLine((int16)v3.x, (int16)v3.y, (int16)v4.x, (int16)v4.y, MEX_COLOR_WHITE);
// 	DrawLine((int16)v4.x, (int16)v4.y, (int16)v1.x, (int16)v1.y, MEX_COLOR_WHITE);
// 	GUI_END();
//	GUI_BEGIN(pScrBuffer, uWidth, uHeight);
//#endif
	Point[0][0] = (iS32)v1.x;
	Point[0][1] = (iS32)v1.y;
	Point[1][0] = (iS32)v2.x;
	Point[1][1] = (iS32)v2.y;
	i51KitG2DrawLine(Point, 0XFF00);
	Point[0][0] = (iS32)v2.x;
	Point[0][1] = (iS32)v2.y;
	Point[1][0] = (iS32)v3.x;
	Point[1][1] = (iS32)v3.y;
	i51KitG2DrawLine(Point, 0XFF00);
	Point[0][0] = (iS32)v3.x;
	Point[0][1] = (iS32)v3.y;
	Point[1][0] = (iS32)v4.x;
	Point[1][1] = (iS32)v4.y;
	i51KitG2DrawLine(Point, 0XFF00);
	Point[0][0] = (iS32)v4.x;
	Point[0][1] = (iS32)v4.y;
	Point[1][0] = (iS32)v1.x;
	Point[1][1] = (iS32)v1.y;
	i51KitG2DrawLine(Point, 0XFF00);
//iLog("End DrawBody ");
}