예제 #1
0
void HMDStereoRender::drawAll(ISceneManager* smgr) {

  ICameraSceneNode* camera = smgr->getActiveCamera();
  camera->OnAnimate(_timer->getTime());

  // Render Left
  _driver->setRenderTarget(_renderTexture, true, true, video::SColor(0,0,0,0));
  
  _pCamera->setProjectionMatrix(_projectionLeft);

  vector3df r = camera->getRotation();
  vector3df tx(-_eyeSeparation, 0.0,0.0);
  tx.rotateXZBy(-r.Y);
  tx.rotateYZBy(-r.X);
  tx.rotateXYBy(-r.Z);

  _pCamera->setPosition(camera->getPosition() + tx);
  _pCamera->setTarget(camera->getTarget() + tx);  

  smgr->setActiveCamera(_pCamera);
  smgr->drawAll();

  _driver->setRenderTarget(0, false, false, video::SColor(0,100,100,100));
  _driver->setViewPort(_viewportLeft);

  _distortionCB.lensCenter[0] = _lensShift;

  _driver->setMaterial(_renderMaterial); 
  _driver->drawIndexedTriangleList(_planeVertices, 4, _planeIndices, 2);
 
  // Render Right
  _driver->setRenderTarget(_renderTexture, true, true, video::SColor(0,0,0,0));
  _pCamera->setProjectionMatrix(_projectionRight);

  vector3df r2 = camera->getRotation();
  vector3df tx2(-_eyeSeparation, 0.0,0.0);
  tx.rotateXZBy(-r2.Y);
  tx.rotateYZBy(-r2.X);
  tx.rotateXYBy(-r2.Z);

  _pCamera->setPosition(camera->getPosition() + tx2);
  _pCamera->setTarget(camera->getTarget() + tx2);  

  smgr->drawAll();

  _driver->setRenderTarget(0, false, false, video::SColor(0,100,100,100));  
  _driver->setViewPort(_viewportRight);

  _distortionCB.lensCenter[0] = -_lensShift;

  _driver->setMaterial(_renderMaterial); 
  _driver->drawIndexedTriangleList(_planeVertices, 4, _planeIndices, 2);

  smgr->setActiveCamera(camera);
}
예제 #2
0
    //-------------------------------------------------------------------------
    //                             p r e R e n d e r 
    //-------------------------------------------------------------------------
    void CApplication::preRender(u32 delta)
    {
        static u32 elapsed=0;
        elapsed += delta;
        if(elapsed > 100)
        {
            elapsed = 0;
            // update debug info if visible
            if(m_debugPanel->getVisible())
            {
                char buf[128];           
                u32 tris = m_videoDriver->getPrimitiveCountDrawn();

                ICameraSceneNode* camera = m_sceneManager->getActiveCamera();
                vector3df pos = camera->getPosition();
                vector3df rot = camera->getRotation();
                vector3df dir = camera->getTarget();
                stringc  nname = camera->getName();
                sprintf(buf,"%s: Pos(%.1f,%.1f,%.1f) Rot(%.1f,%.1f,%.1f) Dir(%.1f,%.1f,%.1f)",
                    nname.c_str(),pos.X,pos.Y,pos.Z,rot.Y,rot.X,rot.Z,dir.X,dir.Y,dir.Z);
                m_debugPanel->updateItem(0,buf);

                sprintf(buf,"Frame: Avg(%d) Min(%d) Max(%d), Tris(%d)",
                    m_fpsAvg, m_fpsMin, m_fpsMax, tris);

                m_debugPanel->updateItem(1,buf);

                array<stringc> debugStrings;
                addCustomDebug(debugStrings);

                if(debugStrings.size() > 0)
                {
                    while((debugStrings.size()+2) > m_debugPanel->getItemCount())
                    {
                        m_debugPanel->addItem(" " ,EGUIA_CENTER);
                    }

                    for(u32 i=0;i<debugStrings.size();i++)
                    {
                        m_debugPanel->updateItem(i+2,debugStrings[i]);
                    }

                }


            }

        }
    }
예제 #3
0
void TheBeginMove::animateNode( ISceneNode* node, u32 timeMs )
{
	ICameraSceneNode* camera = static_cast<ICameraSceneNode*>(node);
	//初始化
	if ( IsFirst )
	{
		IsFirst = false;
		Begin = timeMs + Delay;
		vector3df dir3 = camera->getTarget() - camera->getPosition();
		vector2df direction = vector2df( dir3.X, dir3.Z );
		lastRad = (f32)direction.getAngle() - 90;
		lastRad *= DEGTORAD;
		camera ->setTarget(TheEndPoint + dir3 );
		/*std::cout<< direction.X << " , " << direction.Y << std::endl;
		std::cout<< lastRad << std::endl;*/
	}
	//还未达到动画开始时间
	if( Begin > timeMs )
		return;

	u32 t;
	t = timeMs - Begin;	
	
	//到达动画结束时间
	if ( t > Duration )
	{
		//把自己删掉
		camera->removeAnimator(this);
		return;
	}
	camera -> setPosition( vector3df
		( Center.X + (Distance - M_Distance * t) * sin( radian * t + lastRad ) , 
		Center.Y + M_y * t , 
		Center.Z + (Distance - M_Distance * t)  * cos( radian * t + lastRad ) ));	
	camera ->setTarget(TheEndPoint);
}
		void CSSceneNodeAnimatorFPS::animateNode(ISceneNode* node, u32 timeMs)
		{
			if (!node || node->getType() != ESNT_CAMERA)
				return;

			ICameraSceneNode* camera = static_cast<ICameraSceneNode*>(node);

			if (firstUpdate)
			{
				camera->updateAbsolutePosition();
				if (CursorControl)
				{
					CursorControl->setPosition(m_CursorOffsetX, m_CursorOffsetY);
					CursorPos = CenterCursor = CursorControl->getRelativePosition();
				}

				LastAnimationTime = timeMs;

				firstUpdate = false;
			}

			// If the camera isn't the active camera, and receiving input, then don't process it.
			if (!camera->isInputReceiverEnabled())
			{
				firstInput = true;
				return;
			}

			if (firstInput)
			{
				allKeysUp();
				firstInput = false;
			}

			scene::ISceneManager * smgr = camera->getSceneManager();
			if (smgr && smgr->getActiveCamera() != camera)
				return;

			// get time
			f32 timeDiff = (f32)(timeMs - LastAnimationTime);
			LastAnimationTime = timeMs;

			// update position
			core::vector3df pos = camera->getPosition();

			// Update rotation
			core::vector3df target = (camera->getTarget() - camera->getAbsolutePosition());
			core::vector3df relativeRotation = target.getHorizontalAngle();

			if (CursorControl)
			{
				if (CursorPos != CenterCursor)
				{
					relativeRotation.Y -= (m_CursorOffsetX - CursorPos.X) * RotateSpeed;
					relativeRotation.X -= (m_CursorOffsetY - CursorPos.Y) * RotateSpeed * MouseYDirection;

					// X < MaxVerticalAngle or X > 360-MaxVerticalAngle

					if (relativeRotation.X > MaxVerticalAngle * 2 &&
						relativeRotation.X < 360.0f - MaxVerticalAngle)
					{
						relativeRotation.X = 360.0f - MaxVerticalAngle;
					}
					else
						if (relativeRotation.X > MaxVerticalAngle &&
							relativeRotation.X < 360.0f - MaxVerticalAngle)
						{
						relativeRotation.X = MaxVerticalAngle;
						}

					// Do the fix as normal, special case below
					// reset cursor position to the centre of the window.
					CursorControl->setPosition(m_CursorOffsetX, m_CursorOffsetY);
					CenterCursor = CursorControl->getRelativePosition();

					// needed to avoid problems when the event receiver is disabled
					CursorPos = CenterCursor;
				}

				// Special case, mouse is whipped outside of window before it can update.
				video::IVideoDriver* driver = smgr->getVideoDriver();
				core::vector2d<u32> mousepos(u32(CursorControl->getPosition().X), u32(CursorControl->getPosition().Y));
				core::rect<u32> screenRect(0, 0, driver->getScreenSize().Width, driver->getScreenSize().Height);

				// Only if we are moving outside quickly.
				bool reset = !screenRect.isPointInside(mousepos);

				if (reset)
				{
					// Force a reset.
					CursorControl->setPosition(m_CursorOffsetX, m_CursorOffsetY);
					CenterCursor = CursorControl->getRelativePosition();
					CursorPos = CenterCursor;
				}
			}

			// set target

			target.set(0, 0, core::max_(1.f, pos.getLength()));
			core::vector3df movedir = target;

			core::matrix4 mat;
			mat.setRotationDegrees(core::vector3df(relativeRotation.X, relativeRotation.Y, 0));
			mat.transformVect(target);

			if (NoVerticalMovement)
			{
				mat.setRotationDegrees(core::vector3df(0, relativeRotation.Y, 0));
				mat.transformVect(movedir);
			}
			else
			{
				movedir = target;
			}

			movedir.normalize();

			if (CursorKeys[EKA_MOVE_FORWARD])
				pos += movedir * timeDiff * MoveSpeed;

			if (CursorKeys[EKA_MOVE_BACKWARD])
				pos -= movedir * timeDiff * MoveSpeed;

			// strafing

			core::vector3df strafevect = target;
			strafevect = strafevect.crossProduct(camera->getUpVector());

			if (NoVerticalMovement)
				strafevect.Y = 0.0f;

			strafevect.normalize();

			if (CursorKeys[EKA_STRAFE_LEFT])
				pos += strafevect * timeDiff * MoveSpeed;

			if (CursorKeys[EKA_STRAFE_RIGHT])
				pos -= strafevect * timeDiff * MoveSpeed;

			// For jumping, we find the collision response animator attached to our camera
			// and if it's not falling, we tell it to jump.
			if (CursorKeys[EKA_JUMP_UP])
			{
				const ISceneNodeAnimatorList& animators = camera->getAnimators();
				ISceneNodeAnimatorList::ConstIterator it = animators.begin();
				while (it != animators.end())
				{
					if (ESNAT_COLLISION_RESPONSE == (*it)->getType())
					{
						ISceneNodeAnimatorCollisionResponse * collisionResponse =
							static_cast<ISceneNodeAnimatorCollisionResponse *>(*it);

						if (!collisionResponse->isFalling())
							collisionResponse->jump(JumpSpeed);
					}

					it++;
				}
			}

			// write translation
			camera->setPosition(pos);

			// write right target
			target += pos;
			camera->setTarget(target);
		}
예제 #5
0
파일: main.cpp 프로젝트: bdbdonp/tubras
int main(int argc, char* argv[])
{
    stringc sceneDirectory, saveDir;
    irr::io::path sceneFileName;
    UserDataSerializer serializer;

    if(argc < 2)
    {
        printf("error scene file name missing:\n");
        printf("    irrbPhysics <input scene filename>\n");
        return -1;
    }

    // initialize Irrlicht
    m_device = _createDevice();
    if(!m_device)
        return -1;

    m_fileSystem = m_device->getFileSystem();
    m_videoDriver = m_device->getVideoDriver();
    m_sceneManager = m_device->getSceneManager();
    m_gui = m_device->getGUIEnvironment();
    m_debugNode = new CDebugNode(m_sceneManager);


    // create debug panel (text area) 
    core::dimension2du screen = m_videoDriver->getScreenSize();
    m_debugPanel = m_gui->addStaticText(L"",rect<s32>(screen.Width-202,0,screen.Width-2,100));
    m_debugPanel->setBackgroundColor(SColor(128, 30, 30, 30));
    m_debugPanel->setDrawBorder(true);

    IGUIFont* font=m_debugPanel->getOverrideFont();
    if(!font)
        font = m_gui->getSkin()->getFont();
    m_charHeight = font->getDimension(L"Ay").Height;
    s32 idx=0;
    m_charHeight += font->getKerningHeight();

    // create help panel (text area)
    m_helpPanel = m_gui->addStaticText(L"",rect<s32>(2,0,202,200));
    m_helpPanel->setBackgroundColor(SColor(128, 30, 30, 30));
    m_helpPanel->setDrawBorder(true);
    _addHelpText("F1 - Toggle Help");
    _addHelpText("F3 - Cycle Wire, Points, Solid");
    _addHelpText("F4 - Toggle Physics Debug");
    _addHelpText("F5 - Warp To Start Position");
    _addHelpText("F9 - Detach Camera");

    // turn hardware cursor off
    m_device->getCursorControl()->setVisible(false);

#if defined(USE_BULLET)
    m_device->setWindowCaption(L"irrb Collision/Physics example - Using Bullet");
#elif defined(USE_IRRPHYSX)
    m_device->setWindowCaption(L"irrb Collision/Physics example - Using IrrPhysx");
#else
    m_device->setWindowCaption(L"irrb Collision/Physics example - Using Irrlicht");
#endif
    m_camera = m_sceneManager->addCameraSceneNodeFPS(0, 100.0f, m_moveSpeed, -1, keyMap, 5, true, m_jumpSpeed);
    m_camera->setPosition(vector3df(0,10,0));
    m_camera->setFOV(core::PI / 2.5f);
    m_camera->setNearValue(.1f);
    m_camera->setFarValue(1000.f);

    // save off animator
    core::list<ISceneNodeAnimator*>::ConstIterator anims=m_camera->getAnimators().begin();
    while(anims != m_camera->getAnimators().end())
    {
        if ((*anims)->getType() == ESNAT_CAMERA_FPS)
        {
            m_fpsAnimator = (ISceneNodeAnimatorCameraFPS*)*anims;
            break;
        }
        ++anims;
    }

    // init physics library
    _initPhysicsLibrary();

    m_displayPhysicsDebug = true;
    _enablePhysicsDebug(true);
    m_debugNode->setVisible(true);

    // load scene
    sceneFileName = argv[1];   
    sceneDirectory = m_fileSystem->getFileDir(sceneFileName);

    saveDir = m_fileSystem->getWorkingDirectory();
    m_fileSystem->changeWorkingDirectoryTo(sceneDirectory);

    m_sceneManager->loadScene(sceneFileName.c_str(), &serializer);

    m_fileSystem->changeWorkingDirectoryTo(saveDir);

    // if the scene also contained a camera, set the active
    // camera to our fps camera and update the fps pos/rot.
    if(m_camera && (m_camera != m_sceneManager->getActiveCamera()))
    {
        ICameraSceneNode* anode = m_sceneManager->getActiveCamera();

        m_camera->setPosition(anode->getPosition());
        m_camera->setRotation(anode->getRotation());
        m_sceneManager->setActiveCamera(m_camera);
        m_startPos = m_camera->getPosition();
        _warp(m_startPos);
    }

    ITimer* timer = m_device->getTimer();
    u32 current, last = timer->getRealTime();
    u32 delta = 0;

    while(m_device->run() && m_running)
    {
        _clearDebugText();
        m_videoDriver->beginScene(true, true, SColor(255,100,101,140));

        // calc milliseconds since last frame
        current = timer->getRealTime();
        delta = current-last;
        last = current;

        // update collision/physics simulation
        _stepSimulation(delta);

        m_sceneManager->drawAll();

        static char buf[64];
        sprintf(buf, "FPS: %d", m_videoDriver->getFPS());  
        _updateDebugText(0, buf);
        m_gui->drawAll();

        m_videoDriver->endScene();
    }

    m_device->drop();
    delete m_eventReceiver;    

    return 0;
}
예제 #6
0
void loop(s4 &game_state)
{
    ICameraSceneNode* camera = irrlicht->smgr->addCameraSceneNode();
    matrix4 ortho;
    ortho.buildProjectionMatrixOrthoLH(
        irrlicht->driver->getScreenSize().Width/ortho_scale,
        irrlicht->driver->getScreenSize().Height/ortho_scale,-1.0,1000.0);
    camera->setProjectionMatrix(ortho);
    camera->setPosition({0,0,-100});
    camera->setTarget({0,0,0});

    irrlicht->hud->setActiveCamera(camera);

    IBillboardSceneNode* qnode = irrlicht->smgr->addBillboardSceneNode();
    qnode->setMaterialFlag(EMF_WIREFRAME,true);

    // --------------------------------------
 
    p("---- Game loop start ----");

    d32         dt = 0.0f;
    const d32   maxDelta = 1.0f/60.0f * 5.0f; 
    const d32   tick_ms = 0.01666f; // TODO: change this back to 30ms?
    d32         render_dt = 0.0f;
    const d32   render_ms = RENDER_TIME_STEP;
    uint32      time_physics_prev = btclock->getTimeMicroseconds();

    while(irrlicht->device->run() && game_state == GAME_STATE_PLAY)
    {
        const uint32 time_physics_curr = btclock->getTimeMicroseconds();
        const d32 frameTime = ((d32)(time_physics_curr - time_physics_prev)) / 1000000.0; // todo: is this truncated correctly?
        time_physics_prev = time_physics_curr;
        d32 capped_dt = frameTime;
        if (capped_dt > maxDelta) { capped_dt = maxDelta; }

        render_dt += capped_dt;
        if ( render_dt >= render_ms )
        {
            render_dt = 0.0f;

            update_player();
            update_enemies();
            update_missiles(ply->missiles,ply->num_missile);

            irrlicht->hud->getRootSceneNode()->setPosition(camera->getPosition() + vector3df(0,0,100));

            irrlicht->driver->beginScene(true, true, SColor(255,59,120,140));
            irrlicht->smgr->drawAll();  
            irrlicht->driver->clearZBuffer(); 
            irrlicht->hud->drawAll();

            irrlicht->driver->endScene();
        }

        dt += capped_dt;
        while( dt >= tick_ms ) 
        {
            dt -= tick_ms;
            receiver->input();

            clear_quads(quadtree);
            step_player();
            step_enemies();
            step_missiles(ply->missiles, ply->num_missile); 

            QuadTree::Quad* fq = get_quad_from_pos(quadtree,ply->curr_pos);
            qnode->setSize(dimension2d<f32>(1,1));
            qnode->setPosition(fq->pos.irr());
            qnode->setSize(dimension2d<f32>(fq->width,fq->width));
 
            if (receiver->debug_key.state)
            {
                for (s4 i = 0; i < fleet->num_squad; i++)
                {
                    if (fleet->squads[i].mode != scatter)
                        fleet->squads[i].mode = scatter;
                    else
                        fleet->squads[i].mode = to_positions;
                }
            }
            if (receiver->restart.state) { game_state = GAME_STATE_RESET; return; }
            if (receiver->QUIT) { game_state = GAME_STATE_QUIT; return; }

            empty_transient_soft(memory);
        }

        alpha = dt / tick_ms;

        core::stringw str = L"Coquelicot // score: ";
        str += score;
        str += L" // FPS: ";
        str += (s32)irrlicht->driver->getFPS();
        irrlicht->device->setWindowCaption(str.c_str());
    } 
}
void CSceneNodeAnimatorCameraFPS::animateNode(IDummyTransformationSceneNode* node, uint32_t timeMs)
{
	if (!node || node->getType() != ESNT_CAMERA)
		return;

	ICameraSceneNode* camera = static_cast<ICameraSceneNode*>(node);

	if (firstUpdate)
	{
		camera->updateAbsolutePosition();
		if (CursorControl )
		{
			CursorControl->setPosition(0.5f, 0.5f);
			CursorPos = CenterCursor = CursorControl->getRelativePosition();
		}

		LastAnimationTime = timeMs;

		firstUpdate = false;
	}

	// If the camera isn't the active camera, and receiving input, then don't process it.
	if(!camera->isInputReceiverEnabled())
	{
		firstInput = true;
		return;
	}

	if ( firstInput )
	{
		allKeysUp();
		firstInput = false;
	}

	scene::ISceneManager * smgr = camera->getSceneManager();
	if(smgr && smgr->getActiveCamera() != camera)
		return;

	// get time
	float timeDiff = (float) ( timeMs - LastAnimationTime );
	LastAnimationTime = timeMs;

	// update position
	core::vector3df pos = camera->getPosition();

	// Update rotation
	core::vector3df target = (camera->getTarget() - camera->getAbsolutePosition());
	core::vector3df relativeRotation = target.getHorizontalAngle();

	if (CursorControl)
	{
		if (CursorPos != CenterCursor)
		{
			relativeRotation.Y -= (0.5f - CursorPos.X) * RotateSpeed;
			relativeRotation.X -= (0.5f - CursorPos.Y) * RotateSpeed * MouseYDirection;

			// X < MaxVerticalAngle or X > 360-MaxVerticalAngle

			if (relativeRotation.X > MaxVerticalAngle*2 &&
				relativeRotation.X < 360.0f-MaxVerticalAngle)
			{
				relativeRotation.X = 360.0f-MaxVerticalAngle;
			}
			else
			if (relativeRotation.X > MaxVerticalAngle &&
				relativeRotation.X < 360.0f-MaxVerticalAngle)
			{
				relativeRotation.X = MaxVerticalAngle;
			}

			// Do the fix as normal, special case below
			// reset cursor position to the centre of the window.
			CursorControl->setPosition(0.5f, 0.5f);
			CenterCursor = CursorControl->getRelativePosition();

			// needed to avoid problems when the event receiver is disabled
			CursorPos = CenterCursor;
		}

		// Special case, mouse is whipped outside of window before it can update.
		video::IVideoDriver* driver = smgr->getVideoDriver();
		core::vector2d<uint32_t> mousepos(uint32_t(CursorControl->getPosition().X), uint32_t(CursorControl->getPosition().Y));
		core::rect<uint32_t> screenRect(0, 0, driver->getScreenSize().Width, driver->getScreenSize().Height);

		// Only if we are moving outside quickly.
		bool reset = !screenRect.isPointInside(mousepos);

		if(reset)
		{
			// Force a reset.
			CursorControl->setPosition(0.5f, 0.5f);
			CenterCursor = CursorControl->getRelativePosition();
			CursorPos = CenterCursor;
 		}
	}

	// set target

	target.set(0,0, core::max_(1.f, pos.getLength()));
	core::vector3df movedir = target;

	core::matrix4x3 mat;
	mat.setRotationDegrees(core::vector3df(relativeRotation.X, relativeRotation.Y, 0));
	mat.transformVect(&target.X);

	if (NoVerticalMovement)
	{
		mat.setRotationDegrees(core::vector3df(0, relativeRotation.Y, 0));
		mat.transformVect(&movedir.X);
	}
	else
	{
		movedir = target;
	}

	movedir.normalize();

	if (CursorKeys[EKA_MOVE_FORWARD])
		pos += movedir * timeDiff * MoveSpeed;

	if (CursorKeys[EKA_MOVE_BACKWARD])
		pos -= movedir * timeDiff * MoveSpeed;

	// strafing

	core::vector3df strafevect = target;
	strafevect = strafevect.crossProduct(camera->getUpVector());

	if (NoVerticalMovement)
		strafevect.Y = 0.0f;

	strafevect.normalize();

	if (CursorKeys[EKA_STRAFE_LEFT])
		pos += strafevect * timeDiff * MoveSpeed;

	if (CursorKeys[EKA_STRAFE_RIGHT])
		pos -= strafevect * timeDiff * MoveSpeed;

	// write translation
	camera->setPosition(pos);

	// write right target
	target += pos;
	camera->setTarget(target);
}
WxIrrMainWindow::WxIrrMainWindow(const wxString& title, void (*draw)(WxIrrViewportManager*), void (*update)(void),
                                 bool (*irrlichtLeftMouseDown)(bool controlDown, bool shiftDown, int x, int y),
                                 bool (*irrlichtLeftMouseUp)(bool controlDown, bool shiftDown, int x, int y),
                                 bool (*irrlichtLeftMouseDoubleClick)(bool controlDown, bool shiftDown, int x, int y),
                                 bool (*irrlichtMouseMove)(bool controlDown, bool shiftDown, int x, int y, int moveX, int moveY),
                                 void (*irrlichtCameraMouseMove)(int moveX, int moveY, WxIrrViewport* selectedViewport),
                                 void (*irrlichtCameraKeyDown)(int id, WxIrrViewport* selectedViewport),	void (*irrlichtCameraKeyUp)(int id), void (*irrlichtCameraKeyboardReset)(void),
                                 void (*simulationMouseMove)(wxPoint mousePos, bool isShiftDown, WxIrrViewport* mouseOverViewport),
                                 bool (*simulationMouseClick)(bool isShiftDown, bool isControlDown), bool (*simulationMouseDoubleClick)(void), void (*SimulationStartMouseChecking)(void),
                                 void (*onSimulationShowAxesFunctionPointer)(bool), void (*onSimulationShowObjectNameFunctionPointer)(bool),
                                 SColor (*onSimulationXAxisGetColorFunctionPointer)(void), SColor (*onSimulationYAxisGetColorFunctionPointer)(void), SColor (*onSimulationZAxisGetColorFunctionPointer)(void),
                                 void (*onSimulationXAxisChangeColorFunctionPointer)(wxColour& color), void (*onSimulationYAxisChangeColorFunctionPointer)(wxColour& color), void (*onSimulationZAxisChangeColorFunctionPointer)(wxColour& color),
                                 void (*onSimulationShowXYGridFunctionPointer)(bool), void (*onSimulationShowXZGridFunctionPointer)(bool), void (*onSimulationShowYZGridFunctionPointer)(bool))
    : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(800, 600))
{
    OnSimulationShowAxesFunctionPointer = onSimulationShowAxesFunctionPointer;
    OnSimulationShowObjectNameFunctionPointer = onSimulationShowObjectNameFunctionPointer;

    OnSimulationXAxisGetColorFunctionPointer = onSimulationXAxisGetColorFunctionPointer;
    OnSimulationYAxisGetColorFunctionPointer = onSimulationYAxisGetColorFunctionPointer;
    OnSimulationZAxisGetColorFunctionPointer = onSimulationZAxisGetColorFunctionPointer;
    OnSimulationXAxisChangeColorFunctionPointer = onSimulationXAxisChangeColorFunctionPointer;
    OnSimulationYAxisChangeColorFunctionPointer = onSimulationYAxisChangeColorFunctionPointer;
    OnSimulationZAxisChangeColorFunctionPointer = onSimulationZAxisChangeColorFunctionPointer;

    OnSimulationShowXYGridFunctionPointer = onSimulationShowXYGridFunctionPointer;
    OnSimulationShowXZGridFunctionPointer = onSimulationShowXZGridFunctionPointer;
    OnSimulationShowYZGridFunctionPointer = onSimulationShowYZGridFunctionPointer;

    leftPanel = new WxIrrViewportWindow(this, 1000);
    leftPanel->SetBackgroundColour(wxColour(wxT("Black")));

    irr::SIrrlichtCreationParameters param;
#if defined _WX_IRR_WINDOWS

    param.DriverType = EDT_DIRECT3D9;
    param.AntiAlias = false;
    param.WindowId = reinterpret_cast<void*>(GetLeftPanelHandle());

#elif defined _WX_IRR_LINUX

    param.DriverType = EDT_OPENGL;
    param.AntiAlias = false;
    GtkWidget* handle = (GtkWidget*)GetLeftPanelHandle();
    gtk_widget_realize(handle);
    Window xHandle = GDK_WINDOW_XWINDOW(handle->window);
    param.WindowId = (void*)(xHandle);

#elif defined _WX_IRR_MACOS

    //param.DriverType = EDT_OPENGL;

#else

    //return false;
    Close();

#endif

    leftPanel->InitalizeViewportManager();
    SetupDevice(param, draw, update, irrlichtLeftMouseDown, irrlichtLeftMouseUp, irrlichtLeftMouseDoubleClick, irrlichtMouseMove, irrlichtCameraMouseMove, irrlichtCameraKeyDown, irrlichtCameraKeyUp, irrlichtCameraKeyboardReset,
                simulationMouseMove, simulationMouseClick, simulationMouseDoubleClick, SimulationStartMouseChecking);

    //Main camera
    ICameraSceneNode* camera = GetDevice()->getSceneManager()->addCameraSceneNode();
    camera->setPosition(Vector3(30,-10,30));
    //camera->bindTargetAndRotation(true);
    //camera->setTarget(Vector3(0,0,0));
    Vector3 currentCameraRot = camera->getRotation();
    Vector3 rot = currentCameraRot.rotationToDirection();
    Vector3 pos = camera->getPosition();
    camera->setTarget(rot + pos);
    camera->setFarValue(100000);
    SetCamera(camera);

    rightPanel = new SimulationPanel(this, 1001, wxDefaultPosition, wxDefaultSize);
    rightPanel->SetBackgroundColour(wxColour(wxT("Black")));

    m_mgr.SetManagedWindow(this);

    //Create Main Menu
    menuBar = new wxMenuBar();
    menuBarManager = new PhysicsHelperMenuBar(menuBar);

    SetMenuBar( menuBar );
    //Status bar
    CreateStatusBar();
    SetStatusText( wxT("PhysicsHelper") );
    statusBarText = wxT("PhysicsHelper");

    toolBarsManager = new PhysicsHelperToolbars(this, m_mgr);

    //add the normal panes
    m_mgr.AddPane(leftPanel, wxAuiPaneInfo().CenterPane().Name(wxT("leftPanel")));
    m_mgr.AddPane(rightPanel, wxAuiPaneInfo().CloseButton(false).Right().PinButton(true).MinimizeButton(true).Name(wxT("rightPanel")));

    m_mgr.Update();

    //Centre();
}
void CSceneNodeAnimatorCameraFPS::animateNode(ISceneNode* node, u32 timeMs)
{
	if (node->getType() != ESNT_CAMERA)
		return;

	ICameraSceneNode* camera = static_cast<ICameraSceneNode*>(node);

	if (firstUpdate)
	{
		camera->updateAbsolutePosition();
		if (CursorControl && camera)
		{
			CursorControl->setPosition(0.5f, 0.5f);
			CursorPos = CenterCursor = CursorControl->getRelativePosition();
		}

		LastAnimationTime = timeMs;

		firstUpdate = false;
	}

	// get time
	f32 timeDiff = (f32) ( timeMs - LastAnimationTime );
	LastAnimationTime = timeMs;

	// update position
	core::vector3df pos = camera->getPosition();

	// Update rotation
	core::vector3df target = (camera->getTarget() - camera->getAbsolutePosition());
	core::vector3df relativeRotation = target.getHorizontalAngle();

	if (CursorControl)
	{
		if (CursorPos != CenterCursor)
		{
			relativeRotation.Y -= (0.5f - CursorPos.X) * RotateSpeed;
			relativeRotation.X -= (0.5f - CursorPos.Y) * RotateSpeed;

			// X < MaxVerticalAngle or X > 360-MaxVerticalAngle

			if (relativeRotation.X > MaxVerticalAngle*2 &&
				relativeRotation.X < 360.0f-MaxVerticalAngle)
			{
				relativeRotation.X = 360.0f-MaxVerticalAngle;
			}
			else
			if (relativeRotation.X > MaxVerticalAngle &&
				relativeRotation.X < 360.0f-MaxVerticalAngle)
			{
				relativeRotation.X = MaxVerticalAngle;
			}

			// reset cursor position
			CursorControl->setPosition(0.5f, 0.5f);
			CenterCursor = CursorControl->getRelativePosition();
			// needed to avoid problems when the ecent receiver is
			// disabled
			CursorPos = CenterCursor;
		}
	}

	// set target

	target.set(0,0, core::max_(1.f, pos.getLength()));
	core::vector3df movedir = target;

	core::matrix4 mat;
	mat.setRotationDegrees(core::vector3df(relativeRotation.X, relativeRotation.Y, 0));
	mat.transformVect(target);

	if (NoVerticalMovement)
	{
		mat.setRotationDegrees(core::vector3df(0, relativeRotation.Y, 0));
		mat.transformVect(movedir);
	}
	else
	{
		movedir = target;
	}

	movedir.normalize();

	if (CursorKeys[EKA_MOVE_FORWARD])
		pos += movedir * timeDiff * MoveSpeed;

	if (CursorKeys[EKA_MOVE_BACKWARD])
		pos -= movedir * timeDiff * MoveSpeed;

	// strafing

	core::vector3df strafevect = target;
	strafevect = strafevect.crossProduct(camera->getUpVector());

	if (NoVerticalMovement)
		strafevect.Y = 0.0f;

	strafevect.normalize();

	if (CursorKeys[EKA_STRAFE_LEFT])
		pos += strafevect * timeDiff * MoveSpeed;

	if (CursorKeys[EKA_STRAFE_RIGHT])
		pos -= strafevect * timeDiff * MoveSpeed;

	// For jumping, we find the collision response animator attached to our camera
	// and if it's not falling, we tell it to jump.
	if (CursorKeys[EKA_JUMP_UP])
	{
		const core::list<ISceneNodeAnimator*> & animators = camera->getAnimators();
		core::list<ISceneNodeAnimator*>::ConstIterator it = animators.begin();
		while(it != animators.end())
		{
			if(ESNAT_COLLISION_RESPONSE == (*it)->getType())
			{
				ISceneNodeAnimatorCollisionResponse * collisionResponse = 
					static_cast<ISceneNodeAnimatorCollisionResponse *>(*it);

				if(!collisionResponse->isFalling())
					collisionResponse->jump(JumpSpeed);
			}

			it++;
		}
	}

	// write translation
	camera->setPosition(pos);

	// write right target

	TargetVector = target;
	target += pos;
	camera->setTarget(target);
}
//! OnAnimate() is called just before rendering the whole scene.
void CSceneNodeAnimatorCameraMaya::animateNode(IDummyTransformationSceneNode *node, uint32_t timeMs)
{
	//Alt + LM = Rotate around camera pivot
	//Alt + LM + MM = Dolly forth/back in view direction (speed % distance camera pivot - max distance to pivot)
	//Alt + MM = Move on camera plane (Screen center is about the mouse pointer, depending on move speed)

	if (!node || node->getType() != ESNT_CAMERA)
		return;

	ICameraSceneNode* camera = static_cast<ICameraSceneNode*>(node);

	// If the camera isn't the active camera, and receiving input, then don't process it.
	if (!camera->isInputReceiverEnabled())
		return;

	scene::ISceneManager * smgr = camera->getSceneManager();
	if (smgr && smgr->getActiveCamera() != camera)
		return;

	if (OldCamera != camera)
	{
		LastCameraTarget = OldTarget = camera->getTarget();
		OldCamera = camera;
	}
	else
	{
		OldTarget += camera->getTarget() - LastCameraTarget;
	}

	float nRotX = RotX;
	float nRotY = RotY;
	float nZoom = CurrentZoom;

	if ( (isMouseKeyDown(0) && isMouseKeyDown(2)) || isMouseKeyDown(1) )
	{
		if (!Zooming)
		{
			ZoomStart = MousePos;
			Zooming = true;
		}
		else
		{
			const float targetMinDistance = 0.1f;
			nZoom += (ZoomStart.X - MousePos.X) * ZoomSpeed;

			if (nZoom < targetMinDistance) // jox: fixed bug: bounce back when zooming to close
				nZoom = targetMinDistance;
		}
	}
	else if (Zooming)
	{
		const float old = CurrentZoom;
		CurrentZoom = CurrentZoom + (ZoomStart.X - MousePos.X ) * ZoomSpeed;
		nZoom = CurrentZoom;

		if (nZoom < 0)
			nZoom = CurrentZoom = old;
		Zooming = false;
	}

	// Translation ---------------------------------

	core::vector3df translate(OldTarget);

	core::vector3df_SIMD target,upVector;
	upVector.getAsVector3df() = camera->getUpVector();
	target.getAsVector3df() = camera->getTarget();

	core::vector3df_SIMD pos,tvectX;
	pos.getAsVector3df() = camera->getPosition();
	tvectX = pos - target;
	tvectX = normalize(cross(tvectX,upVector));

	const SViewFrustum* const va = camera->getViewFrustum();
	core::vector3df_SIMD tvectY = (va->getFarLeftDown() - va->getFarRightDown());
	tvectY = normalize(cross(tvectY,upVector.Y > 0 ? pos - target : target - pos));

	if (isMouseKeyDown(2) && !Zooming)
	{
		if (!Translating)
		{
			TranslateStart = MousePos;
			Translating = true;
		}
		else
		{
			translate +=  tvectX.getAsVector3df() * (TranslateStart.X - MousePos.X)*TranslateSpeed +
			              tvectY.getAsVector3df() * (TranslateStart.Y - MousePos.Y)*TranslateSpeed;
		}
	}
	else if (Translating)
	{
		translate += tvectX.getAsVector3df() * (TranslateStart.X - MousePos.X)*TranslateSpeed +
		             tvectY.getAsVector3df() * (TranslateStart.Y - MousePos.Y)*TranslateSpeed;
		OldTarget = translate;
		Translating = false;
	}

	// Rotation ------------------------------------

	if (isMouseKeyDown(0) && !Zooming)
	{
		if (!Rotating)
		{
			RotateStart = MousePos;
			Rotating = true;
			nRotX = RotX;
			nRotY = RotY;
		}
		else
		{
			nRotX += (RotateStart.X - MousePos.X) * RotateSpeed;
			nRotY += (RotateStart.Y - MousePos.Y) * RotateSpeed;
		}
	}
	else if (Rotating)
	{
		RotX += (RotateStart.X - MousePos.X) * RotateSpeed;
		RotY += (RotateStart.Y - MousePos.Y) * RotateSpeed;
		nRotX = RotX;
		nRotY = RotY;
		Rotating = false;
	}

	// Set pos ------------------------------------

	pos.getAsVector3df() = translate;
	pos.X += nZoom;

	pos.getAsVector3df().rotateXYBy(nRotY, translate);
	pos.getAsVector3df().rotateXZBy(-nRotX, translate);

	camera->setPosition(pos.getAsVector3df());
	camera->setTarget(translate);

	// Rotation Error ----------------------------

	// jox: fixed bug: jitter when rotating to the top and bottom of y
	pos.set(0,1,0);
	pos.getAsVector3df().rotateXYBy(-nRotY);
	pos.getAsVector3df().rotateXZBy(-nRotX+180.f);
	camera->setUpVector(pos.getAsVector3df());
	LastCameraTarget = camera->getTarget();
}