예제 #1
0
void XFileLoader::ReadData<glm::mat4>(istream& s, glm::mat4& d)
{
	float elems[16];
    ReadArray(s, elems, elems + 16);
    d = make_mat4(elems);
	SkipToken(s, XFileToken::Semicolon);
}
예제 #2
0
파일: Mat4fTest.cpp 프로젝트: knuke/GMath
  TEST_F(Mat4fTest, OperatorMultiplyMat4f)
  {
    for (int i = 0; i < RANDOM_ITERATION_COUNT; i++)
    {
      float* rnd = createRandomMat4f();
      float* rnd3 = createRandomMat4f();
      float rnd2 = createRandomF();

      Mat4f m(rnd);
      mat4 glm_m = make_mat4(rnd);
      Mat4f m2(rnd3);
      mat4 glm_m2 = make_mat4(rnd3);

      m = m * m2;
      glm_m = glm_m * glm_m2;

      cmpMat4f(value_ptr(glm_m), m);

      delete[] rnd;
    }
  }
예제 #3
0
draw_obj make_draw_field(material_t _material) {
    draw_obj ret;
    ret.mat_m = make_mat4();
    id_mat4(ret.mat_m);
    ret.mode = GL_QUADS;
    ret.vbo = field_vbo;
    ret.ibo = NULL;
    ret.count = field_w * field_h * 4 * 6;
    ret.material = _material;
    ret.free_mat_m = 0;
    ret.free_ibo = 0;
    return ret;
}
예제 #4
0
파일: Mat4fTest.cpp 프로젝트: knuke/GMath
  TEST_F(Mat4fTest, MethodCreateTranspose)
  {
    for (int i = 0; i < RANDOM_ITERATION_COUNT; i++)
    {
      float* rnd = createRandomMat4f();

      Mat4f rnd_m(rnd);
      mat4 rnd_glm_m = make_mat4(rnd);

      rnd_m = Mat4f::createTranspose(rnd_m);
      rnd_glm_m = glm::transpose(rnd_glm_m);

      cmpMat4f(value_ptr(rnd_glm_m), rnd_m);

      delete[] rnd;
    }
  }
예제 #5
0
파일: Mat4fTest.cpp 프로젝트: knuke/GMath
  TEST_F(Mat4fTest, OperatorMultiplyVec4f)
  {
    for (int i = 0; i < RANDOM_ITERATION_COUNT; i++)
    {
      float* rnd = createRandomMat4f();
      float* rnd2 = createRandomVec4f();

      Mat4f m(rnd);
      mat4 glm_m = make_mat4(rnd);
      Vec4f v(rnd2);
      vec4 glm_v = make_vec4(rnd2);

      v = m * v;
      glm_v = glm_m * glm_v;

      cmpVec4f(value_ptr(glm_v), v);

      delete[] rnd;
    }
  }
예제 #6
0
draw_obj make_draw_subfield(int x1, int y1, int x2, int y2, material_t _material) {
    draw_obj ret;
    ret.mat_m = make_mat4();
    id_mat4(ret.mat_m);
    ret.mode = GL_QUADS;
    ret.vbo = field_vbo;
    ret.ibo = malloc((x2 - x1) * (y2 - y1) * 4 * 6 * sizeof(unsigned int));
    int idx = 0;
    for (int i = x1; i < x2; ++i) {
        for (int j = y1; j < y2; ++j) {
            for (int k = 0; k < 4 * 6; ++k) {
                ((unsigned int *) ret.ibo)[idx++] = 4 * 6 * (i * field_h + j) + k;
            }
        }
    }
    ret.count = (x2 - x1) * (y2 - y1) * 4 * 6;
    ret.material = _material;
    ret.free_mat_m = 0;
    ret.free_ibo = 0;
    return ret;
}
예제 #7
0
void Display::draw()
{
	std::vector<Particle*> particles = theFluid->getParticles();
	int w = camera->getWidth();
	int h = camera->getHeight();

	//BEGIN render from light
	glUseProgram(shadowShaderProgram);
	glBindFramebuffer(GL_FRAMEBUFFER, fbo);
	// Clear previous frame values
	glClear( GL_DEPTH_BUFFER_BIT);
	
	//Disable color rendering, we only want to write to the Z-Buffer
	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
	glCullFace( GL_FRONT );

	camera->setViewport(SHADOW_MAP_SIZE, SHADOW_MAP_SIZE);
	glViewport(0,0,SHADOW_MAP_SIZE,SHADOW_MAP_SIZE);
	vec3 pos = camera->getPos();
	camera->setPos( vec3( lightPos.x, lightPos.y, lightPos.z ) );
	
	mat4 cmat = camera->getMat4();
	
	glUniformMatrix4fv(u_shadowProjMatrixLocation, 1, GL_FALSE, &cmat[0][0]);

	if( pos.y > 0 ) 
		world->draw( shadowPositionLocation, colorLocation, normalLocation, u_shadowModelMatrixLocation );
	//TODO: draw particles
	World::Shape * particle = new World::Cube();
	for (unsigned int i = 0; i < particles.size(); i++)
	{
		int pidx = particles.at( i )->getIndex();
		if( flags & pidx )
		{
			particle->clearMat();
			particle->translate(particles.at(i)->getPosition()); 
			particle->scale( vec3( 0.04 ) );
			particle->draw( shadowPositionLocation, colorLocation, normalLocation, u_shadowModelMatrixLocation );
		}
	}
	//END render from light

	//BEGIN render from camera
	glUseProgram(shaderProgram);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glUniform1i( u_shadowMapLocation, 7 );
	glActiveTexture(GL_TEXTURE7);
	glBindTexture(GL_TEXTURE_2D,depthTexture);

	float bias[16] = {	0.5, 0.0, 0.0, 0.0, 
						0.0, 0.5, 0.0, 0.0,
						0.0, 0.0, 0.5, 0.0,
						0.5, 0.5, 0.5, 1.0  };
	
	
	mat4 cameraMatrix = make_mat4( bias ) * cmat;
	glUniformMatrix4fv(u_shadowBiasMatrixLocation, 1, GL_FALSE, &cameraMatrix[0][0]);
	
	camera->setViewport(w, h);
	camera->setPos( pos );
	glViewport(0,0,w,h);
	glCullFace( GL_BACK );
	if( pos.y > 0 ) 
		world->draw( positionLocation, colorLocation, normalLocation, u_modelMatrixLocation );
	//TODO: draw particles
	vec3 red( 1,0,0 );
	vec3 blue( 0,0,1 );

	for (unsigned int i = 0; i < particles.size(); i++)
	{
		int pidx = particles.at( i )->getIndex();
		if( flags & pidx )
		{
			particle->clearMat();
			particle->translate(particles.at(i)->getPosition()); 
			particle->scale( vec3( 0.04 ) );

			if( flags & DFLAG_VEL )
			{
				particle->setColor( 0.1f+glm::clamp( particles.at(i)->getVelocity()*particles.at(i)->getVelocity()/5.0f, vec3(0.0), vec3(1.0) ) );
			}
			else if( flags & DFLAG_TEMP )
			{
				float alpha = ( particles.at( i )->getTemp() - 5 ) / 10;
				particle->setColor(alpha*red + (1-alpha)*blue);
			}
			else
			{
				particle->setColor( colorMap[pidx] );
			}
			particle->draw( positionLocation, colorLocation, normalLocation, u_modelMatrixLocation );
		}
	}	
	delete particle;
	
	//END render from camera
	glBindTexture(GL_TEXTURE_2D,0);
}