【3D技术宅公社】XR数字艺术论坛  XR技术讨论 XR互动电影 定格动画

 找回密码
 立即注册

QQ登录

只需一步,快速开始

调查问卷
论坛即将给大家带来全新的技术服务,面向三围图形学、游戏、动画的全新服务论坛升级为UTF8版本后,中文用户名和用户密码中有中文的都无法登陆,请发邮件到324007255(at)QQ.com联系手动修改密码

3D技术论坛将以计算机图形学为核心,面向教育 推出国内的三维教育引擎该项目在持续研发当中,感谢大家的关注。

12
返回列表 发新帖
楼主: 鼯鼠

[转帖]创建3D图形引擎

[复制链接]
 楼主| 发表于 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();
}
截图:

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|3D数字艺术论坛 ( 沪ICP备14023054号 )

GMT+8, 2024-5-22 01:59

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表