一个关于d3d的camera space的问题

popy007 2003-08-19 11:20:48

各位高手:
D3DXVec3Subtract(&ZAxis, pAt, pEye);
是pAt-pEye还是pEye-pAt???

还有就是不论上面的相减顺序如何,下面这样的camera space岂不是做成了右手系??
// Normalize the z basis vector.
D3DXVec3Normalize(&ZAxis, &ZAxis);

// Compute the orthogonal axes from the cross product of the gaze
// and the pUp vector.
D3DXVec3Cross(&XAxis, pUp, &ZAxis);
D3DXVec3Normalize(&XAxis, &XAxis);
D3DXVec3Cross(&YAxis, &ZAxis, &XAxis);

这样在做对world space旋转的时候方向应该就不对了。我是这么理解的,但肯定是我错了,因为d3d就是按照上面那样做的,且正确。希望高手指教!
...全文
112 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
popy007 2003-08-21
  • 打赏
  • 举报
回复
chenlee()

叉乘的结果都是符合右手螺旋定则的,但叉乘公式对于不同的坐标系是需要改变的。

a(x1,y1,z1)
b(x2,y2,z2)

左手系

| i j k |
a×b=| x2 y2 z2 | (i,j,k单位向量)
| x1 y1 z1 |
右手系
| i j k |
a×b=| x1 y1 z1 | (i,j,k单位向量)
| x2 y2 z2 |

你可以代值验证,或者你可以察看有关书籍。

叉乘公式:

| i j k |
a×b=| x1 y1 z1 | (i,j,k单位向量)
| x2 y2 z2 |

一般是根据右手坐标系定义的。

比如现在你在右手坐标系下,用x(1,0,0) x z(0,0,1)=
| i j k |
| 1 0 0 | = -j = (0, -1, 0) 此时x,z,xxz符合右手螺旋定则
| 0 0 1 |
但如果你在左手坐标系下,还是用x(1,0,0) x z(0,0,1)=
| i j k |
| 1 0 0 | = -j = (0, -1, 0) 此时x,z,xxz就不符合右手螺旋定则了
| 0 0 1 |

所以要变成

| i j k |
| 0 0 1 | = j = (0, 1, 0) 才能使x,z,xxz符合右手螺旋定则
| 1 0 0 |

这就是左右手叉乘公式的区别所在

chenlee 2003-08-20
  • 打赏
  • 举报
回复
> 回复人: happy__888([顾问团]寻开心) ( ) 信誉:110 2003-08-19 17:27:00 得分:0
>
>
> 单独一个z乘符号不够,xyz都要乘-1
>
> 其实你自己使用两个已知向量测试一下就知道了,例如
> 第一个向量(1 0 0)
> 第二个向量(0 1 0)
> 看但得到的结果是右手:(0 0 1 ) 还是左手:(0 0 -1)

绝对错误啊!

不管是左手还是右手系,查乘的算法是不会遍的,
(1,0,0) X (0,1,0) 恒等于 (0,0,1)


popy007 2003-08-20
  • 打赏
  • 举报
回复
happy__888([顾问团]寻开心)

我明白了,我的世界坐标是左手的,而这个叉乘公式是右手的,所以我要么把

公式变为

| i j k |
a×b=| x2 y2 z2 | (i,j,k单位向量)
| x1 y1 z1 |

要么用b x a,呵呵,原来是我对叉乘的理解还不透彻,现在全明白了!Thank you for your reminding!

谢谢各位的参与!
寻开心 2003-08-20
  • 打赏
  • 举报
回复
至于你的结果有符号问题,是因为右手坐标系和左手坐标系本来就是差一个符号的关系
寻开心 2003-08-20
  • 打赏
  • 举报
回复
叉乘公式是右手的。
D3DVec3Cross()里面向量也是按照右手计算的没错

前面的计算步骤是按照右手的顺序来的
但是这和左手坐标系冲突啊。

你的世界坐标系是左手的还是右手的啊?
寻开心 2003-08-19
  • 打赏
  • 举报
回复
D3DXVec3Cross()就是按照左手的顺序来生的啊。
D3DXVec3Cross(&YAxis, &ZAxis, &XAxis);

Y向上,Z朝向屏幕里面,X朝向右侧就是左手系的啊。

定义差积的时候,可以按照左手,也可以按照右手来处理,D3D是左手的。

ptAT-ptEye得到的是视向量
popy007 2003-08-19
  • 打赏
  • 举报
回复

这么说吧,按照d3d,最后的view matrix应该是这样的,
[ux vx nx 0]
[uy vy ny 0]
[uz vz nz 0]
[-(c.u) -(c.u) -(c.n) 1]

其中向量u,v,n是由照相机在world space中的位置Eye、看向的一点LookAt和world space中的
“上”vup,一般情况是"(0,1,0)"决定的。我没有用D3DXVec3LookAtLH()来做这个
view matrix,我自己计算这个matrix,所以要得到u,v,n,相机的位置Eye是知道的。我不用d3d的左手叉乘。

我按照叉乘的公式:


| i j k |
a×b=| x1 y1 z1 | (i,j,k单位向量)
| x2 y2 z2 |

a(x1,y1,z1),b(x2,y2,z2),a x b=(y1z2-z1y2)i+(z1x2-x1z2)j+(x1y2-y1x2)k
做右手的叉乘(a,b,axb这时符合右手系对吗?)

我首先用LookAt-Eye得到n,
然后用n x vup 得到u,
最后用u x n 得到v

u,v,n单位化

接着把他们填充到上面的矩阵中形成view matrix。

我试着用这个矩阵变换一个world space中的点,但发现得到camera space中的点的

的x坐标是相反的(因该在x的位置,变成了-x)。

我就认为上面我有疑问的叉乘公式是左手系的,

就按左手系的求了一边u,v,n,结果正确。这样我就不明白了,

难道上面的叉乘公式

| i j k |
a×b=| x1 y1 z1 | (i,j,k单位向量)
| x2 y2 z2 |

是左手系的吗?
寻开心 2003-08-19
  • 打赏
  • 举报
回复
单独一个z乘符号不够,xyz都要乘-1

其实你自己使用两个已知向量测试一下就知道了,例如
第一个向量(1 0 0)
第二个向量(0 1 0)
看但得到的结果是右手:(0 0 1 ) 还是左手:(0 0 -1)
azheng0305 2003-08-19
  • 打赏
  • 举报
回复
D3DVec3Cross()就是做了叉乘的事情啊,你看看数学上怎么乘不久可以了?
好像是这么乘的,其中我写的×就是叉乘:
a(x1,y1,z1) b(x2,y2,z2)
| i j k |
a×b=| x1 y1 z1 | (i,j,k单位向量)
| x2 y2 z2 |
将行列式的第一行展开得到坐标表达式:
a×b=(y1z2-z1y2)i+(z1x2-x1z2)j+(x1y2-y1x2)k

——————————————————————
另外,你可以看到右手系统和左手系统的区别,就是Z是相差一个负号啊,你只要在自己的数据里吧Z值加个符号,程序就可以继续用你的右手系统了。呵呵。
popy007 2003-08-19
  • 打赏
  • 举报
回复
My God!!

原来问题在D3DVec3Cross()!是按左手系,我以为是按右手!有什么办法可以看

D3DVec3Cross()代码阿??
This book describes the Direct3D graphics pipeline, from presentation of scene data to pixels appearing on the screen. The book is organized sequentially following the data °ow through the pipeline from the application to the image displayed on the monitor. Each major section of the pipeline is treated by a part of the book, with chapters and subsections detailing each discrete stage of the pipeline. This section summarizes the contents of the book. Part I begins with a review of basic concepts used in 3D computer graphics and their representations in Direct3D. The IDirect3D9 interface is introduced and device selection is described. The IDirect3DDevice9 interface is introduced and an overview of device methods and internal state is given. Finally, a basic framework is given for a 2D application. Chapter 1 begins with an overview of the entire book. A review is given of display technology and the important concept of gamma correction. The representation of color in Direct3D and the macros for manipulating color values are described. The relevant mathematics of vectors, geometry and matrices are reviewed and summarized. A summary of COM and the IUnknown interface is COM: Component Object Model given. Finally, the coding style conventions followed in this book are presented along with some useful C++ coding techniques. Chapter 2 describes the Direct3D object. Every application instantiates this object to select a device from those available. Available devices advertise their location in the Win32 virtual desktop and their capabilities to applications 34 CHAPTER 1. INTRODUCTION through the Direct3D object. Selecting a device from those available and exam- ining a device's capabilities are described. Multiple monitor considerations are also discussed. Chapter 3 describes the Direct3D device object which provides access to the rendering pipeline. The device is the interface an application will use most often and it has a large amount of internal state that controls every stage of the rendering pipeline. This chapter provides a high-level overview of the device and its associated internal state. Detailed discussion of the device state appears throughout the rest of the book. Chapter 4 describes the basic architecture of a typical Direct3D application. Every 3D application can use 2D operations for manipulating frame bu®er con- tents directly. An application can run in full-screen or windowed modes and the di®erences are presented here. The handling of Windows messages and a ba- sic display processing loop are presented. At times it may be convenient to use GDI in a Direct3D application window and a method for mixing these two Win- dows subsystems is presented. Almost every full-screen application will want to use the cursor management provided by the device. Device color palettes and methods for gamma correction are presented. Part II describes the geometry processing portion of the graphics pipeline. The application delivers scene data to the pipeline in the form of geometric primitives. The pipeline processes the geometric primitives through a series of stages that results in pixels displayed on the monitor. This part describes the start of the pipeline where the processing of geometry takes place. Chapter 5 describes how to construct a scene representing the digital world that is imaged by the imaginary camera of the device. A scene consists of a collection of models drawn in sequence. Models are composed of a collection of graphic primitives. Graphic primitives are composed from streams of vertex and index data de¯ning the shape and appearance of objects in the scene. Vertices and indices are stored in resources created through the device. Chapter 6 covers vertex transformations, vertex blending and user-de¯ned clipping planes. With transformations, primitives can be positioned relative to each other in space. Vertex blending, also called \skinning", allows for smooth mesh interpolation. User-de¯ned clipping planes can be used to provide cut away views of primitives. Chapter 7 covers viewing with a virtual camera and projection onto the viewing plane which is displayed as pixels on the monitor. After modeling, objects are positioned relative to a camera. Objects are then projected from 3D camera space into the viewing plane for conversion into 2D screen pixels. Chapter 8 describes the lighting of geometric primitives. The lighting model is introduced and the supported shading algorithms and light types are de- scribed. Chapter 9 covers programmable vertex shading. Programmable vertex shaders can process the vertex data streams with custom code, producing a single ver- tex that is used for rasterization. The vertex shading machine architecture and instruction set are presented. Part III covers the rasterization portion of the pipeline where geometry is1.1. OVERVIEW 5 converted to a series of pixels for display on the monitor. Geometric primitives are lit based on the lighting of their environment and their material properties. After light has been applied to a primitive, it is scan converted into pixels for processing into the frame bu®er. Textures can be used to provide detailed surface appearance without extensive geometric modeling. Pixel shaders can be used to provide custom per-pixel appearance processing instead of the ¯xed- function pixel processing provided by the stock pipeline. Finally, the pixels generated from the scan conversion process are incorporated into the render target surface by the frame bu®er. Chapter 10 describes the scanline conversion of primitives into pixel frag- ments. Lighting and shading are used to process vertex positions and their associated data into a series of pixel fragments to be processed by the frame bu®er. Chapter 11 describes textures and volumes. Textures provide many e±cient per-pixel e®ects and can be used in a variety of manners. Volumes extend texture images to three dimensions and can be used for a volumetric per-pixel rendering e®ects. Chapter 13 describes programmable pixel shaders. Programmable pixel shaders combine texture map information and interpolated vertex information to produce a source pixel fragment. The pixel shading machine architecture and instruction set are presented. Chapter 14 describes how fragments are processed into the frame bu®er. After pixel shading, fragments are processed by the fog, alpha test, depth test, stencil test, alpha blending, dither, and color channel mask stages of the pipeline before being incorporated into the render target. A render target is presented for display on the monitor and video scan out. Part IV covers the D3DX utility library. D3DX provides an implementation of common operations used by Direct3D client programs. The code in D3DX consists entirely of client code and no system components. An application is free to reimplement the operations provided by D3DX, if necessary. Chapter 15 introduces D3DX and summarizes features not described else- where. Chapter 16 describes the abstract data types provided by D3DX. D3DX provides support for RGBA color, point, vector, plane, quaternion, and matrix data types. Chapter 17 describes the helper COM objects provided by D3DX. D3DX provides a matrix stack object to assist in rendering frame hierarchies, a font object to assist in the rendering of text, a sprite object to assist in the rendering of 2D images, an object to assist in rendering to a surface or an environment map and objects for the rendering of special e®ects. Chapter 19 describes the mesh objects provided by D3DX. The mesh objects provided by D3DX encompass rendering of indexed triangle lists as well as progressive meshes, mesh simpli¯cation and skinned meshes. Chapter 21 describes the X ¯le format with the ¯le extension .x. The X ¯le format provides for extensible hierarchical storage of data objects with object instancing.6 CHAPTER 1. INTRODUCTION Part V covers application level considerations. This part of the book de- scribes issues that are important to applications but aren't strictly part of the graphics pipeline. Debugging strategies for applications are presented. Almost all Direct3D applications will be concerned with performance; API related per- formance issues are discussed here. Finally, installation and deployment issues for Direct3D applications are discussed. Chapter 22 describes debugging strategies for Direct3D applications. This includes using the debug run-time for DirectX 9.0c, techniques for debugging full-screen applications and remote debugging. Chapter 23 covers application performance considerations. All real devices have limitations that a®ect performance. A general consideration of how the pipeline state a®ects performance is given. Chapter 24 covers application installation and setup. Appendix A provides a guided tour of the DirectX SDK materials.
1,CODE_UPLOAD137411132001.zip
A 3Dimensional park with lolly pop trees and flying birds. Programmed with Direct3D (Retained Mode). A good program to learn some simple direct3d in. Requires the DirectX7 SDK to use
2,CODE_UPLOAD39693132000.zip
This code shows you how to use DirectX 7 and the RM Canvas control to create nice animations that are smooth and simple. It shows you how to create lights, frames animation and more.
3,CODE_UPLOAD140811232001.zip
Space Quest is the temporary name for the single player RPG (in progress) that currently P4R14H(art) and I(programming) are working on. It has nothing to do with space travel or anything (more Lord of the Rings-ish), just read the readme.txt in the zip
4,CODE_UPLOAD76727112000.zip
This shows you the basics of using Direct Draw and Direct Sound. It shows you how to create a sprite and move it around the screen
5,CODE_UPLOAD1093810242000.zip
CHECK THIS OUT! This is a really cool effect. Stand in the middle of a 3D world and use the mouse to rotate the camera around. All running at over 60 frames per second
6,CODE_UPLOAD15673312001.zip
This is a DirectX car game made in VB. I used Objects in this one so it should help some people. It's not very interesting but demonstrates a good way to make an OO Game. Hope you like this.
7,CODE_UPLOAD150532162001.zip
This is a complete screen saver made in VB5. It uses DirectX7. At first I wanted to make it compatible with older DirectX, but they only DirectX 7 and higher supports drawing primitives on surfaces. Now the code is simple and commented.
8,D3DSample.zip
This is a sample that demonstrates some basic Direct3D techniques.
9,biohazrdDD.zip
A library of DirectDraw graphics functions and subroutines. Being used in DDCK: MOC!
10,DXHelp.zip
Gives some meaningful error codes instead of the traditional archaic automation errors.
11,ColDet.zip
Detecting collisions between polygons.
12,AscPlay.zip
This sample will play animated .ASC files.
13 , avb-ddraw.zip
This is an Example of using Microsoft's Direct Draw Type Libs (below.)
14 , directx.zip
These are the Type Libs that go with Microsofts (tm) Direct Draw. There is an excellent example using these Libs above.


8,301

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧