/////////////////////////////////////////////////////////////////////////////
//
// 3D Math Primer for Games and Graphics Development
//
// Renderer.cpp - Very simple low-level 3D renderer interface
//
// Visit gamemath.com for the latest version of this file.
//
// --------------------------------------------------------------------------
//
// This file implements a very simple 3D renderer via Direct3D. Our goal was
// to provide a simple, cross-platform rendering engine. If you do not want
// to learn DirectX (and there are MANY people who work in graphics related
// firlds who have no need to know DirectX) then you don't need to look
// at the inside of this file - you can just get the benefits of a simple,
// clean rendering API without digging through mountains of DirectX
// documentation.
//
// <soapbox>
//
// Nowadays lots of people want to learn Direct3D, before they know graphics.
// As is typical of Microsoft, some people act as if the two are the same,
// like DirectX is "how things are done." Graphics is an academic pursuit
// unto itself, and many researchers spent many years investigating
// techniques and interfaces for rendering, long before Microsoft got
// involved in DirectX. It is more important to learn how graphics work
// from a platform- and API-independent standpoint than it is to learn how
// DirectX works, with all its quirks and shortcomings. And DirectX changes
// every year - sometimes radically. Most serious projects do most of their
// high-level graphics work using a graphics abstraction (such as this one)
// and leave the messy details hidden in a lower level. Certainly any
// cross-platform project must do this, but even ones only destinated for
// one platform can make use of this insulation. Please don't put DirectX
// code anywhere in your high level code. In fact you may notice that all
// of the files on gamemath.com can be used to make a platform-independent
// game loop, with the "game" files (the project-specific files) never
// including a big huge mess of stuff like <windows.h> or <xtl.h>.
//
// Many other books or Internet sources provide so-called "wrappers"
// around DirectX, which are designed to make it "easy" to write DirectX
// applications. Supposedly, you can use their code without knowing any
// DirectX. However, let us differentiate between a "wrapper" and an
// "abstraction layer." A wrapper is a very thin translation layer,
// usually designed to do nothing more than translate calls. It often
// can decrease compile times, facilitate DLL linkage, or provide shorthand
// for commonly used operations. However, a "wrapper" really doesn't
// help insulate you from the implementation details any or provide any
// platform independence. An abstraction layer, on the other hand,
// is designed to provide insulation from implementation details and/or
// platform independance. We have provided an abstraction layer, not a
// wrapper. This is evidenced by the fact that the header file does
// not contain a single platform independent element and could be ported
// to any number of platforms without a line of code being changed.
//
// Many wrappers or abstraction layers provided in books and on the Internet
// are useless because they are just as complicated or have as many quirks
// (or bugs) as the "messy" internals they proport to hide you from.
// (And what's more - they are usually more poorly documented!)
// Therefore, you not only have to learn DirectX, for example, but you have
// to learn their weird API as well. We have tried to design our interface
// layer so that it provides basic graphics functionality in the most
// straightforward manner possible, truly hiding DirectX details. Of course,
// with any interface, there is a learning curve associated with it. We
// hope that our design and comments make this curve as short as possible.
//
// </soapbox>
//
// So, the interface is completely platform independent, and much of the
// implentation is as well. All that said, however, eventually you have to
// impement the interface on a particular platform. It is possible, and
// in many ways advantageous, to make this file sit atop different
// lower level layers - i.e. one for DirectX, one for OpenGL, one for
// PlayStationII, etc. For simplicity, we have not done this. We have
// chosen one API (Direct3D) and made calls to it directly in this file.
// This makes it basically impossible to support multiple platforms or
// APIs easily without duplciating the entire contents of the file, but the
// purpose of this code is ease of understanding the API most people are
// most interested in learning - DirectX.
//
// We have also not concerned ourselved with optimization too much. This
// is an "engine" designed for you to look at the guts and learn how things
// work. Optimization would complicate the internals significantly and
// make things more difficult to understand.
//
// There is only one instance of class Renderer, a global variable
// gRenderer. (It is a "singleton" in C++ terminology.) Some internal
// state variables are declared here as private members. Other internal
// state variables are declared statically in the various C++ files -
// declaring all the variables here as private would be a drain on compile
// times, since it would require declaring more structures and including
// other files that are not necessary. C++ has the unfortunate property
// that all class internal members are visible to clients of the class, even
// if they are not accessible. In other words, they must be processed by
// the compiler, and if they are changed, seemingly unrelated files are
// often recompiled. Putting state variables statically, rather than in
// the private section, avoids this problem. A C++ purist might object,
// but a person waiting on the compiler will not.
//
/////////////////////////////////////////////////////////////////////////////
#include <assert.h>
#include "CommonStuff.h"
#include "Renderer.h"
#include "WinMain.h"
#include "MathUtil.h"
#include "Bitmap.h"
#include <d3d8.h>
/////////////////////////////////////////////////////////////////////////////
//
// local data
//
/////////////////////////////////////////////////////////////////////////////
// Direct3D interface object
static LPDIRECT3D8 pD3D = NULL;
// Direct3D device interface
static LPDIRECT3DDEVICE8 pD3DDevice = NULL;
// List of video modes
static int videoModeCount;
static VideoMode *videoModeList;
// The clip matrix. This transforms camera space points to clip
// space, aka "canonical view volume space." it is computed
// by computeClipMatrix(). D3D calls this matrix the "projection"
// matrix
static D3DMATRIX clipMatrix;
// Instance stack system. This is an OpenGL-like system to manage the
// current reference frame. For example, by default, without instancing,
// all 3D coordinates submitted to the rendering system are assumed to be
// in world space. Now, let's say we "instance" into an object's local
// reference frame, by specifying the position and orientation of the
// object. Now any 3D coordinates we submit will be transformed from
// local space to world space and then into camera space. Instancing
// can be performed multiple times, for example, to render a tire within a
// car.
struct InstanceInfo {
// The model->world matrix
Matrix4x3 modelToWorldMatrix;
};
const int kMaxInstanceDepth = 8;
static int instanceStackPtr = 0;
static InstanceInfo instanceStack[kMaxInstanceDepth];
// The model->clip matrix. This matrix takes a point in the current
// reference frame, and transforms it to clip space. Note that this is a
// 4x4 matrix. We could have our own nice 4x4 matrix class, but since they
// are actually not used very much outside of the graphcis internals, we just
// use D3D'
没有合适的资源?快使用搜索试试~ 我知道了~
3D数学基础:图形与游戏开发 中文版 史银雪译
共35个文件
h:16个
cpp:15个
pdf:1个
需积分: 10 9 下载量 125 浏览量
2010-03-01
16:01:51
上传
评论 1
收藏 13.33MB RAR 举报
温馨提示
《3d数学基础:图形与游戏开发》史银雪等翻译,Flecher Dunnlan Parberry著作 英文 书籍和源代码,含有全部的资源,放心使用!
资源推荐
资源详情
资源评论
收起资源包目录
3d数学基础图形与游戏开发 中文书籍和源代码.rar (35个子文件)
3d数学基础图形与游戏开发
test
Debug
3D数学基础 图形与游戏开发.pdf 13.58MB
viewer
viewer.cpp 3KB
AR_COUCH.s3d 17KB
viewer.dsp 5KB
AR_COUCH.tga 256KB
Debug
common
Renderer.h 16KB
TriMesh.cpp 5KB
EditTriMesh.cpp 51KB
Quaternion.cpp 11KB
Matrix4x3.cpp 23KB
Font.h 2KB
winmain.h 852B
Renderer.cpp 81KB
Quaternion.h 3KB
RotationMatrix.cpp 5KB
Model.h 2KB
MathUtil.h 2KB
AABB3.cpp 19KB
TriMesh.h 2KB
Model.cpp 7KB
Bitmap.h 2KB
CommonStuff.cpp 3KB
MathUtil.cpp 1KB
Bitmap.cpp 8KB
AABB3.h 3KB
EulerAngles.cpp 8KB
RotationMatrix.h 2KB
Input.cpp 6KB
Matrix4x3.h 4KB
EulerAngles.h 2KB
Input.h 8KB
WinMain.cpp 6KB
CommonStuff.h 2KB
vector3.h 5KB
EditTriMesh.h 8KB
共 35 条
- 1
资源评论
vvvhaichuan
- 粉丝: 8
- 资源: 24
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- mosquitto-2.018-install-windows-x64
- FTPServer FTP 服务器,绿色免安装,单文件
- 梦畅语音点名软件,上课点名
- 利用ADNI数据集和标签,在tensorflow框架上使用tensorlayer接口,通过架构u-net实现海马体的分割
- Kutools for Word v9.0 office word 插件
- 修复Windows 10 LTSC 2021资源占用率高
- Hash工具,小巧绿色hash校验工具,免费hash工具
- 重启进行BIOS快捷方式,不需要开机按BIOS键
- 鸭子开车记(儿童绘本)
- 威纶通触摸屏编程软件Easy builder pro V6.09.01.556安装包(2024.04).txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功