Exemplo n.º 1
0
void lndr_gen_jet_mv_matrix(Lander *lander)
{
    if(lander->jetState == JS_OFF)
        return;

    float scale = 0;
    if(lander->jetState == JS_INCREASING || lander->jetState == JS_DECREASING)
        scale = lander->jetFrames / FLAME_GROW_RATE;
    else if(lander->jetState == JS_ON)
    {
        if(lander->jetFrames < 10)
            return;

        lander->jetFrames = 0;

        int rnd = rand() % 6 - 3;
        scale = 1.0 + (0.07 * rnd);
    }

    mat4x4 ident, temp;
    mat4x4_identity(ident);

    mat4x4_translate_in_place(ident, 0, -0.3529412, 0);
    mat4x4_scale_aniso(temp, ident, 1.0, scale, 1.0);
    mat4x4_translate_in_place(temp, 0, 0.3529412, 0);

    mat4x4_transpose(lander->jetMatrix, temp);
}
Exemplo 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();
	}
}
Exemplo n.º 3
0
static void
recalculate_matrices(struct ball *b)
{
    mat4x4_identity(b->model_matrix);
    mat4x4_translate_in_place(b->model_matrix, b->x, b->y, b->z);
    mat4x4_scale_aniso(b->model_matrix, b->model_matrix, SCALE_FACTOR, SCALE_FACTOR, SCALE_FACTOR);

    mat4x4_invert(b->normal_matrix, b->model_matrix);
    mat4x4_transpose(b->normal_matrix, b->normal_matrix);

}
Exemplo n.º 4
0
void cubeUpdate(CubeRenderPacket* cube, vec3 rot, float angle, float x, float y, float z, float* view, float* proj)
{
    static mat4x4 temp;
    memcpy(cube->transforms.view, view, 16 * sizeof(float));
    memcpy(cube->transforms.proj, proj, 16 * sizeof(float));

    vec3_norm(rot, rot);

    mat4x4_identity(cube->transforms.world);
    mat4x4_translate_in_place(cube->transforms.world, x, y, z);
    mat4x4_rotate(cube->transforms.world, cube->transforms.world, rot[0], rot[1], rot[2], angle);

    mat4x4_mul(temp, cube->transforms.view, cube->transforms.world);
    mat4x4_mul(cube->transforms.proj_view_world, cube->transforms.proj, temp);
    gfxBindUniformBuffer(cube->ubo, &cube->transforms, sizeof(struct Transforms), 0);
}
Exemplo n.º 5
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 );
}
Exemplo n.º 6
0
/* TODO/FIXME - finish */
void matrix_4x4_lookat(math_matrix_4x4 *out,
      vec3_t eye,
      vec3_t center,
      vec3_t up)
{
   vec3_t s, t, f;

   vec3_copy(&f[0], center);
   vec3_subtract(&f[0], eye);
   vec3_normalize(&f[0]);

   vec3_cross(&s[0], &f[0], up);
   vec3_normalize(&s[0]);

   vec3_cross(&t[0], &s[0], f);

   memset(out, 0, sizeof(*out));

   MAT_ELEM_4X4(*out, 0, 0) = s[0];
   MAT_ELEM_4X4(*out, 0, 1) = t[0];
   MAT_ELEM_4X4(*out, 0, 2) = -f[0];

   MAT_ELEM_4X4(*out, 1, 0) = s[1];
   MAT_ELEM_4X4(*out, 1, 1) = t[1];
   MAT_ELEM_4X4(*out, 1, 2) = -f[1];

   MAT_ELEM_4X4(*out, 2, 0) = s[2];
   MAT_ELEM_4X4(*out, 2, 1) = t[2];
   MAT_ELEM_4X4(*out, 2, 2) = -f[2];

   MAT_ELEM_4X4(*out, 3, 3) = 1.f;

#if 0
   mat4x4_translate_in_place(m, -eye[0], -eye[1], -eye[2]);
#endif

}
Exemplo n.º 7
0
void G_Tick() {
	BufferTextInput();

	if (G_ContainsHeightMap(*((heightmap*)((object*)G_staticMeshes.first->value)->shape), G_camPos)) 
		printf("\rYes\n");

	vec3 dir = {0, 0, 0};
	float moveSpeed = G_moveSpeed * (SYS_deltaMillis / 1000.0);
	float rotSpeed = G_rotSpeed * (SYS_deltaMillis / 1000.0);
	if (IN_IsKeyPressed(IN_W))		dir[2]		-= moveSpeed;
	if (IN_IsKeyPressed(IN_A))		dir[0]		-= moveSpeed;
	if (IN_IsKeyPressed(IN_S))		dir[2]		+= moveSpeed;
	if (IN_IsKeyPressed(IN_D))		dir[0]		+= moveSpeed;
	if (IN_IsKeyPressed(IN_UP))		dir[1]		+= moveSpeed;
	if (IN_IsKeyPressed(IN_DOWN))	dir[1]		-= moveSpeed;
	if (IN_IsKeyPressed(IN_RIGHT))	G_camRot[1]	+= rotSpeed;
	if (IN_IsKeyPressed(IN_LEFT))	G_camRot[1]	-= rotSpeed;
	if (IN_IsKeyPressed(IN_PITCH_UP))	G_camRot[0]	+= rotSpeed;
	if (IN_IsKeyPressed(IN_PITCH_DOWN))	G_camRot[0]	-= rotSpeed;
	if (IN_IsKeyPressed(IN_ACTION)) {
		if (!actionHeld) {
			Shoot();
			actionHeld = true;
		}
	}else actionHeld = false;
	if (IN_IsKeyPressed(IN_TOGGLE)) {
		if (!toggleHeld) {
			ads = ads ? false : true;
			lastAdsTime = SYS_TimeMillis() / 1000.0;
			toggleHeld = true;
		}
	}else toggleHeld = false;
	if (IN_IsKeyPressed(IN_CHAT)) {
		if (!chatHeld) {
			IN_StartTextInput();
			C_console.inputActive = true;
			chatHeld = true;
		}
	}else chatHeld = false;
	
	if (IN_IsKeyPressed(IN_RELOAD)) {
		ReloadLevel();
	}
	
	if (G_camRot[0] > PITCH_LIMIT) G_camRot[0] = PITCH_LIMIT;
	else if (G_camRot[0] < -PITCH_LIMIT) G_camRot[0] = -PITCH_LIMIT;
	
	float c = cos(G_camRot[1]);
	float s = sin(G_camRot[1]);
	G_camPos[0] += -dir[2] * s + dir[0] * c;
	G_camPos[2] += dir[2] * c + dir[0] * s;
	G_camPos[1] += dir[1];
	
	mat4x4_translate(G_gunMat, G_camPos[0], G_camPos[1], G_camPos[2]);
	mat4x4_rotate_Y(G_gunMat, G_gunMat, G_camRot[1] + M_PI);
	mat4x4_rotate_X(G_gunMat, G_gunMat, -G_camRot[0]);

	double d, f;
	{
		termf terms[2] = {{2, 2}, {-1, 4}};
		d = G_Valuef((function) {0, 1, 2, terms},
							(SYS_TimeMillis() / 1000.0 - lastAdsTime) * 5);
		if (ads) d = 1 - d;
	}
	{
		termf terms[2] = {{1, 0.3}, {-1, 1}};
		f = G_Valuef((function) {0, 1, 2, terms},
							(SYS_TimeMillis() / 1000.0 - lastShootTime) * 5);
	}
	V_SetProj(fov->value * d + adsFov->value * (1 - d));
	vec3 resultant = {0, 0, 0};
	for (int i = 0; i < 3; i++) {
		resultant[i] += defGunPos[i];
		resultant[i] += hipGunPos[i] * d;
		resultant[i] += fireGunPos[i] * f;
		resultant[i] += hipFireGunPos[i] * d * f;
	}
	resultant[0] += d * 0.01 * cos(SYS_TimeMillis() / 2000.0);
	resultant[1] += d * 0.005 * cos(SYS_TimeMillis() / 1500.0);
	mat4x4_translate_in_place(G_gunMat, resultant[0], resultant[1], resultant[2]);
	
	HandleSmoke();

	if (IN_IsKeyPressed(IN_RELOAD)) V_reloadShaders = true;
}
Exemplo n.º 8
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();
}