游戏开发论坛

 找回密码
 立即注册
搜索
查看: 4067|回复: 12

刚学3D的疑惑

[复制链接]

47

主题

145

帖子

3602

积分

论坛元老

Rank: 8Rank: 8

积分
3602
发表于 2004-7-5 11:31:00 | 显示全部楼层 |阅读模式
大家好!我现在要问个问题。。。因为我是个初学者,我问的问题对于你门来说可能有点幼稚,但请慷慨解嘴,告诉我吧~~~



//================================================

比如说我现在在第一个3D程序里画了个正方形,然后我想让它动,比如沿着X轴移动N像素,于是就有了我想期望的效果了,但是该怎么移动呢?就如我所说的把正方形沿着X轴移动N像素。要知道正方行是由8个点组成的啊,每个点都有自己的坐标,那正方形的坐标在哪??还有。。我看例子上是通过改变世界矩阵来达到这个效果的!我也有个疑问,这个世界矩阵是不是  (摄像机+正方形)的世界空间如果按照例子上的,让世界矩阵旋转或移动的话,那摄像机不也跟着动了吗?因为它门同处于在同一个世界之中。。移动这个世界当然就2者一起移动了。我知道是我错理解了世界矩阵这个概念,请大家告诉我这个世界矩阵到底是啥???  

//=================================================

28

主题

433

帖子

433

积分

中级会员

Rank: 3Rank: 3

积分
433
发表于 2004-7-5 14:10:00 | 显示全部楼层

Re:刚学3D的疑惑

摄像机 和 世界矩 是两个 相对独立的 东西!

世界矩 相当于 一个方盒子~
摄像机 相当于 你的眼睛~
--------------------------------------------------

你的眼睛移动 和 方盒子移动 可以达到 相似的 效果~
-------------------------------------------------
没想到现在的 新手 空间概念 ~~~

47

主题

145

帖子

3602

积分

论坛元老

Rank: 8Rank: 8

积分
3602
 楼主| 发表于 2004-7-5 15:23:00 | 显示全部楼层

Re:刚学3D的疑惑

那比如说我现在的场景中有2个物体
那如果其中一个要动另外一个静止!!!该怎么做??世界矩阵只有一个啊??按照这样来的话。。那2个就都动了,用什么办法呢?

9

主题

198

帖子

198

积分

注册会员

Rank: 2

积分
198
发表于 2004-7-5 18:57:00 | 显示全部楼层

Re:刚学3D的疑惑

This is from DX9 SDK Document
Matrix Stacks

--------------------------------------------------------------------------------

The D3DX utility library provides the ID3DXMatrixStack interface. It supplies a mechanism to enable matrices to be pushed onto and popped off of a matrix stack. Implementing a matrix stack is an efficient way to track matrices while traversing a transform hierarchy.

The D3DX utility library uses a matrix stack to store transformations as matrices. The various methods of the ID3DXMatrixStack interface deal with the current matrix, or the matrix located on top of the stack. You can clear the current matrix with the ID3DXMatrixStack:oadIdentity method. To explicitly specify a certain matrix to load as the current transformation matrix, use the ID3DXMatrixStack::LoadMatrix method. Then you can call either the ID3DXMatrixStack::MultMatrix method or the ID3DXMatrixStack::MultMatrixLocal method to multiply the current matrix by the specified matrix.

The ID3DXMatrixStack:op method enables you to return to the previous transformation matrix and the ID3DXMatrixStack::Push method adds a transformation matrix to the stack.

The individual matrices on the matrix stack are represented as 4? homogeneous matrices, defined by the D3DX utility library D3DXMATRIX structure.

The D3DX utility library provides a matrix stack through a Component Object Model (COM) object.

Implementing a Scene Hierarchy
A matrix stack simplifies the construction of hierarchical models, in which complicated objects are constructed from a series of simpler objects.

A scene, or transform, hierarchy is usually represented by a tree data structure. Each node in the tree data structure contains a matrix. A particular matrix represents the change in coordinate systems from the node's parent to the node. For example, if you are modeling a human arm, you might implement the following hierarchy.



In this hierarchy, the Body matrix places the body in the world. The UpperArm matrix contains the rotation of the shoulder, the LowerArm matrix contains the rotation of the elbow, and the Hand matrix contains the rotation of the wrist. To determine where the hand is relative to the world, you multiply all the matrices from Body down through Hand together.

The previous hierarchy is overly simplistic, because each node has only one child. If you begin to model the hand in more detail, you will probably add fingers and a thumb. Each digit can be added to the hierarchy as children of Hand.



If you traverse the complete graph of the arm in depth-first order?traversing as far down one path as possible before moving on to the next path?to draw the scene, you perform a sequence of segmented rendering. For example, to render the hand and fingers, you implement the following pattern.

Push the Hand matrix onto the matrix stack.
Draw the hand.
Push the Thumb matrix onto the matrix stack.
Draw the thumb.
Pop the Thumb matrix off the stack.
Push the Finger 1 matrix onto the matrix stack.
Draw the first finger.
Pop the Finger 1 matrix off the stack.
Push the Finger 2 matrix onto the matrix stack. You continue in this manner until all the fingers and thumb are rendered.
After you have completed rendering the fingers, you would pop the Hand matrix off the stack.

You can follow this basic process in code with the following examples. When you encounter a node during the depth-first search of the tree data structure, push the matrix onto the top of the matrix stack.

MatrixStack-&gtush();

MatrixStack->MultMatrix(pNode->matrix);

When you are finished with a node, pop the matrix off the top of the matrix stack.

MatrixStack->Pop();

In this way, the matrix on the top of the stack always represents the world-transform of the current node. Therefore, before drawing each node, you should set the Microsoft?Direct3D?matrix.

pD3DDevice->SetTransform(D3DTS_WORLDMATRIX(0), *MatrixStack->GetTop());

For more information about the specific methods that you can perform on a D3DX matrix stack, see the ID3DXMatrixStack reference topic.

11

主题

145

帖子

150

积分

注册会员

Rank: 2

积分
150
发表于 2004-7-5 19:11:00 | 显示全部楼层

Re: 刚学3D的疑惑

hays2002: 刚学3D的疑惑

大家好!我现在要问个问题。。。因为我是个初学者,我问的问题对于你门来说可能有点幼稚,但请慷慨解嘴,告诉我吧~~~


//================================================

比如说我现在在第一个3D程序里画了个正方形,然后我想让它动,比如沿着X轴移动N像素,于是就有了我想期望的效果了,但是该怎么移动呢?就如我所说的把正方形沿着X轴移动N像素。要知道正方行是由8个点组成的啊,每个点都有自己的坐标,那正方形的坐标在哪??还有。。我看例子上是通过改变世界矩阵来达到这个效果的!我也有个疑问,这个世界矩阵是不是  (摄像机+正方形)的世界空间如果按照例子上的,让世界矩阵旋转或移动的话,那摄像机不也跟着动了吗?因为它门同处于在同一个世界之中。。移动这个世界当然就2者一起移动了。我知道是我错理解了世界矩阵这个概念,请大家告诉我这个世界矩阵到底是啥???  

//=================================================


在QQ的群里上也跟你说了,不懂“线性代数”是没法搞懂矩阵这个概念的[em7]

[em10]

所以说...

11

主题

145

帖子

150

积分

注册会员

Rank: 2

积分
150
发表于 2004-7-5 19:15:00 | 显示全部楼层

Re: Re:刚学3D的疑惑

hays2002: Re:刚学3D的疑惑

那比如说我现在的场景中有2个物体
那如果其中一个要动另外一个静止!!!该怎么做??世界矩阵只有一个啊??按照这样来的话。。那2个就都动了,用什么办法呢?


这个要用到矩阵堆栈,

压入,弹出矩阵~楼上的哥们儿节选的dxsdk片断写的很清楚了 [em2]

69

主题

335

帖子

343

积分

中级会员

Rank: 3Rank: 3

积分
343
QQ
发表于 2004-7-5 20:16:00 | 显示全部楼层

Re:刚学3D的疑惑

让其中1个box的位置发生改变不就行了。
想的复杂了。

11

主题

145

帖子

150

积分

注册会员

Rank: 2

积分
150
发表于 2004-7-5 20:57:00 | 显示全部楼层

Re: Re:刚学3D的疑惑

thinbug: Re:刚学3D的疑惑

让其中1个box的位置发生改变不就行了。
想的复杂了。


对,这样也可以 [em3],呵呵

36

主题

382

帖子

498

积分

中级会员

Rank: 3Rank: 3

积分
498
发表于 2004-7-6 07:58:00 | 显示全部楼层

Re:刚学3D的疑惑

你们不要吓唬人家,
我觉得不懂矩阵也可以学得。
其实道理都是非常简单的。

每一个物体都有自己的世界矩阵。用来把自己转换到世界中去。
这个世界有一个投影矩阵用来观察就够了,所以一个就好拉。

directx提供一大堆函数用来操作这些矩阵,也很简单形象。
当然想让它复杂自己搞也可以,活活。

4

主题

140

帖子

140

积分

注册会员

Rank: 2

积分
140
发表于 2004-7-6 11:43:00 | 显示全部楼层

Re:刚学3D的疑惑

不要虾仁,局阵其实也很简单。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-7-5 13:46

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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