⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 urot.c

📁 图形处理算法合集3:包括图形处理、帧缓存技术、渲染、矩阵运算、建模方法
💻 C
字号:
/* urot.c *//* Generates a uniform random rotation *//* Ken Shoemake, September 1991 */#include <stdlib.h>#include <math.h>#include "GraphicsGems.h"/* Define an INT32 value to be a 32 bit signed integer */typedef int INT32;typedef struct {float x, y, z, w;} Quat;enum QuatPart {X, Y, Z, W, QuatLen, V=0};/* * * * * *  Utility for quaternion conversion * * * * * *//** Qt_ToMatrix *  Construct rotation matrix from quaternion (unit or not). *  Assumes matrix is used to multiply row vector on the right: *  vnew = vold mat.  Works correctly for right-handed coordinate system *  and right-handed rotations. For column vectors or for left-handed *  coordinate systems, transpose the matrix. */void Qt_ToMatrix(Quat q, Matrix3 *out){	double norm = q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w;	double s = (norm > 0.0) ? 2.0/norm : 0.0;	double xs = q.x*s,		ys = q.y*s,		zs = q.z*s;	double wx = q.w*xs,	wy = q.w*ys,	wz = q.w*zs,		 	xx = q.x*xs,	xy = q.x*ys,	xz = q.x*zs,		 	yy = q.y*ys,	yz = q.y*zs,	zz = q.z*zs;	double (*mat)[3] = out->element;	mat[X][X] = 1.0 - (yy + zz); mat[X][Y] = xy + wz; mat[X][Z] = xz - wy;	mat[Y][X] = xy - wz; mat[Y][Y] = 1.0 - (xx + zz); mat[Y][Z] = yz + wx;	mat[Z][X] = xz + wy; mat[Z][Y] = yz - wx; mat[Z][Z] = 1.0 - (xx + yy);} /* Qt_ToMatrix *//* * * * * *  How to do it using gaussians * * * * * *//** Qt_RandomG *  Generate uniform random unit quaternion from random seed. */Quat Qt_RandomG(INT32 *argseed){/*  This algorithm generates a gaussian deviate for each coordinate, so *  the total effect is to generate a symmetric 4-D gaussian distribution, *  by separability. Projecting onto the surface of the hypersphere gives *  a uniform distribution. */	Quat q;	/* uurand generates doubles uniformly distributed between 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -