博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
物体坐标to世界坐标
阅读量:4597 次
发布时间:2019-06-09

本文共 2458 字,大约阅读时间需要 8 分钟。

源地址:

真尼玛不容易,找了两天才有点眉目。。汗

Local to World Coordinates

This document is designed to explain how to determine the position of an object in World coordinates after it has undergone an arbitrary number of transformations, (glTranslatef, glRotatef and glScalef.)

这个文档被设计用来解释如何判断一个物体在进行各种变换后(平移,旋转,缩放)在世界坐标系中的位置。

该死的opengl没有提供从Local坐标系到world坐标系的转换机制,甚至它也没定义世界坐标系。它使用称为modelview的矩阵,这个矩阵是model矩阵和view矩阵的结合。

你可以通过model矩阵得到world坐标,(该矩阵包含the world translate poision 和scale rotation).这通过逆矩阵乘以MV矩阵得到。

OpenGL does not provide a mechanism for converting Local coordinates to World coordinates, (nor does it define any such coordinates). It uses something called the 'ModelView Matrix' (M*V), which is a combination of transformed local model coordinates known as a Model Matrix (M) and virtual camera position known as a View Matrix (V).

You can get the World coordinates by determining the Model Matrix, (which contains the World Translate position as well as scale and rotation.) This is achieved by multiplying the inverse camera view V-1 by MV:

V-1 * ( V * M ) == M

Then you have m12 = X , m13 = Y, and m14 = Z (in World Coordinates!)

ModelView

OpenGL Transformation Concepts:

A good discussion on this method and some other possible techniques can be found here:


Code Used in ANTz:

//load the identity matrix and position the virtual camera

glLoadIdentity();
gluLookAt ( camNode->translate.x, camNode->translate.y, camNode->translate.z,
camNode->translate.x + camNode->rotateVec.x,
camNode->translate.y + camNode->rotateVec.y,
camNode->translate.z + camNode->rotateVec.z,
upX, upY, upZ ); 
//now get the virtual Camera Matrix, V
glGetFloatv (GL_MODELVIEW_MATRIX, camData->matrix);

//then invert the matrix V, you can use any standard 4x4 matrix inversion method

npInvertMatrixf (camData->matrix, camData->inverseMatrix);
.....

//transformation code here, multiple glTranslatef(), glRotatef() and glScalef()

.....
//then get your local object ModelView Matrix
glGetFloatv (GL_MODELVIEW_MATRIX, modelView);

//ANTz uses a fast partial matrix multiplication which only calculates m12, m13 and m14

//however, you can use any standard 4x4 Matrix Multiplication routine
npLocalToWorld (&world, camData->inverseMatrix, modelView);

printf("%6.2f %6.2f %6.2fn", world.x, world.y, world.z );

*camData->matrix, camData->inverseMatrix and modelView are all simple 1D arrays of 16 floats, or a 4x4 matrix however you look at it.

转载于:https://www.cnblogs.com/Vulkan/archive/2012/07/09/7530289.html

你可能感兴趣的文章
iOS7程序后台运行
查看>>
maven+testng+reportng的pom设置
查看>>
IT telephone interview
查看>>
gitlab安装配置
查看>>
ps载入画笔
查看>>
悲怆:IT人的一声叹息->一个程序员的自白[转帖]
查看>>
[SpringMVC]自定义注解实现控制器访问次数限制
查看>>
日记(序)
查看>>
A == B ?
查看>>
洛谷P3763 [Tjoi2017]DNA 【后缀数组】
查看>>
GSM模块_STM32实现GPRS与服务器数据传输经验总结
查看>>
5.Python进阶_循环设计
查看>>
【NLP】揭秘马尔可夫模型神秘面纱系列文章(一)
查看>>
Android采访开发——2.通用Android基础笔试题
查看>>
UVa 442 Matrix Chain Multiplication(矩阵链,模拟栈)
查看>>
多种方法求解八数码问题
查看>>
spring mvc ModelAndView向前台传值
查看>>
(黑客游戏)HackTheGame1.21 过关攻略
查看>>
Transparency Tutorial with C# - Part 2
查看>>
android 文件上传
查看>>