Esempio n. 1
0
void CsCameraManager::NextCamera() {
	// if we have only the default camera
	if (mCameraList.size() < 2) return;

	if (++mCurrentCamera  >= mCameraList.size()) mCurrentCamera = 1;
	ApplyCamera();
} 
Esempio n. 2
0
bool TDCamera::onTick(float fElapsedTime, CTerrain* terrain)
{
	static float fTime(0.f);
	KeyboardInput(fElapsedTime);
	if (m_bDragging || m_bFollowing) MouseInput();
	UpdateAxis();
	if (m_bFollowing) {
		if (m_bGravity) m_pvPos.y = terrain->GetHeight(m_pvPos.x, m_pvPos.z); 
		m_vecEyePosition = m_pvPos - m_vecDirection * m_fFollowDist 
			+ m_vOffset - m_vecRight * (.5f * m_fFollowDist + .5f);
		D3DXMatrixRotationY(m_pTransform, m_fYaw - D3DX_PI);
		m_pTransform->_41 = m_pvPos.x; m_pTransform->_42 = m_pvPos.y; m_pTransform->_43 = m_pvPos.z;
	}
	ApplyCamera();
	if (m_bFollowing) {
		std::string action;
		if (m_bMoving) {
			if (m_bRunning) action = "run";
			else action = "walk";
		} else action = "stand";
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			action = "attack";
			fTime += fElapsedTime;
			// Animation Specific Parameters
			if (fTime > 1.2f) {
				fTime = 0.f;
				return true;
			}
		} else fTime = .6f;
		m_pPlayer->SetAction(action.c_str(), true, 5.f, .5f);
	}
	return false;
}
Esempio n. 3
0
void UberShader::ApplyCamera() {
  Device *dev = Device::GetInstance();
  RenderState *render_dev = &dev->render_state();
  const glm::mat4 &projection = render_dev->projection_mat();
  const glm::mat4 &view = render_dev->view_mat();
  const glm::mat4 &model = render_dev->model_mat();
  ApplyCamera(projection, view, model);
}
Esempio n. 4
0
// NOTE: the first camera at index 0 is used for animation purposes and is 
// not available
void CsCameraManager::PrevCamera() {
	// if we have only the default camera
	if (mCameraList.size() < 2) return;

	mCurrentCamera--;
	if (mCurrentCamera  < 1) mCurrentCamera = mCameraList.size() - 1;
	ApplyCamera();
} 
Esempio n. 5
0
void CsCameraManager::SetTarget (Ogre::SceneNode* targetNode) {
	if (targetNode == NULL) return;
	if (mTargetNode != NULL && mCameraType[mCurrentCamera] == Chaos::CHASE_CAMERA) {
		mTargetNode->removeChild(mCameraList[mCurrentCamera].second);
	}
	mTargetNode = targetNode; 
	ApplyCamera(); 

	mTargetObject = NULL;
}
Esempio n. 6
0
void CsCameraManager::Load (Ogre::SceneNode* ogreScene) {
	UnLoad();
	SetupDefaultCamera();

	if (ogreScene == NULL) return;

	Ogre::Node::ChildNodeIterator it = ogreScene->getChildIterator();
	
	Ogre::SceneNode *tempNode;

	while (it.hasMoreElements()) {
		tempNode = static_cast <Ogre::SceneNode*> (it.getNext());
		assert(tempNode);

		if ((tempNode->getName().find("Camera")) != std::string::npos) {
			ogreScene->removeChild(tempNode);

			if (tempNode->getName().find("Free") != std::string::npos)
				AddCamera((Ogre::Camera*)tempNode->getAttachedObject(0), Chaos::FREE_CAMERA);
			else if (tempNode->getName().find("Track") != std::string::npos)
				AddCamera((Ogre::Camera*)tempNode->getAttachedObject(0), Chaos::TRACK_CAMERA);
			else if (tempNode->getName().find("Chase") != std::string::npos) {
				AddCamera((Ogre::Camera*)tempNode->getAttachedObject(0), Chaos::CHASE_CAMERA);
				if (tempNode->getName().find("001") != std::string::npos) {
					mCurrentCamera = mCameraList.size() - 1;
					ApplyCamera();
				}
			}
			else if (tempNode->getName().find("Cockpit") != std::string::npos)
				AddCamera((Ogre::Camera*)tempNode->getAttachedObject(0), Chaos::COCKPIT_CAMERA);
		}
	}

	mCurrentCamera = 0;
	ApplyCamera();
}
Esempio n. 7
0
void CsCameraManager::SetCamera (const char* name) {
	int count = 0;

	std::vector<std::pair<Ogre::Camera*, Ogre::SceneNode*>>::iterator it;

	for (it = mCameraList.begin(); it != mCameraList.end(); it++) {
		if ((*it).first->getName().find(name) != Ogre::String::npos)  {
			// found
			mCurrentCamera = count;
			ApplyCamera();
			return;
		}
		count++;
	}
}
/*
########  ######## ##    ## ########  ######## ########  
##     ## ##       ###   ## ##     ## ##       ##     ## 
##     ## ##       ####  ## ##     ## ##       ##     ## 
########  ######   ## ## ## ##     ## ######   ########  
##   ##   ##       ##  #### ##     ## ##       ##   ##   
##    ##  ##       ##   ### ##     ## ##       ##    ##  
##     ## ######## ##    ## ########  ######## ##     ## 
*/
void SpaceInvadersState::Render(RenderState* renderState)
{
	// Apply the camera transformation
	ApplyCamera(renderState);

	Shader *shader = shaderMan->GetShader(SHADER_NORMAL);

    // Apply renderState settings
    //renderState->renderAABB = this->renderAABB;
    //renderState->renderOutline = this->renderOutline;

    // Render the grid
	if(renderGrid)
		RenderGrid(renderState);
    // Render the border
	if(renderBorder)
		RenderBorder(renderState);

	glUseProgram(shader->program);
    
    /*RigidBody **objects = physics->GetObjects();
    int amountObjects = physics->AmountObjects();
    for(int i = 0; i < amountObjects; ++i){
        if(objects[i])
            objects[i]->Render(renderState);
    }*/
    
    // Render Spaceship
    if(spaceship)
    	RenderSpaceShip(renderState);

	//PrintSentence(renderState, "Made by Blankycan", Vector2f(1.5f * 16.f * (float)windowState->GetWindow()->GetXPixel(), -4.5f * 16.f * (float)windowState->GetWindow()->GetYPixel()));

    
	glUseProgram(shader->program);
   
   
	glUseProgram(0);
}
Esempio n. 9
0
void CsCameraManager::SetupDefaultCamera() {
	//for proper orientation
	Ogre::Quaternion q(Ogre::Radian(Ogre::Degree(0.0)), Ogre::Vector3::UNIT_Z);
	
	// Free movable Camera
	mDefaultCamNode  =  mSceneMgr->createSceneNode("DefaultCamNode");

	mDefaultCam = mSceneMgr->createCamera("DefaultCam");

	mDefaultCam->setNearClipDistance(0.1);
	mDefaultCam->setFarClipDistance(5000);

	mDefaultCam->setAspectRatio(Ogre::Real(mViewport->getActualWidth()) / Ogre::Real(mViewport->getActualHeight()));
	mDefaultCam->setPosition(0,0,0);
	mDefaultCam->setFixedYawAxis(false);

	mDefaultCamNode->translate(0, 200, -600);
	mDefaultCamNode->setFixedYawAxis(false);
	//mDefaultCamNode->lookAt(Ogre::Vector3(0,0,0), Ogre::Node::TS_LOCAL);

	mDefaultCamNode->attachObject(mDefaultCam);
	
	AddCamera(mDefaultCam, Chaos::FREE_CAMERA);
	mCurrentCamera = mCameraList.size() - 1;
	
	ApplyCamera();
	mViewport->setCamera(mCameraList[mCurrentCamera].first);

	Ogre::SceneNode *orbitNode = mSceneMgr->createSceneNode("OrbitCamera");
	Ogre::Camera *orbitCam = mSceneMgr->createCamera("OrbitCamera");
	orbitCam->setAspectRatio(Ogre::Real(mViewport->getActualWidth()) / Ogre::Real(mViewport->getActualHeight()));
	orbitCam->setFixedYawAxis(true);
	orbitNode->attachObject(orbitCam);
	orbitNode->setInheritOrientation(false);

	AddCamera(orbitCam, Chaos::ORBIT_CAMERA);

}
Esempio n. 10
0
    void Renderer::Render(const Camera& cam, IContext& c){
#if ZEUS_SAFE
        if (c.GetType() != IContext::OpenGL21) throw Exception("Context not supported by renderer: " + Utils::ToString<IContext::Type>(c.GetType()));
#endif
        Context& glContext = (Context&)c;

        // Draw scene
        ApplyCamera(cam, c);

        glEnable(GL_CULL_FACE);

        // @TODO Setup light. Lightmaps 'n shit
        glEnable(GL_COLOR_MATERIAL);
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
        Vector3 dir = Vector3(1,3,2);
        Normalize(dir);
        float hat[4]; dir.GetData(hat); hat[3] = 1.0f;
        glLightfv(GL_LIGHT0, GL_POSITION, hat);


        SceneObjectList::iterator itr = SceneObjectList::Begin();
        while (itr != SceneObjectList::End()){
            //Debug::Log("Rendering " + (*itr)->GetName());
            
            const ModelComponent* m = (*itr)->GetComponent<ModelComponent>();
            if (m){
                //Debug::Log((*itr)->GetName() + " has mesh");
                const ModelPropertiesPtr props = m->GetModelProperties();
                if (props) {
                    ModelProperties::Texture2DIterator itr = props->Texture2DBegin();
                    while (itr != props->Texture2DEnd()) {
                        const GLTexture2D* tex = glContext.AddTexture(itr->second);
                        glBindTexture(GL_TEXTURE_2D, tex->GetID());
                        glEnable(GL_TEXTURE_2D);
                        ++itr;
                    }
                } else {
                    glBindTexture(GL_TEXTURE_2D, 0);
                    glDisable(GL_TEXTURE_2D);
                }

                const MeshPtr mesh = m->GetMesh();
                if (mesh) {
                    const Transformation* t = (*itr)->GetComponent<Transformation>();
                    glPushMatrix();
                    Matrix4x4 m = t->GetAccumulatedMatrix();
                    glMultMatrixf(m.GetData());
                    
                    // @TODO Apply material

                    const GLMesh* mInfo = glContext.AddMesh(mesh);
                    RenderModel(*mInfo, glContext);
                    
                    glPopMatrix();
                }
            }
            ++itr;
        }

        glDisable(GL_COLOR_MATERIAL);
        glDisable(GL_LIGHTING);
        glDisable(GL_LIGHT0);

        glDisable(GL_CULL_FACE);
    }
Esempio n. 11
0
	void D3DRenderContext::ApplyCamera(const ICamera& camera) {
		ApplyCamera(dynamic_cast<const D3DCamera&>(camera));
	}