コード例 #1
0
ファイル: qikdraw.cpp プロジェクト: qpHalcy0n/Quad2012
void CSprite::Render(vec3f camPos)
{
	vec4f pos[4];
	float h2 = height * 0.5f;
	float w2 = width * 0.5f;
	pos[0].set(center.x - w2, center.y - h2, center.z, 1.0f);
	pos[1].set(center.x + w2, center.y - h2, center.z, 1.0f);
	pos[2].set(center.x + w2, center.y + h2, center.z, 1.0f);
	pos[3].set(center.x - w2, center.y + h2, center.z, 1.0f);

	vec3f look = camPos - center;
	look.normalize();
	vec3f up(0.0f, 1.0f, 0.0f);
	vec3f right = up.crossProd(look);
	up = look.crossProd(right);

	mat4f m, t, nt, f, R;
	R.loadZRotation(angle);

	m.m[0] = right.x;		m.m[4] = up.x;		m.m[8] = look.x;		m.m[12] = 0.0f;
	m.m[1] = right.y;		m.m[5] = up.y;		m.m[9] = look.y;		m.m[13] = 0.0f;
	m.m[2] = right.z;		m.m[6] = up.z;		m.m[10] = look.z;		m.m[14] = 0.0f;
	m.m[3] = 0.0f;			m.m[7] = 0.0f;		m.m[11] = 0.0f;			m.m[15] = 1.0f;

	m *= R;

	nt.loadTranslation(-center.x, -center.y, -center.z);
	t.loadTranslation(center.x, center.y, center.z);
	float verts[20] = { pos[0].x, pos[0].y, pos[0].z, 0.0f, 0.0f,
						pos[1].x, pos[1].y, pos[1].z, 1.0f, 0.0f,
						pos[2].x, pos[2].y, pos[2].z, 1.0f, 1.0f,
						pos[3].x, pos[3].y, pos[3].z, 0.0f, 1.0f };

	mat4_mul_mat4(m.m, nt.m, f.m);
	mat4_mul_mat4(t.m, f.m, m.m);
	pushMatrix(MATRIX_MODEL, m);
	unsigned int indices[6] = { 0, 1, 2, 0, 2, 3 };

	float color[4] = {r, g, b, a};

	g_pTexturedEffect->Bind();
	bool invert = false;
	g_pTexturedEffect->BindBool("invert", invert);
	g_pTexturedEffect->BindFloat("globalColor", color, 4);
	g_pTexturedEffect->BindStateMatrix("MVP", MATRIX_MODEL | MATRIX_VIEW | MATRIX_PROJECTION);
	g_pTexturedEffect->BindTexture("s0", texID);

	glEnableVertexAttribArray(LOC_POSITION);
	glEnableVertexAttribArray(LOC_TEXCOORD0);
	glVertexAttribPointer(LOC_POSITION, 3, GL_FLOAT, GL_FALSE, 20, verts);
	glVertexAttribPointer(LOC_TEXCOORD0, 2, GL_FLOAT, GL_TRUE, 20, (float*)&verts[3]);
	glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, indices);
	glDisableVertexAttribArray(LOC_POSITION);
	glDisableVertexAttribArray(LOC_TEXCOORD0);

	g_pTexturedEffect->EvictTextures();
	g_pTexturedEffect->Unbind();
	popMatrix(MATRIX_MODEL);
}
コード例 #2
0
void DebugEmitterComponent::_CalculateNodeTransform(std::stack<mat4*>& stack, mat4* res)
{
	if (stack.size() == 1)
	{
		auto top = stack.top();
		stack.pop();

		mat4 result;
		mat4_copy(result, *top);
		mat4_copy(*res, result);
		float a = 0;
	}
	else
	{
		mat4 childRes;
		auto top = stack.top();
		stack.pop();
		_CalculateNodeTransform(stack, &childRes);

		mat4 result;

		mat4_mul_mat4(*top, childRes, result);
		mat4_copy(*res, result);
		float a = 0;
	}
}
コード例 #3
0
ファイル: quickshader.cpp プロジェクト: inkadnb/Mooball
void CShaderObject::BindStateMatrix(const char* paramName, unsigned int matrix)
{
    // Check and validate bind status //
	if(!m_bIsBound)
		return;

    // Get and validate bind point //
	int bind_point = glGetUniformLocation(m_shaderObject, paramName);
	if(bind_point < 0)
		return;

	mat4 MV, P, F;
	mat4_load_identity(MV);
	mat4_load_identity(P);

	if(matrix & MATRIX_MODELVIEW)
		glGetFloatv(GL_MODELVIEW_MATRIX, MV);
	if(matrix & MATRIX_PROJECTION)
		glGetFloatv(GL_PROJECTION_MATRIX, P);

	mat4_mul_mat4(P, MV, F);

	if(matrix & MATRIX_TRANSPOSE)
		mat4_transpose(F);

	glUniformMatrix4fv(bind_point, 1, false, F);
}
コード例 #4
0
ファイル: renderer.c プロジェクト: ElArtista/EnergyCore
static void upload_gbuffer_uniforms(GLuint shdr, float viewport[2], mat4* view, mat4* proj)
{
    glUniform1i(glGetUniformLocation(shdr, "gbuf.depth"), 0);
    glUniform1i(glGetUniformLocation(shdr, "gbuf.normal"), 1);
    glUniform1i(glGetUniformLocation(shdr, "gbuf.albedo"), 2);
    glUniform1i(glGetUniformLocation(shdr, "gbuf.roughness_metallic"), 3);
    glUniform2fv(glGetUniformLocation(shdr, "u_screen"), 1, viewport);
    mat4 inv_view_proj = mat4_inverse(mat4_mul_mat4(*proj, *view));
    glUniformMatrix4fv(glGetUniformLocation(shdr, "u_inv_view_proj"), 1, GL_FALSE, inv_view_proj.m);
}
コード例 #5
0
ファイル: animation.c プロジェクト: ghosthamlet/Corange
animation* ani_load_file(char* filename) {
  
  int state = STATE_LOAD_EMPTY;
  
  animation* a =  animation_new();
  skeleton* base = skeleton_new();
  frame* f = NULL;
  
  SDL_RWops* file = SDL_RWFromFile(filename, "r");
  
  if(file == NULL) {
    error("Could not load file %s", filename);
  }
  
  char line[1024];
  while(SDL_RWreadline(file, line, 1024)) {
    
    if (state == STATE_LOAD_EMPTY) {
      
      int version;
      if (sscanf(line, "version %i", &version) > 0) {
        if (version != 1) {
          error("Can't load ani file '%s'. Don't know how to load version %i\n", filename, version);
        }
      }
      
      if (strstr(line, "nodes")) {
        state = STATE_LOAD_NODES;
      }
      
      if (strstr(line, "skeleton")) {
        state = STATE_LOAD_SKELETON;
      }
    }
    
    else if (state == STATE_LOAD_NODES) {
      char name[1024];
      int id, parent;
      if (sscanf(line, "%i \"%[^\"]\" %i", &id, name, &parent) == 3) {
        skeleton_joint_add(base, name, parent);
      }
      
      if (strstr(line, "end")) {
        state = STATE_LOAD_EMPTY;
      }
    }
    
    else if (state == STATE_LOAD_SKELETON) {
    
      float time;
      if (sscanf(line, "time %f", &time) == 1) {
        f = animation_add_frame(a, base->rest_pose);
      }
    
      int id;
      float x, y, z, rx, ry, rz;
      if (sscanf(line, "%i %f %f %f %f %f %f", &id, &x, &y, &z, &rx, &ry, &rz) > 0) {
        
        f->joint_positions[id] = vec3_new(x, z, y);
        
        mat4 rotation = mat4_rotation_euler(rx, ry, rz);
        mat4 handedflip = mat4_new(1,0,0,0,
                                   0,0,1,0,
                                   0,1,0,0,
                                   0,0,0,1);
      
        rotation = mat4_mul_mat4(handedflip, rotation);
        rotation = mat4_mul_mat4(rotation, handedflip);
        rotation = mat4_transpose(rotation);
        
        f->joint_rotations[id] = mat4_to_quat(rotation);
        
      }
      
      if (strstr(line, "end")) {
        state = STATE_LOAD_EMPTY;
      }
      
    }
  }
  
  SDL_RWclose(file);
  
  skeleton_delete(base);
  
  return a;
}
コード例 #6
0
ファイル: camera.c プロジェクト: AntonioCS/Corange
mat4 camera_view_proj_matrix(camera* c, float aspect_ratio) {
  mat4 view = camera_view_matrix(c);
  mat4 proj = camera_proj_matrix(c, aspect_ratio);
  return mat4_mul_mat4(view, proj);
}
コード例 #7
0
ファイル: camera.c プロジェクト: Drooids/Corange
mat4 camera_view_proj_matrix(camera* c) {
  mat4 view = camera_view_matrix(c);
  mat4 proj = camera_proj_matrix(c);
  return mat4_mul_mat4(view, proj);
}