Exemple #1
0
core::matrix4 CGUIPlot::buildProjectionMatrixOrthoLH( f32 left, f32 right, f32 bottom, f32 top, f32 zNear, f32 zFar )
{
	core::matrix4 M;
	_IRR_DEBUG_BREAK_IF( core::equals(left,right) ); //divide by zero
	_IRR_DEBUG_BREAK_IF( core::equals(top,bottom) ); //divide by zero
	_IRR_DEBUG_BREAK_IF( core::equals(zNear,zFar) ); //divide by zero

	//	2/(r-l)      0            0           0
	//	0            2/(t-b)      0           0
	//	0            0            1/(zf-zn)   0
	//	(l+r)/(l-r)  (t+b)/(b-t)  zn/(zn-zf)  1

	M[0] = 2.f/(left-right);
	M[1] = 0.f;
	M[2] = 0.f;
	M[3] = 0.f;

	M[4] = 0.f;
	M[5] = 2.f/(top-bottom);
	M[6] = 0.f;
	M[7] = 0.f;

	M[8] = 0.f;
	M[9] = 0.f;
	M[10] = 1.f/(zFar-zNear);
	M[11] = 0.f;

	M[12] = (left+right)/(left-right);
	M[13] = (top+bottom)/(bottom-top);
	M[14] = zNear/(zNear-zFar);
	M[15] = 1.f;

	return M;
}
//------------------------------------------------------------------------------
//! zeroForces
//! Zero all forces
void CBulletObjectAnimator::zeroForces() const
{
  _IRR_DEBUG_BREAK_IF(rigidBody == NULL);

  rigidBody->setLinearVelocity(btVector3(0,0,0));
  rigidBody->setAngularVelocity(btVector3(0,0,0));
}
void CCursorController::setActiveCursor(u32 index)
{
   _IRR_DEBUG_BREAK_IF(index>used); // access violation

   m_pMouseCursor = m_aMouseCursors[index].tex;
   topleft = m_aMouseCursors[index].topleft;
}
void CCursorController::render()
{
   updateMousePos();

   if(isVisible() && used)
   {
      _IRR_DEBUG_BREAK_IF(!m_pMouseCursor); // There isn't any cursor texture loaded
      if(m_pMouseCursor)
      {
         videoDriver->draw2DImage(m_pMouseCursor,
            topleft ? position2di(m_MousePos.X,m_MousePos.Y) : position2di(m_MousePos.X - m_pMouseCursor->getSize().Width/2+1,
            m_MousePos.Y - m_pMouseCursor->getSize().Height/2+2),
            rect<s32>(position2di(0,0),m_pMouseCursor->getSize()),
            0, SColor(140,255,255,255), true);
      }
   }

   if(isOSCursorVisible())
   {
      irrCursorControl->setVisible(true);
//       irrCursorControl->setPosition(irrCursorControl->getPosition());
   }
   else
   {
      irrCursorControl->setVisible(false);
//       irrCursorControl->setPosition(irrCursorControl->getPosition());
   }
}
//------------------------------------------------------------------------------
//! setRotation
//! Set animator rotation
core::vector3df CBulletObjectAnimator::getPosition() const
{
  _IRR_DEBUG_BREAK_IF(rigidBody == NULL);

  btVector3 p = rigidBody->getCenterOfMassPosition();
  return core::vector3df(p.getX(), p.getY(), p.getZ());
}
void CCursorController::removeCursor(u32 index)
{
   _IRR_DEBUG_BREAK_IF(index>used); // access violation

   videoDriver->removeTexture(m_aMouseCursors[index].tex);
   m_aMouseCursors.erase(index);
   used--;
}
//------------------------------------------------------------------------------
//! getLinearVelocity
//! Get animator linear vel
core::vector3df CBulletObjectAnimator::getLinearVelocity() const
{	
  _IRR_DEBUG_BREAK_IF(rigidBody == NULL);

  if (physicsParams.mass == 0.0f) 
    return core::vector3df(0,0,0);
  btVector3 btV = rigidBody->getLinearVelocity();
  return core::vector3df(btV.getX(), btV.getY(), btV.getZ());
}
//------------------------------------------------------------------------------
//! setPosition
//! Set animator position
void CBulletObjectAnimator::setPosition(const core::vector3df& v) const
{
  _IRR_DEBUG_BREAK_IF(rigidBody == NULL);

  btTransform t = rigidBody->getWorldTransform();
  btVector3 btv(v.X, v.Y, v.Z);
  t.setOrigin(btv);
  rigidBody->setWorldTransform(t);
}
//------------------------------------------------------------------------------
//! applyForce
//! Apply force to object
void CBulletObjectAnimator::applyForce(const core::vector3df& force, 
  const core::vector3df& rel_pos/* = core::vector3df(0,0,0)*/) const
{
  _IRR_DEBUG_BREAK_IF(rigidBody == NULL);

  rigidBody->applyForce(btVector3(force.X, force.Y, force.Z), 
    btVector3(rel_pos.X, rel_pos.Y, rel_pos.Z));
  rigidBody->activate();
}
//------------------------------------------------------------------------------
//! setRotation
//! Set animator rotation (v measured in radians)
void CBulletObjectAnimator::setRotation(const core::vector3df& v) const
{
  _IRR_DEBUG_BREAK_IF(rigidBody == NULL);

  btTransform t = rigidBody->getWorldTransform();
  btQuaternion btq;
  EulerXYZToQuaternion(v, btq);
  t.setRotation(btq);
  rigidBody->setWorldTransform(t);
}
//------------------------------------------------------------------------------
//! setLinearVelocity
//! Set animator linear vel
void CBulletObjectAnimator::setAngularVelocity(const core::vector3df & vel) const
{	
  _IRR_DEBUG_BREAK_IF(rigidBody == NULL);

  //bullet hangs if attempt to set lin. or ang. velocity on static object
  if (physicsParams.mass != 0.0f) 
  {
    rigidBody->setAngularVelocity(btVector3(vel.X, vel.Y, vel.Z));
  }
}
//------------------------------------------------------------------------------
//! getRotation
//! Get animator rotation
core::vector3df CBulletObjectAnimator::getRotation() const
{
  _IRR_DEBUG_BREAK_IF(rigidBody == NULL);

  core::vector3df rot;
  btQuaternion btq=rigidBody->getOrientation();
  QuaternionToEulerXYZ(btq, rot);
  //rot *= (f32)BPU_360_PI2;
  rot *= (f32)BPU_180_PI; //gbox patch 2008.8.13
  return rot;
}
//------------------------------------------------------------------------------
//! setLinearVelocity
//! Set animator linear vel
void CBulletObjectAnimator::setLinearVelocity(const core::vector3df& vel) const
{	
  _IRR_DEBUG_BREAK_IF(rigidBody == NULL);

  //bullet hangs if attempt to set lin. or ang. velocity on static object
  if (physicsParams.mass != 0.0f) 
  {
    rigidBody->setLinearVelocity(btVector3(vel.X, vel.Y, vel.Z));
  }
  //note - apparently, need to use motion state on kinematic objects, and rigid body functions
  // on dynamic rigid bodies to change pos / rot etc.
}
Exemple #14
0
void CD3D9Texture::uploadTexture(u32 layer, u32 level, void* data)
{
	if (!data)
		return;

	u32 width = Size.Width >> level;
	u32 height = Size.Height >> level;

	u32 dataSize = IImage::getDataSizeFromFormat(ColorFormat, width, height);

	HRESULT hr = 0;

	D3DLOCKED_RECT lockRectangle;

	if (Texture)
	{
		hr = Texture->LockRect(level, &lockRectangle, 0, 0);
	}
	else if (CubeTexture)
	{
		_IRR_DEBUG_BREAK_IF(layer > 5)

		hr = CubeTexture->LockRect(static_cast<_D3DCUBEMAP_FACES>(layer), level, &lockRectangle, 0, 0);
	}

	if (FAILED(hr))
	{
		os::Printer::log("Texture data not copied", "Could not LockRect D3D9 Texture.", ELL_ERROR);
		return;
	}

	memcpy(lockRectangle.pBits, data, dataSize);

	if (Texture)
	{
		hr = Texture->UnlockRect(level);
	}
	else if (CubeTexture)
	{
		hr = CubeTexture->UnlockRect(static_cast<_D3DCUBEMAP_FACES>(layer), level);
	}

	if (FAILED(hr))
	{
		os::Printer::log("Texture data not copied", "Could not UnlockRect D3D9 Texture.", ELL_ERROR);
	}
}
//------------------------------------------------------------------------------
//! animateNode
//! animates a scene node
void CBulletObjectAnimator::animateNode(ISceneNode* node, u32 timeMs)
{
  _IRR_DEBUG_BREAK_IF(node != sceneNode);

  if (physicsParams.mass != 0.0f && rigidBody && rigidBody->getMotionState())
  {
    // set pos
    btVector3 p = rigidBody->getCenterOfMassPosition();
    sceneNode->setPosition(core::vector3df(p.getX(), p.getY(), p.getZ()));

    // set rot
    core::vector3df rot;
    btQuaternion btq = rigidBody->getOrientation();
    QuaternionToEulerXYZ(btq, rot);
    rot *= (f32)BPU_180_PI;

	//rot.Y = 0-rot.Y; 

    sceneNode->setRotation(rot);
  } 
}
ITexture* CCursorController::getCursorTexture(u32 index) const
{
   _IRR_DEBUG_BREAK_IF(index>used); // access violation

   return m_aMouseCursors[index].tex;
}
//------------------------------------------------------------------------------
//! activate
//! Zero all forces
void CBulletObjectAnimator::activate(bool force) const
{
  _IRR_DEBUG_BREAK_IF(rigidBody == NULL);

  rigidBody->activate(force);
}
//------------------------------------------------------------------------------
//! setActivationState
//! Zero all forces
void CBulletObjectAnimator::setActivationState(bool active) const
{
  _IRR_DEBUG_BREAK_IF(rigidBody == NULL);

  rigidBody->setActivationState((active) ? 1 : 0);
}
Exemple #19
0
//! constructor
CGUIPlot::CGUIPlot(
	scene::ISceneManager* smgr,
	IGUIEnvironment* env,
	IGUIElement* parent,
	s32 id,
	const core::rect<s32>& rectangle)
: IGUIElement( EGUIET_ELEMENT, env, parent, id, rectangle)
//, Viewport(0,0,0,0)
, ZoomRect(-1,-4,10,5)
, Plotrect(0,0,0,0)
, IsDrawBackground(false)
, BackgroundColor(video::SColor(255,255,255,255))
, TextColor(video::SColor(255,0,0,0))
, IsDrawGrid(true)
, GridColor(video::SColor(255,200,200,200))
, SubGridColor(video::SColor(255,235,235,235))
, SceneManager(smgr)
, Root(0)
, Camera(0)
{
#ifdef _DEBUG
	setDebugName("CGUIPlot");
#endif

	// this element can be tabbed to
	setTabStop(false);
	setTabOrder(-1);

	IGUISkin *skin = 0;
	if (Environment)
		skin = Environment->getSkin();

	//FrameRect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X)+1;
	//FrameRect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y)+1;
	//FrameRect.LowerRightCorner.X -= skin->getSize(EGDS_TEXT_DISTANCE_X)+1;
	//FrameRect.LowerRightCorner.Y -= skin->getSize(EGDS_TEXT_DISTANCE_Y)+1;

	// TextColor=skin->getColor(EGDC_HIGH_LIGHT_TEXT);

	s32 w = rectangle.getWidth(); // in pixels
	s32 h = rectangle.getHeight(); // in pixels
	s32 sb_size = 16; // in pixels

	core::recti r_canvas = makeRect(0,0, (u32)(w-sb_size-1), (u32)(h-sb_size-1) );
	core::recti r_scrollH = makeRect(1,h-sb_size, (u32)(w-sb_size-1), (u32)sb_size );
	core::recti r_scrollV = makeRect( w-sb_size, 1, (u32)sb_size, (u32)(h-sb_size-1) );
	core::recti r_reset = makeRect( w-sb_size, h-sb_size, (u32)sb_size, (u32)sb_size );

	Plotrect = r_canvas; //! visible ContentRect, Viewport is projected to this rect

	ScrollbarH = Environment->addScrollBar(true,r_scrollH,this,-1);
	ScrollbarH->setVisible(true);
	ScrollbarH->setSubElement(false);
	ScrollbarH->setTabStop(false);
	ScrollbarH->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
	ScrollbarH->setSmallStep(3);
	ScrollbarH->setMin(0);
	ScrollbarH->setMax(100);
	ScrollbarH->setPos(0);

	ScrollbarV = Environment->addScrollBar(false,r_scrollV,this,-1);
	ScrollbarV->setVisible(true);
	ScrollbarV->setSubElement(false);
	ScrollbarV->setTabStop(false);
	ScrollbarV->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
	ScrollbarV->setMin(0);
	ScrollbarV->setMax(100);
	ScrollbarV->setSmallStep(3);
	ScrollbarV->setPos(0);

	Environment->addButton( r_reset, this, -1, L"R", L"Reset Zoom Button");

	BackgroundColor=skin->getColor(EGDC_WINDOW);

	ContentPane = 0;

	Environment->setFocus(this);
//
//	SceneManager = new scene::CSceneManager(
//		Environment->getVideoDriver(), Environment->getFileSystem(), 0, 0, Environment);

	_IRR_DEBUG_BREAK_IF( !SceneManager )
//	if (!SceneManager)
//	{
//		printf("CGUIPlot::Could not create SceneManager\n");
//		return;
//	}

	Root = SceneManager->addEmptySceneNode( SceneManager->getRootSceneNode(), -1);

	_IRR_DEBUG_BREAK_IF( !Root )

	Camera = SceneManager->addCameraSceneNode( Root, core::vector3df(0,0,-100), core::vector3df(0,0,100), -1, false);

	_IRR_DEBUG_BREAK_IF( !Camera )

	Root->setVisible( false );

	/// Prepare some SceneNodes for x,y Axis and Grid

	//scene::ISceneManager* SceneManager = SceneManager;

	gui::IGUIFont* font = Environment->getBuiltInFont();

	scene::ITextSceneNode* textNode00 = SceneManager->addTextSceneNode(
		font, L"(0,0)", TextColor, SceneManager->getRootSceneNode(), core::vector3df(0,0,0) );

	scene::ITextSceneNode* textNodeX = SceneManager->addTextSceneNode(
		font, L"X", TextColor, SceneManager->getRootSceneNode(), core::vector3df(ZoomRect.LowerRightCorner.X,0,0) );

	scene::ITextSceneNode* textNodeY = SceneManager->addTextSceneNode(
		font, L"Y", TextColor, SceneManager->getRootSceneNode(), core::vector3df(0, ZoomRect.UpperLeftCorner.Y,0) );

	addShape( textNode00, L"Ursprung" );

	addShape( textNodeX, L"X-Axis" );

	addShape( textNodeY, L"Y-Axis" );


}