对opengl列主序效率更高质疑

news/2024/7/3 12:26:38 标签: float, struct
 
下面程序,容易看出行主序在坐标点变换中效率更高 
#include <WINDOWS.H>
#include <IOSTREAM>

using namespace std;



enum MatrixIndex
{
	Xx, Xy, Xz, Xi,	   // X方向
	Yx, Yy, Yz, Yi,    // y方向
	Zx, Zy, Zz, Zi,    // z方向
	Tx, Ty, Tz, Ii,    // 移动
};


struct POINT3D
{
	double x, y, z;
	POINT3D() { ZeroMemory(this, sizeof(POINT3D)); }
	POINT3D(double tx, double ty, double tz) {x = tx; y = ty; z = tz;}
	void Modify(float *pglM)
	{
		double x1=0.0, y1=0.0, z1=0.0;
		x1 = x*pglM[Xx] + y*pglM[Yx] + z*pglM[Zx] + pglM[Tx];
		y1 = x*pglM[Xy] + y*pglM[Yy] + z*pglM[Zy] + pglM[Ty];
		z1 = x*pglM[Xz] + y*pglM[Yz] + z*pglM[Zz] + pglM[Tz];
		x = x1;
		y = y1;
		z = z1;
	}
	void ModifyT(float *pglM)
	{
		double x1=0.0, y1=0.0, z1=0.0;
		x1 = x*(*pglM++); x1 += y*(*pglM++); x1 += z*(*pglM++); x1 += (*pglM++);
		y1 = x*(*pglM++); y1 += y*(*pglM++); y1 += z*(*pglM++); y1 += (*pglM++);
		z1 = x*(*pglM++); z1 += y*(*pglM++); z1 += z*(*pglM++); z1 += (*pglM++);
		x = x1;
		y = y1;
		z = z1;
	}
};

void main()
{
	// 列主序
	float M[16] = 
	{
		1.0, 0.0, 0.0, 0.0,
		0.0, 1.0, 0.0, 0.0,
		0.0, 0.0, 1.0, 0.0,
		2.0, 2.0, 2.0, 1.0   // Trans
	};

	POINT3D pt(1.0, 2.0, 3.0);
	pt.Modify(M);
	cout << pt.x << " " << pt.y << " " << pt.z << endl;


	// 行主序
	float MT[16] = 
	{                  //Trans
		1.0, 0.0, 0.0, 2.0,
		0.0, 1.0, 0.0, 2.0,
		0.0, 0.0, 1.0, 2.0,
		0.0, 0.0, 0.0, 1.0
	};
	POINT3D pt2(1.0, 2.0, 3.0);
	pt2.ModifyT(MT);
	cout << pt2.x << " " << pt2.y << " " << pt2.z << endl;
}


http://www.niftyadmin.cn/n/654455.html

相关文章

按位与、或、异或等运算方法

按位与运算符&#xff08;&&#xff09; 参加运算的两个数据&#xff0c;按二进制位进行“与”运算。 运算规则&#xff1a;0&00; 0&10; 1&00; 1&11; 即&#xff1a;两位同时为“1”&#xff0c;结果才为“1”&#xff0c;否则为0 例如&#xff1…

逆波兰 计算器 C语言实现代码

#include <stdio.h> #include <stdlib.h>#define MAXOP 100 // 操作数或运算符的最大长度 #define NUMBER 0 // 标识找到一个数int getop(char []); void push(double); double pop(void);int main(void) { int type;double op2, op3;char s[MAXOP];while ((ty…

python没有数组_Python共享内存数组,没有属性get_obj()

我正在使用多处理模块操作numpy数组,并且遇到了一些问题,尝试了我在这里运行的一些代码.具体来说,我从一个numpy数组创建一个ctypes数组,然后尝试将ctypes数组返回到一个numpy数组.这是代码&#xff1a;shared_arr multiprocessing.RawArray(_numpy_to_ctypes[array.dtype.typ…

计算机中的换行符、回车符、\n、\r、\n\r 怎么区分

\n是换行&#xff0c;英文是New line \r是回车&#xff0c;英文是Carriage return \r’是回车&#xff0c;前者使光标到行首&#xff0c;&#xff08;carriage return&#xff09; \n’是换行&#xff0c;后者使光标下移一行&#xff0c;&#xff08;line feed&#xff09; \…

线程同步的3种实现方法 互斥对象 临界资源 事件对象

给懒的重新打代码的人用。 // Win32 Console.cpp : Defines the entry point for the console application. //#include "stdafx.h" #include <windows.h> #include <iostream> using namespace std;CRITICAL_SECTION g_cs; HANDLE g_hMutex; HANDLE g_h…

testng相关用法

一、idea中testng使用的条件 1、需要引入testng的依赖包&#xff1b; 2、需要在idea中添加testng插件包。 只有满足以上两个条件&#xff0c;才能在代码中出现运行testng的标识。如下图&#xff1a; 在只满足条件1的情况下&#xff0c;即只有testng依赖包&#xff08;插件中…

fiddler的命令行用法

命令行的输入区域&#xff1a; 注1&#xff1a;通过快捷键 Alt q 可以将焦点定位到命令行输入框&#xff08;小黑框&#xff09;中&#xff1b; 注2&#xff1a;当焦点在命令输入框中时&#xff0c;快捷键 Ctrl i 可以快速插入当前选中会话的 URL。 下边是 Fiddler 的内置命…

邮件发送时间怎么修改 python_怎么发送邮箱-2分钟教会你如何利用Python库定时或者批量发送电子邮件...

本文介绍下如何用smtplib发送email。工作中如果每天需要发送日报啊&#xff0c;或者需要把相同的电子邮件发给不同顾客啊&#xff0c;定时发送某些提示邮件啊。学会这个就不会担心会忘记发了。下面的代码本人测试过没问题。#导入smtplib库import smtplib#导入我们需要的email模…