当前位置: 首页>>代码示例>>C++>>正文


C++ mat4::perspective方法代码示例

本文整理汇总了C++中mat4::perspective方法的典型用法代码示例。如果您正苦于以下问题:C++ mat4::perspective方法的具体用法?C++ mat4::perspective怎么用?C++ mat4::perspective使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mat4的用法示例。


在下文中一共展示了mat4::perspective方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: idle

void GLAppMain::idle()
{
    float ratio = (float)window_width / (float) window_height;
    projection.perspective(45,ratio,1,10000);

    vec3 lat = vec3(0,1,0)^lookat;
    lat.normalize();

    // keyboard events
    if(keys[KEY_ESC]) exit();
    if(keys[' ']){ 
	    goon = !goon;
	    keys[' '] = 0;
	  }
    if(keys[KEY_UP]) {
        pos += lookat*(50/fps);
        keys[KEY_UP] = 0;
    }
    if(keys[KEY_DOWN]) {
        pos -= lookat*(50/fps);
        keys[KEY_DOWN] = 0;
    }
    if(keys[KEY_LEFT]) {
        pos += lat*(50/fps);
        keys[KEY_LEFT] = 0;
    }
    if(keys[KEY_RIGHT]) {
        pos -= lat*(50/fps);
        keys[KEY_RIGHT] = 0;
    }

    static int look = 0;
    if(!look && mouse_button & BUTTON_LEFT) {
        setCursor(window_width / 2,window_height / 2);
        mouse_x = window_width / 2;
        mouse_y = window_height / 2;
        look = 1;
    }
    if(mouse_button & BUTTON_RIGHT) look = 0;

    if(look) {
        showCursor(0);
        mat3 m;
        m.rotate( lat, (mouse_y - window_height / 2) * 0.2 );
        lookat = m*lookat;
        m.rotate_y( -(mouse_x - window_width / 2) * 0.2 );
        lookat = m*lookat;
        setCursor(window_width / 2,window_height / 2);
    } else showCursor(1);

    vec3 up = lookat^lat;
    up.normalize();
    modelview.look_at(pos,pos+lookat,up);
}
开发者ID:,项目名称:,代码行数:54,代码来源:

示例2: opengl_init


//.........这里部分代码省略.........

		t3DObject* p = &g_3DModel.pObject[0];
LOGI("---------- 0");
		model_mesh.loc_view_matrix = glGetUniformLocation(model_mesh.program->get_program(), "view_matrix");
		model_mesh.loc_view_proj_matrix = glGetUniformLocation(model_mesh.program->get_program(), "view_proj_matrix");
		model_mesh.texs_locs[0] = glGetUniformLocation(model_mesh.program->get_program(), "base");
LOGI("---------- 1");
		model_mesh.texs_idxs[0] = create_texture("media/Wood.tga");

LOGI("---------- 2");
		glGenBuffers(4, model_mesh.attribute_vbos);
LOGI("---------- 3");
		glBindBuffer(GL_ARRAY_BUFFER, model_mesh.attribute_vbos[static_mesh::POSITION]);
		glBufferData(GL_ARRAY_BUFFER, 4*3*p->numOfVerts, &(p->pVerts[0].x), GL_STATIC_DRAW);
LOGI("---------- 4");
		glBindBuffer(GL_ARRAY_BUFFER, model_mesh.attribute_vbos[static_mesh::NORMAL]);
		glBufferData(GL_ARRAY_BUFFER, 4*3*p->numOfVerts, &(p->pNormals[0].x), GL_STATIC_DRAW);

		glBindBuffer(GL_ARRAY_BUFFER, model_mesh.attribute_vbos[static_mesh::TEXCOORD]);
		glBufferData(GL_ARRAY_BUFFER, 4*2*p->numOfVerts, &(p->pTexVerts[0].x), GL_STATIC_DRAW);

		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, model_mesh.attribute_vbos[static_mesh::INDEX]);
		glBufferData(GL_ELEMENT_ARRAY_BUFFER, 2*3*p->numOfFaces, &(p->pFaces[0].vertIndex[0]), GL_STATIC_DRAW);
LOGI("---------- 5");
		model_mesh.num_faces = p->numOfFaces;
	}

	/* init background *********************************************************************************/
	
	if(blur_mesh.program == NULL)
	{
		float *pos_data;
		GLushort *inds;
		GLuint num_ves;

		blur_mesh.program = new shader_program;
		if(!blur_mesh.program->build(vs.load_shader_source("media/quad.vs"),ps.load_shader_source("media/quad.ps")))
		{
			LOGI("build shader failed");
			return;
		}

		blur_mesh.texs_idxs[0] = render_rt;
		blur_mesh.texs_locs[0] = glGetUniformLocation(blur_mesh.program->get_program(), "RT");

		shape::create_plane(1, &pos_data, NULL, NULL, &inds, num_ves);

//		blur_mesh.loc_view_proj_matrix = glGetUniformLocation(blur_mesh.program->get_program(), "view_proj_matrix");
		
		blur_mesh.attribute_locations[static_mesh::POSITION] = glGetAttribLocation(blur_mesh.program->get_program(),"rm_Vertex");

		glGenBuffers(1, &blur_mesh.attribute_vbos[static_mesh::POSITION]);
		glGenBuffers(1, &blur_mesh.attribute_vbos[static_mesh::INDEX]);

		glBindBuffer(GL_ARRAY_BUFFER, blur_mesh.attribute_vbos[static_mesh::POSITION]);
		glBufferData(GL_ARRAY_BUFFER, num_ves*4*3, pos_data, GL_STATIC_DRAW);

		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, blur_mesh.attribute_vbos[static_mesh::INDEX]);
		glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6*2*3, inds, GL_STATIC_DRAW);

		blur_mesh.num_faces = 6;

		delete []pos_data;
		delete []inds;
	}

	if(combine_mesh.program == NULL)
	{
		float *pos_data;
		GLushort *inds;
		GLuint num_ves;

		combine_mesh = blur_mesh;

		combine_mesh.program = new shader_program;
		if(!combine_mesh.program->build(vs.load_shader_source("media/combine.vs"),ps.load_shader_source("media/combine.ps")))
		{
			LOGI("build shader failed");
			return;
		}

		combine_mesh.texs_idxs[0] = render_rt;
		combine_mesh.texs_locs[0] = glGetUniformLocation(combine_mesh.program->get_program(), "RT");

		combine_mesh.texs_idxs[1] = blur_rt;
		combine_mesh.texs_locs[1] = glGetUniformLocation(combine_mesh.program->get_program(), "Blur1");

		

	}

	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	
	width = w;
	height = h;
	
	quad_proj_matrix.perspective(60, (float)w/h, 1.0f,3000.0f);
}
开发者ID:gaoguanglei,项目名称:Android-OpenGL-ES-2.0-Effects,代码行数:101,代码来源:main.cpp


注:本文中的mat4::perspective方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。