コード例 #1
0
ファイル: DynamicVehicle.cpp プロジェクト: minsulander/moon
	void DynamicVehicle::exit()
	{
		unbindControls();
		if (entrycam.valid()) {
			entrycam->setPosition( getWorldTransformMatrix().getTrans() + getWorldTransformMatrix().getRotate() * entrypos);
			entrycam->track(NULL);
			entrycam->pointAt(this);
			entrycam->activate();
		} else
			CameraManipulator::instance().setNoActiveCamera();
		if (trackcam.valid())
			trackcam->track(NULL);
		if (Scenario::current())
			Scenario::current()->removeComponent(trackcam.get());
		// Export current vehicle to Lua interpreter
		Interpreter::instance().pushGlobal("objects");
		Interpreter::instance().setTable("vehicle", NULL, "nil");
		// Set model visbility interior/extiror
		setModelVisibilityWithTag("interior", false);
		setModelVisibilityWithTag("exterior", true);

		setOwner(NULL);
		
		Vehicle::exit();
	}
コード例 #2
0
ファイル: DynamicVehicle.cpp プロジェクト: minsulander/moon
	void DynamicVehicle::enter()
	{
		if (!drivercam.valid()) {
			drivercam = dynamic_cast<Camera*> (findRelatedByTag("driver"));
			if (!drivercam.valid()) {
				dout(ERROR) << "No driver camera found in vehicle '" << getName() << "'\n";
				return;
			}
		}
		entrycam = CameraManipulator::instance().getActiveCamera();
		if (entrycam.valid())
			entrypos = osg::Matrix::inverse(getWorldTransformMatrix()).getRotate() * (entrycam->getWorldTransformMatrix().getTrans() - getWorldTransformMatrix().getTrans());
		drivercam->activate();
		
		if (!exitControl.valid())
			exitControl = new ListenerControl("Exit", Control::MOMENTARY, this);
		if (!cameraModeControl.valid())
			cameraModeControl = new ListenerControl("CameraMode", Control::MOMENTARY, this);
		bindControls();
		if (isRemote() && getOwner())
			dout(WARN) << "Entered remote vehicle " << getName() << " owned by " << (getOwner() ? getOwner()->toString() : "server") << "\n";
		setOwner(moonet::Client::me());
		// Export current vehicle to Lua interpreter
		Interpreter::instance().pushGlobal("objects");
		Interpreter::instance().setTable("vehicle", this, "moon::KinematicObject");
		// Set model visbility interior/extiror
		setModelVisibilityWithTag("interior", true);
		setModelVisibilityWithTag("exterior", false);

		Vehicle::enter();
	}
コード例 #3
0
ファイル: BakedTerrain.cpp プロジェクト: xHaVoK87/kit
void kit::BakedTerrain::renderShadows(glm::mat4 const & viewMatrix, glm::mat4 const & projectionMatrix)
{
  glDisable(GL_CULL_FACE);
  auto program = kit::Model::getShadowProgram(false, false, false);
  program->setUniformMat4("uniform_mvpMatrix", projectionMatrix * viewMatrix * getWorldTransformMatrix());
  program->use();
  renderGeometry();
}
コード例 #4
0
ファイル: DynamicVehicle.cpp プロジェクト: minsulander/moon
	DynamicVehicle::~DynamicVehicle()
	{
		if (currentVehicle == this) {
			unbindControls();
			if (entrycam.valid()) {
				entrycam->setPosition( getWorldTransformMatrix().getTrans() + getWorldTransformMatrix().getRotate() * entrypos);
				entrycam->track(NULL);
				entrycam->pointAt(this);
				entrycam->activate();
			} else
				CameraManipulator::instance().setNoActiveCamera();
			if (trackcam.valid())
				trackcam->track(NULL);
			if (Scenario::current())
				Scenario::current()->removeComponent(trackcam.get());
		}
	}
コード例 #5
0
ファイル: Model.cpp プロジェクト: xHaVoK87/kit
void kit::Model::renderShadows(glm::mat4 const & viewMatrix, glm::mat4 const & projectionMatrix)
{
  for (auto &currSubmeshIndex : m_mesh->getSubmeshEntries())
  {
    auto & currMaterial = currSubmeshIndex.second.m_material;
    auto & currSubmesh = currSubmeshIndex.second.m_submesh;

    if (!currMaterial->getCastShadows())
    {
      continue;
    }

    if (currMaterial->getDoubleSided())
    {
      glDisable(GL_CULL_FACE);
    }
    else
    {
      glEnable(GL_CULL_FACE);
      glCullFace(GL_BACK);
    }

    bool O = (currMaterial->getOpacityMask() != nullptr);
    bool S = (m_skeleton != nullptr);
    bool I = m_instanced;

    auto currProgram = kit::Model::getShadowProgram(S, O, I);

    currProgram->setUniformMat4("uniform_mvpMatrix", projectionMatrix * viewMatrix * getWorldTransformMatrix());

    if(O)
    {
      currProgram->setUniformTexture("uniform_opacityMask", currMaterial->getOpacityMask().get());
    }

    if(S)
    {
      currProgram->setUniformMat4v("uniform_bones", m_skeleton->getSkin());
    }
    
    if(I)
    {
      currProgram->setUniformMat4v("uniform_instanceTransform", m_instanceTransform);
      currProgram->use();
      currSubmesh->renderGeometryInstanced(m_instanceTransform.size());
    }
    else
    {
      currProgram->use();
      currSubmesh->renderGeometry();
    }
  }
}
コード例 #6
0
ファイル: Model.cpp プロジェクト: xHaVoK87/kit
glm::vec3 kit::Model::getBoneWorldPosition(const std::string&bone)
{
  if (!m_skeleton)
  {
    KIT_ERR("Warning: tried to get bone position from non-skinned model");
    return glm::vec3();
  }

  kit::Skeleton::Bone * currBone = m_skeleton->getBone(bone);
  if (!currBone)
  {
    KIT_ERR("Warning: tried to get bone position from non-existent bone");
    return glm::vec3();
  }

  return glm::vec3( getWorldTransformMatrix() * currBone->m_globalTransform * glm::vec4(0.0, 0.0, 0.0, 1.0));
}
コード例 #7
0
ファイル: BakedTerrain.cpp プロジェクト: xHaVoK87/kit
void kit::BakedTerrain::renderDeferred(kit::Renderer * renderer)
{
  if(!m_valid)
  {
    return;
  }

  glm::mat4 modelViewMatrix = renderer->getActiveCamera()->getViewMatrix() * getWorldTransformMatrix();
  glm::mat4 modelViewProjectionMatrix = renderer->getActiveCamera()->getProjectionMatrix() * renderer->getActiveCamera()->getViewMatrix() * getWorldTransformMatrix();

  glDisable(GL_BLEND);
  glDisable(GL_CULL_FACE);
  //glCullFace(GL_BACK);

  m_program->setUniformMat4("uniform_mvMatrix", modelViewMatrix);
  m_program->setUniformMat4("uniform_mvpMatrix", modelViewProjectionMatrix);

  m_program->use();
  
  renderGeometry();
}
コード例 #8
0
ファイル: Model.cpp プロジェクト: xHaVoK87/kit
glm::quat kit::Model::getBoneWorldRotation(const std::string&bone)
{
  if (!m_skeleton)
  {
    KIT_ERR("Warning: tried to get bone rotation from non-skinned model");
    return glm::quat();
  }

  kit::Skeleton::Bone* currBone = m_skeleton->getBone(bone);
  if (!currBone)
  {
    KIT_ERR("Warning: tried to get bone rotation from non-existent bone");
    return glm::quat();
  }

  // TODO: This (fodderFix) is needed for badly exported/imported models. Fix our importer/blenders exporter/whatever and then remove this.
  glm::quat fodderFix;
  fodderFix = glm::rotate(fodderFix, glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f));
  //fodderFix = glm::rotate(fodderFix, glm::radians(180.0f), glm::vec3(0.0f, 0.0f, 1.0f));

  return glm::quat_cast(getWorldTransformMatrix() * currBone->m_globalTransform) * fodderFix;
}
コード例 #9
0
ファイル: Model.cpp プロジェクト: xHaVoK87/kit
void kit::Model::renderReflection(Renderer * renderer, const glm::mat4& viewMatrix, const glm::mat4& projectionMatrix)
{
  kit::Mesh::RenderConfig conf;
  
  conf.viewMatrix = viewMatrix;
  conf.projectionMatrix = projectionMatrix;
  conf.modelMatrix = getWorldTransformMatrix();
  conf.renderPass = kit::Mesh::RenderPass::Reflection;
  conf.renderer = renderer;
  
  if(m_skeleton)
  {
    conf.skinTransform = m_skeleton->getSkin();
  }
  
  if(m_instanced)
  {
    conf.instanceTransform = m_instanceTransform;
  }
  
  m_mesh->render(conf);
}
コード例 #10
0
ファイル: Model.cpp プロジェクト: xHaVoK87/kit
void kit::Model::renderForward(kit::Renderer* renderer)
{
  kit::Mesh::RenderConfig conf;
 
  auto camera = renderer->getActiveCamera();
  conf.viewMatrix = camera->getViewMatrix();
  conf.projectionMatrix =  camera->getProjectionMatrix();
  conf.modelMatrix = getWorldTransformMatrix();
  conf.renderPass = kit::Mesh::RenderPass::Forward;
  conf.renderer = renderer;
  
  if(m_skeleton)
  {
    conf.skinTransform = m_skeleton->getSkin();
  }
  
  if(m_instanced)
  {
    conf.instanceTransform = m_instanceTransform;
  }
  
  m_mesh->render(conf);
}
コード例 #11
0
ファイル: Water.cpp プロジェクト: xHaVoK87/kit
void kit::Water::renderForward(kit::Renderer* renderer)
{

  // Set OpenGL states
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  //glBlendFunc(GL_ONE, GL_ONE);
  glEnable(GL_CULL_FACE);
  glCullFace(GL_FRONT);
  glEnable(GL_DEPTH_TEST);
  glDepthMask(GL_TRUE);


  
  // Calculate matrices to pass into shader
  glm::mat4 modelMatrix = getWorldTransformMatrix();
  glm::mat4 viewMatrix = renderer->getActiveCamera()->getViewMatrix();
  glm::mat4 invViewMatrix = glm::inverse(viewMatrix);
  glm::mat4 projectionMatrix = renderer->getActiveCamera()->getProjectionMatrix();
  glm::mat4 mvMatrix = viewMatrix * modelMatrix;
  //glm::mat4 normalMatrix = glm::transpose(glm::inverse(mvMatrix));
  glm::mat4 mvpMatrix = projectionMatrix * viewMatrix * modelMatrix;
  
  // Calculate px and py to linearize depth in shader
  glm::vec2 clip = renderer->getActiveCamera()->getClipRange();
  float znear = clip.x;
  float zfar = clip.y;
  float px = (-zfar * znear) / (zfar - znear);
  float py = zfar / (zfar - znear);
  

  // Render below
  if(renderer->getActiveCamera()->getWorldPosition().y < getWorldPosition().y)
  {
    // Render surface from below
    {
      // Set OpenGL states
      glCullFace(GL_BACK);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glEnable(GL_CULL_FACE);
      glEnable(GL_DEPTH_TEST);
      glDepthMask(GL_TRUE);

      //glStencilFunc(GL_ALWAYS, 1, 0xFF); // Set any stencil to 1
      //glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
      //glStencilMask(0xFF); // Write to stencil buffer
      //glClear(GL_STENCIL_BUFFER_BIT); // Clear stencil buffer (0 by default)
      
      // Use our shader program, and update variables
      m_belowProgram->setUniformTexture("uniform_colormap", renderer->getAccumulationCopy()->getColorAttachment(0));
      m_belowProgram->setUniformTexture("uniform_depthmap", renderer->getAccumulationCopy()->getDepthAttachment());
      m_belowProgram->setUniformTexture("uniform_positionmap", renderer->getPositionBuffer()->getColorAttachment(0));
      m_belowProgram->setUniformMat4("uniform_invViewMatrix", invViewMatrix);
      m_belowProgram->setUniform3f("uniform_camerawp", renderer->getActiveCamera()->getWorldPosition());

      m_belowProgram->setUniformTexture("uniform_normalmapA", m_normalmapA.get());
      m_belowProgram->setUniformTexture("uniform_normalmapB", m_normalmapB.get());
      //m_belowProgram->setUniformTexture("uniform_heightmapA", m_heightmapA.get());
      //m_belowProgram->setUniformTexture("uniform_heightmapB", m_heightmapB.get());

      m_belowProgram->setUniformMat4("uniform_mvpMatrix", mvpMatrix);
      m_belowProgram->setUniformMat4("uniform_mvMatrix", mvMatrix);
      
      m_belowProgram->use();
      
      glBindVertexArray(m_glVao);
      glDrawElements(GL_TRIANGLES, m_indexCount, GL_UNSIGNED_INT, (void*)0);
    }
    
    // Render fullscreen effects
    {
      renderer->updateAccumulationCopy();
      renderer->updatePositionBuffer();
      
      glDisable(GL_BLEND);
      glEnable(GL_CULL_FACE);
      glCullFace(GL_BACK);
      glDisable(GL_DEPTH_TEST);
      glDepthMask(GL_FALSE);
      //glStencilFunc(GL_EQUAL, 1, 0xFF); // Pass test if stencil value is 1
      //glStencilMask(0x00); // Don't write anything to stencil buffer
      
      m_underwaterProgram->setUniformTexture("uniform_normalmapA", m_normalmapA.get());
      m_underwaterProgram->setUniformTexture("uniform_normalmapB", m_normalmapB.get());
      m_underwaterProgram->setUniformTexture("uniform_colormap", renderer->getAccumulationCopy()->getColorAttachment(0));
      m_underwaterProgram->setUniformTexture("uniform_positionmap", renderer->getPositionBuffer()->getColorAttachment(0));
      m_underwaterProgram->setUniformMat4("uniform_invViewMatrix", invViewMatrix);
      m_underwaterProgram->setUniformTexture("uniform_vignette", m_vignette.get());
      m_underwaterProgram->use();

      m_underwaterQuad->setBlending(false);
      m_underwaterQuad->render(m_underwaterProgram);
    }

  }
  // Render above
  else
  {
    // Use our shader program, and update variables
    m_program->setUniformTexture("uniform_colormap", renderer->getAccumulationCopy()->getColorAttachment(0));
    m_program->setUniformTexture("uniform_depthmap", renderer->getAccumulationCopy()->getDepthAttachment());
    m_program->setUniformTexture("uniform_positionmap", renderer->getPositionBuffer()->getColorAttachment(0));
    m_program->setUniformMat4("uniform_invViewMatrix", invViewMatrix);
    m_program->setUniformMat4("uniform_viewMatrix", viewMatrix);
    //m_program->setUniform3f("uniform_camerawp", renderer->getActiveCamera()->getWorldPosition());
    //m_program->setUniform3f("uniform_camerafwd", renderer->getActiveCamera()->getWorldForward());

    
    
    m_program->setUniformTexture("uniform_normalmapA", m_normalmapA.get());
    m_program->setUniformTexture("uniform_normalmapB", m_normalmapB.get());
    m_program->setUniformTexture("uniform_reflection", renderer->getReflectionMap());
    //m_program->setUniformTexture("uniform_heightmapA", m_heightmapA.get());
    //m_program->setUniformTexture("uniform_heightmapB", m_heightmapB.get());

    m_program->setUniformMat4("uniform_mvpMatrix", mvpMatrix);
    m_program->setUniformMat4("uniform_mvMatrix", mvMatrix);
    
    m_program->use();

    glBindVertexArray(m_glVao);
    glDrawElements(GL_TRIANGLES, m_indexCount, GL_UNSIGNED_INT, (void*)0);
  }
  
}