|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2009-3-16 08:50:36
|
显示全部楼层
// check for movement collision - can not walk past anything blocking path. if(_node_tree_mesh.is_ray_intersect_mesh(_x_pos, _y_pos + _above_floor, _z_pos, _x_pos + x_move, _y_pos + _above_floor, _z_pos + z_move, &dist)) { // adjust coordinates to be exactly 2.5 units away from target
float diff = dist - 2.5f;
D3DXVECTOR2 dir; D3DXVec2Normalize(&dir, &D3DXVECTOR2(x_move, z_move));
dir *= diff;
x_move = dir.x; z_move = dir.y; }
// update view coordinats _x_pos += x_move; _z_pos += z_move;
// position camera and rotate based on mouse position
_camera.move(_x_pos, _y_pos + 50.0f, _z_pos);
// _mouse.get_y_delta(): // get mouse's relative x movement coordinate. // // _mouse.get_x_delta(): // get mouse's relative y movement coordinate. _camera.rotate_rel((float) _mouse.get_y_delta() / 200.0f, (float) _mouse.get_x_delta() / 200.0f, 0.0f);
// position _light.move(_x_pos, _y_pos + 60.0f, _z_pos); _graphics.set_light(0, &_light);
FRUSTUM frustum;
// set camera and calculate frustum _graphics.set_camera(&_camera); frustum.construct(&_graphics); // render everything _graphics.clear_zbuffer(1.0f);
// begin render now if(_graphics.begin_scene()) { _graphics.enable_zbuffer(FALSE); _graphics.enable_lighting(FALSE); _sky_box.render(&_camera);
_graphics.enable_zbuffer(TRUE); _graphics.enable_lighting(TRUE); _node_tree_mesh.render(&frustum);
_graphics.end_scene(); }
_graphics.display();
return TRUE; }
BOOL shutdown() { return TRUE; }
private: GRAPHICS _graphics; CAMERA _camera; LIGHT _light;
SOUND _sound; SOUND_DATA _sound_data; SOUND_CHANNEL _sound_channel[3];
SKY_BOX _sky_box;
INPUT _input; INPUT_DEVICE _keyboard; INPUT_DEVICE _mouse;
MESH _mesh; NODE_TREE_MESH _node_tree_mesh;
float _x_pos, _y_pos, _z_pos; static const float _above_floor; };
const float APP::_above_floor = 64.0f;
int WINAPI WinMain(HINSTANCE inst, HINSTANCE, LPSTR cmd_line, int cmd_show) { APP app;
return app.run(); } 截图:
![](http://www.cppblog.com/images/cppblog_com/lovedday/4157/o_node_tree_mesh_1.jpg)
|
|