示例#1
0
//-----------------------------------------------------------------------------
// Purpose: Label paint functions - take into account current highligh status
//-----------------------------------------------------------------------------
void CLabelHeader::paint()
{
	Color oldFg;
	getFgColor(oldFg);

	if (gViewPort->GetScoreBoard()->m_iHighlightRow == _row)
	{
		setFgColor(255, 255, 255, 0);
	}

	// draw text
	int x, y, iwide, itall;
	getTextSize(iwide, itall);
	calcAlignment(iwide, itall, x, y);
	_dualImage->setPos(x, y);

	int x1, y1;
	_dualImage->GetImage(1)->getPos(x1, y1);
	_dualImage->GetImage(1)->setPos(_gap, y1);

	_dualImage->doPaint(this);

	// get size of the panel and the image
	if (_image)
	{
		Color imgColor;
		getFgColor( imgColor );
		if( _useFgColorAsImageColor )
		{
			_image->setColor( imgColor );
		}

		_image->getSize(iwide, itall);
		calcAlignment(iwide, itall, x, y);
		_image->setPos(x, y);
		_image->doPaint(this);
	}

	setFgColor(oldFg[0], oldFg[1], oldFg[2], oldFg[3]);
}
void NGLScene::updateMember(Member &io_toUpdate)
{
  ngl::Vec3 alignment = calcAlignment(io_toUpdate) * 10;
  ngl::Vec3 cohesion = /*followSphere->getPosition() - */calcCohesion(io_toUpdate) *10;
  ngl::Vec3 separation = calcSeparation(io_toUpdate);
  ngl::Vec3 newVelocity = (followSphere->getPosition()) -
                          (io_toUpdate.getPosition() +
                          (ngl::Vec3(alignment + cohesion + separation)));
  for(unsigned int i = 0; i<ShapeStore.ShapeList.size(); i++)
  {
    float shapeDist = calcDistance(getMemberPosition(ShapeStore.ShapeList[i]), io_toUpdate.getPosition());

    if(abs(shapeDist) < 8.0f)
    {
      newVelocity += (io_toUpdate.getPosition() - getMemberPosition(ShapeStore.ShapeList[i])) * 100;
    }
  }

  if(newVelocity.lengthSquared() != 0.0f)
  {
    newVelocity.normalize();
  }
  //std::cout<<"x = "<<newVelocity.m_x<<" y = "<<newVelocity.m_y<<" z = "<<newVelocity.m_z<<"\n";

//  if(newVelocity.m_x < 0.0f)
//  {
//    newVelocity.m_x = -newVelocity.m_x;
//  }
//  if(newVelocity.m_y < 0.0f)
//  {
//    newVelocity.m_y = -newVelocity.m_y;
//  }
//  if(newVelocity.m_z < 0.0f)
//  {
//    newVelocity.m_z = -newVelocity.m_z;
//  }

  float dist = ngl::Vec3(followSphere->getPosition() - io_toUpdate.getPosition()).length();

  if (dist > 15.0f)
  {
    io_toUpdate.setForwardVector(followSphere->getPosition());
    io_toUpdate.calcSideVector();
  }
  else
  {
    io_toUpdate.setSideVector(followSphere->getPosition());
    io_toUpdate.calcForwardVector();
  }

  io_toUpdate.getForwardVector().normalize();
  if(io_toUpdate.getForwardVector().m_x <0.0f)
  {
    io_toUpdate.setForwardVector(ngl::Vec3(-io_toUpdate.getForwardVector().m_x,
                                           io_toUpdate.getForwardVector().m_y,
                                           io_toUpdate.getForwardVector().m_z));
  }

  if(io_toUpdate.getForwardVector().m_y <0.0f)
  {
    io_toUpdate.setForwardVector(ngl::Vec3(io_toUpdate.getForwardVector().m_x,
                                           -io_toUpdate.getForwardVector().m_y,
                                           io_toUpdate.getForwardVector().m_z));
  }

  if(io_toUpdate.getForwardVector().m_z <0.0f)
  {
    io_toUpdate.setForwardVector(ngl::Vec3(io_toUpdate.getForwardVector().m_x,
                                           io_toUpdate.getForwardVector().m_y,
                                           -io_toUpdate.getForwardVector().m_z));
  }


  io_toUpdate.setVelocity(newVelocity * 0.0001f * (io_toUpdate.getForwardVector() + io_toUpdate.getPosition()) , false);

  if(io_toUpdate.getVelocity().m_x > 0.5f)
  {
    io_toUpdate.setVelocity(ngl::Vec3(0.5f,
                                      io_toUpdate.getVelocity().m_y,
                                      io_toUpdate.getVelocity().m_z),
                                      true);
  }

  else if(io_toUpdate.getVelocity().m_x < -0.5f)
  {
    io_toUpdate.setVelocity(ngl::Vec3(-0.5f,
                                      io_toUpdate.getVelocity().m_y,
                                      io_toUpdate.getVelocity().m_z),
                                      true);
  }

  if(io_toUpdate.getVelocity().m_y > 0.5f)
  {
    io_toUpdate.setVelocity(ngl::Vec3(io_toUpdate.getVelocity().m_x,
                                      0.5f,
                                      io_toUpdate.getVelocity().m_z),
                                      true);
  }

  else if(io_toUpdate.getVelocity().m_y < -0.5f)
  {
    io_toUpdate.setVelocity(ngl::Vec3(io_toUpdate.getVelocity().m_x,
                                      -0.5f,
                                      io_toUpdate.getVelocity().m_z),
                                      true);
  }

  if(io_toUpdate.getVelocity().m_z > 0.5f)
  {
    io_toUpdate.setVelocity(ngl::Vec3(io_toUpdate.getVelocity().m_x,
                                      io_toUpdate.getVelocity().m_y,
                                      0.5f),
                                      true);
  }

  else if(io_toUpdate.getVelocity().m_z < -0.5f)
  {
    io_toUpdate.setVelocity(ngl::Vec3(io_toUpdate.getVelocity().m_x,
                                      io_toUpdate.getVelocity().m_y,
                                      -0.5f),
                                      true);
  }

  //io_toUpdate.setVelocity(newVelocity * 0.0001f * io_toUpdate.getForwardVector() , false);

  io_toUpdate.setPosition(io_toUpdate.getVelocity(), false);
}