Esempio n. 1
0
static inline void mvp_matrix(mat4x4 model_view_projection_matrix, Params params, mat4x4 view_projection_matrix)
{

    mat4x4 model_matrix;
    mat4x4_identity(model_matrix);

    mat4x4 id;
    mat4x4_identity(id);


    mat4x4_translate(model_matrix, -params.anchor.x, -params.anchor.y, params.anchor.z);

    mat4x4 scaled;
    mat4x4_identity(scaled);
    mat4x4_scale_aniso(scaled, scaled, params.scale.x, -params.scale.y, params.scale.z);


    mat4x4 tmp;
    mat4x4_dup(tmp, model_matrix);

    mat4x4_mul(model_matrix, scaled, tmp);





    mat4x4 rotate;
    mat4x4_dup(rotate, id);
    mat4x4_rotate_Z2(rotate, id, deg_to_radf(-params.rotation));


    mat4x4_dup(tmp, model_matrix);

    mat4x4_mul(model_matrix, rotate, tmp);

    mat4x4_translate_independed(model_matrix, params.position.x, -params.position.y, params.position.z);



    mat4x4 model_matrix3;
    mat4x4_identity(model_matrix3);



    mat4x4 mm;

    mat4x4_mul(mm, model_matrix3, view_projection_matrix);

    mat4x4_mul(model_view_projection_matrix, mm, model_matrix);

    mat4x4_translate_independed(model_view_projection_matrix, 0, -y_offset/view_projection_matrix[3][3], 0);
}
Esempio n. 2
0
static void wolf_draw_wall(struct point2 *position, int x, int y)
{
	float wall_height = 1.5;

	glBindTexture(GL_TEXTURE_2D, textures[0]);

	glEnable(GL_TEXTURE_2D);

	mat4x4 mat;
	mat4x4_dup(mat, model_view);
	mat4x4_translate_in_place(mat, x, 0, y);

	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf((const GLfloat*) mat);

	for (int i = 0; i < 4; i++) {
		glBegin(GL_TRIANGLE_STRIP);
		glTexCoord2f(0.0f, 1.0f);
		glVertex3f(wolf_cube_mesh[i][0].x, 0.0f,        wolf_cube_mesh[i][0].y);
		glTexCoord2f(0.0f, 0.0f);
		glVertex3f(wolf_cube_mesh[i][1].x, wall_height, wolf_cube_mesh[i][1].y);
		glTexCoord2f(1.0f, 0.0f);
		glVertex3f(wolf_cube_mesh[i][2].x, wall_height, wolf_cube_mesh[i][2].y);
		glTexCoord2f(0.0f, 1.0f);
		glVertex3f(wolf_cube_mesh[i][0].x, 0.0f,        wolf_cube_mesh[i][0].y);
		glTexCoord2f(1.0f, 0.0f);
		glVertex3f(wolf_cube_mesh[i][2].x, wall_height, wolf_cube_mesh[i][2].y);
		glTexCoord2f(1.0f, 1.0f);
		glVertex3f(wolf_cube_mesh[i][3].x, 0.0f,        wolf_cube_mesh[i][3].y);
		glEnd();
	}
}
void setPrimitiveTransformation(Primitive *base, unsigned int position, unsigned int maxCount,
				mat4x4 matrix)
{
	assert(position < maxCount);
	assert(NULL != base);
	
	mat4x4_dup(base[position].transf, matrix);
}
Esempio n. 4
0
void mat4x4_translate_independed(mat4x4 m, float x, float y, float z)
{
    mat4x4 tr;
    mat4x4_identity(tr);

    mat4x4_translate_in_place(tr, x, y, z);


    //mat4x4 model_matrix2_tr;
    //mat4x4_mul(model_matrix2_tr, tr, m);


    mat4x4 m_dup;
    mat4x4_dup(m_dup, m);
    mat4x4_mul(m, tr, m_dup );
}
void setFaceTransformation(Faces *face, mat4x4 matrix)
{
	assert(NULL != face);
	mat4x4_dup(face->transf, matrix);
}
Esempio n. 6
0
void crop_rotate::toolbar(PapayaMemory* mem)
{
    ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(3, 0));
    if (ImGui::Button("-90")) { mem->crop_rotate.base_rotation--; }
    ImGui::SameLine();
    if (ImGui::Button("+90")) { mem->crop_rotate.base_rotation++; }
    ImGui::SameLine();
    ImGui::PopStyleVar();

    ImGui::PushItemWidth(85);
    ImGui::SliderAngle("Rotate", &mem->crop_rotate.slider_angle, -45.0f, 45.0f);
    ImGui::PopItemWidth();

    ImGui::SameLine(ImGui::GetWindowWidth() - 94); // TODO: Magic number alert
    ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(2, 0));

    if (ImGui::Button("Apply")) {
        bool size_changed = (mem->crop_rotate.base_rotation % 2 != 0);

        // Swap render texture and document texture handles
        if (size_changed) {
            int32 temp = mem->doc.width;
            mem->doc.width  = mem->doc.height;
            mem->doc.height = temp;

            mat4x4_ortho(mem->doc.proj_mtx,
                         0.f, (float)mem->doc.width,
                         0.f, (float)mem->doc.height,
                         -1.f, 1.f);
            mem->doc.inverse_aspect = (float)mem->doc.height /
                                      (float)mem->doc.width;
            GLCHK( glDeleteTextures(1, &mem->misc.fbo_sample_tex) );
            mem->misc.fbo_sample_tex = gl::allocate_tex(mem->doc.width,
                                                           mem->doc.height);
        }

        GLCHK( glDisable(GL_BLEND) );
        GLCHK( glViewport(0, 0, mem->doc.width, mem->doc.height) );

        // Bind and clear the frame buffer
        GLCHK( glBindFramebuffer(GL_FRAMEBUFFER, mem->misc.fbo) );
        GLCHK( glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                      GL_TEXTURE_2D, mem->misc.fbo_sample_tex, 0) );

        GLCHK( glClearColor(0.0f, 0.0f, 0.0f, 0.0f) );
        GLCHK( glClear(GL_COLOR_BUFFER_BIT) );

        mat4x4 m, r;
        // Rotate around center
        {
            Vec2 offset = Vec2(mem->doc.width  * 0.5f,
                               mem->doc.height * 0.5f);
            mat4x4_dup(m, mem->doc.proj_mtx);
            mat4x4_translate_in_place(m, offset.x, offset.y, 0.f);
            // mat4x4_rotate_Z(r, m, math::to_radians(-90));
            mat4x4_rotate_Z(r, m, mem->crop_rotate.slider_angle +
                            math::to_radians(90.0f * mem->crop_rotate.base_rotation));
            if (size_changed) {
                mat4x4_translate_in_place(r, -offset.y, -offset.x, 0.f);
            } else {
                mat4x4_translate_in_place(r, -offset.x, -offset.y, 0.f);
            }
        }

        // Draw the image onto the frame buffer
        GLCHK( glBindBuffer(GL_ARRAY_BUFFER, mem->meshes[PapayaMesh_RTTAdd].vbo_handle) );
        GLCHK( glUseProgram(mem->shaders[PapayaShader_DeMultiplyAlpha].handle) );
        GLCHK( glUniformMatrix4fv(mem->shaders[PapayaShader_ImGui].uniforms[0],
                                  1, GL_FALSE, (GLfloat*)r) );
        gl::set_vertex_attribs(mem->shaders[PapayaShader_DeMultiplyAlpha]);
        GLCHK( glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)mem->doc.texture_id) );
        GLCHK( glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) );
        GLCHK( glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) );
        GLCHK( glDrawArrays (GL_TRIANGLES, 0, 6) );

        uint32 temp = mem->misc.fbo_sample_tex;
        mem->misc.fbo_sample_tex = mem->doc.texture_id;
        mem->doc.texture_id = temp;

        if (size_changed) {
            core::resize_doc(mem, mem->doc.width, mem->doc.height);

            // Reposition canvas to maintain apparent position
            int32 delta = math::round_to_int((mem->doc.height - mem->doc.width)
                    * 0.5f * mem->doc.canvas_zoom);
            mem->doc.canvas_pos.x += delta;
            mem->doc.canvas_pos.y -= delta;
        }

        // Reset stuff
        GLCHK( glBindFramebuffer(GL_FRAMEBUFFER, 0) );
        GLCHK( glViewport(0, 0, (int32)ImGui::GetIO().DisplaySize.x, (int32)ImGui::GetIO().DisplaySize.y) );

        mem->crop_rotate.slider_angle = 0.f;
        mem->crop_rotate.base_rotation = 0;
    }

    ImGui::SameLine();
    if (ImGui::Button("Cancel")) {
        mem->crop_rotate.slider_angle = 0.f;
        mem->crop_rotate.base_rotation = 0;
    }

    ImGui::PopStyleVar();
}