亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? t3dlib4.cpp

?? 3D游戲編程大師技巧第十一章的源代碼
?? CPP
?? 第 1 頁 / 共 5 頁
字號:
// T3DLIB4.CPP - Game Engine Part IV, Basic Math Engine Part I
 
// INCLUDES ///////////////////////////////////////////////////

#define WIN32_LEAN_AND_MEAN  

//#ifndef INITGUID
//#define INITGUID       // you need this or DXGUID.LIB
//#endif

#include <windows.h>   // include important windows stuff
#include <windowsx.h> 
#include <mmsystem.h>
#include <objbase.h>
#include <iostream.h> // include important C/C++ stuff
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <math.h>
#include <io.h>
#include <fcntl.h>
#include <direct.h>
#include <wchar.h>

#include <ddraw.h>      // needed for defs in T3DLIB1.H 
#include "T3DLIB1.H"    // T3DLIB4 is based on some defs in this 
#include "T3DLIB4.H"

// DEFINES ////////////////////////////////////////////////

// TYPES //////////////////////////////////////////////////

// PROTOTYPES /////////////////////////////////////////////

// EXTERNALS /////////////////////////////////////////////

extern HWND main_window_handle;     // access to main window handle in main module

// GLOBALS ////////////////////////////////////////////////

// FUNCTIONS //////////////////////////////////////////////

FIXP16 FIXP16_MUL(FIXP16 fp1, FIXP16 fp2)
{
// this function computes the product fp_prod = fp1*fp2
// using 64 bit math, so as not to loose precission

FIXP16 fp_prod; // return the product

_asm {
     mov eax, fp1      // move into eax fp2
     imul fp2          // multiply fp1*fp2
     shrd eax, edx, 16 // result is in 32:32 format 
                       // residing at edx:eax
                       // shift it into eax alone 16:16
     // result is sitting in eax
     } // end asm

} // end FIXP16_MUL

///////////////////////////////////////////////////////////////

FIXP16 FIXP16_DIV(FIXP16 fp1, FIXP16 fp2)
{
// this function computes the quotient fp1/fp2 using
// 64 bit math, so as not to loose precision

_asm {
     mov eax, fp1      // move dividend into eax
     cdq               // sign extend it to edx:eax
     shld edx, eax, 16 // now shift 16:16 into position in edx
     sal eax, 16       // and shift eax into position since the
                       // shld didn't move it -- DUMB! uPC
     idiv fp2          // do the divide
     // result is sitting in eax     
     } // end asm

} // end FIXP16_DIV

///////////////////////////////////////////////////////////////

void FIXP16_Print(FIXP16 fp)
{
// this function prints out a fixed point number
Write_Error("\nfp=%f", (float)(fp)/FIXP16_MAG);

} // end FIXP16_Print

///////////////////////////////////////////////////////////////

void QUAT_Add(QUAT_PTR q1, QUAT_PTR q2, QUAT_PTR qsum)
{
// this function adds two quaternions
qsum->x = q1->x + q2->x;
qsum->y = q1->y + q2->y;
qsum->z = q1->z + q2->z;
qsum->w = q1->w + q2->w;

} // end QUAT_Add

///////////////////////////////////////////////////////////////

 void QUAT_Sub(QUAT_PTR q1, QUAT_PTR q2, QUAT_PTR qdiff)
{
// this function subtracts two quaternions, q1-q2
qdiff->x = q1->x - q2->x;
qdiff->y = q1->y - q2->y;
qdiff->z = q1->z - q2->z;
qdiff->w = q1->w - q2->w;

} // end QUAT_Sub

///////////////////////////////////////////////////////////////

void QUAT_Conjugate(QUAT_PTR q, QUAT_PTR qconj)
{
// this function computes the conjugate of a quaternion
qconj->x = -q->x;
qconj->y = -q->y;
qconj->z = -q->z;
qconj->w = q->w;
} // end QUAT_Conjugate

///////////////////////////////////////////////////////////////

void QUAT_Scale(QUAT_PTR q, float scale, QUAT_PTR qs)
{
// this function scales a quaternion and returns it 
qs->x = scale*q->x;
qs->y = scale*q->y;
qs->z = scale*q->z;
qs->w = scale*q->w;

} // end QUAT_Scale

///////////////////////////////////////////////////////////////

void QUAT_Scale(QUAT_PTR q, float scale)
{
// this function scales a quaternion in place
q->x*=scale;
q->y*=scale;
q->z*=scale;
q->w*=scale;

} // end QUAT_Scale

//////////////////////////////////////////////////////////////

float QUAT_Norm(QUAT_PTR q)
{
// returns the length or norm of a quaterion
return(sqrtf(q->w*q->w + q->x*q->x + q->y*q->y + q->z*q->z));

} // end QUAT_Norm

//////////////////////////////////////////////////////////////

float QUAT_Norm2(QUAT_PTR q)
{
// returns the length or norm of a quaterion squared
return(q->w*q->w + q->x*q->x + q->y*q->y + q->z*q->z);

} // end QUAT_Norm2

/////////////////////////////////////////////////////////////

void QUAT_Normalize(QUAT_PTR q, QUAT_PTR qn)
{
// this functions normalizes the sent quaternion and 
// returns it

// compute 1/length
float qlength_inv = 1.0/(sqrtf(q->w*q->w + q->x*q->x + q->y*q->y + q->z*q->z));

// now normalize
qn->w=q->w*qlength_inv;
qn->x=q->x*qlength_inv;
qn->y=q->y*qlength_inv;
qn->z=q->z*qlength_inv;

} // end QUAT_Normalize

/////////////////////////////////////////////////////////////

void QUAT_Normalize(QUAT_PTR q)
{
// this functions normalizes the sent quaternion in place

// compute length
float qlength_inv = 1.0/(sqrtf(q->w*q->w + q->x*q->x + q->y*q->y + q->z*q->z));

// now normalize
q->w*=qlength_inv;
q->x*=qlength_inv;
q->y*=qlength_inv;
q->z*=qlength_inv;

} // end QUAT_Normalize

//////////////////////////////////////////////////////////////

void QUAT_Unit_Inverse(QUAT_PTR q, QUAT_PTR qi)
{
// this function computes the inverse of a unit quaternion
// and returns the result
// the inverse of a unit quaternion is the conjugate :)
qi->w =  q->w;
qi->x = -q->x;
qi->y = -q->y;
qi->z = -q->z;
} // end QUAT_Unit_Inverse

//////////////////////////////////////////////////////////////

void QUAT_Unit_Inverse(QUAT_PTR q)
{
// this function computes the inverse of a unit quaternion
// in place
// the inverse of a unit quaternion is the conjugate :)
q->x = -q->x;
q->y = -q->y;
q->z = -q->z;
} // end QUAT_Unit_Inverse

/////////////////////////////////////////////////////////////

void QUAT_Inverse(QUAT_PTR q, QUAT_PTR qi)
{
// this function computes the inverse of a general quaternion
// and returns result
// in general, q-1 = *q/|q|2
// compute norm squared
float norm2_inv = 1.0/(q->w*q->w + q->x*q->x + q->y*q->y + q->z*q->z);

// and plug in
qi->w =  q->w*norm2_inv;
qi->x = -q->x*norm2_inv;
qi->y = -q->y*norm2_inv;
qi->z = -q->z*norm2_inv;

} // end QUAT_Inverse

/////////////////////////////////////////////////////////////

void QUAT_Inverse(QUAT_PTR q)
{
// this function computes the inverse of a general quaternion
// in place
// in general, q-1 = *q/|q|2
// compute norm squared
float norm2_inv = 1.0/(q->w*q->w + q->x*q->x + q->y*q->y + q->z*q->z);

// and plug in
q->w =  q->w*norm2_inv;
q->x = -q->x*norm2_inv;
q->y = -q->y*norm2_inv;
q->z = -q->z*norm2_inv;

} // end QUAT_Inverse

/////////////////////////////////////////////////////////////

void QUAT_Mul(QUAT_PTR q1, QUAT_PTR q2, QUAT_PTR qprod)
{
// this function multiplies two quaternions

// this is the brute force method
//qprod->w = q1->w*q2->w - q1->x*q2->x - q1->y*q2->y - q1->z*q2->z;
//qprod->x = q1->w*q2->x + q1->x*q2->w + q1->y*q2->z - q1->z*q2->y;
//qprod->y = q1->w*q2->y - q1->x*q2->z + q1->y*q2->w - q1->z*q2->x;
//qprod->z = q1->w*q2->z + q1->x*q2->y - q1->y*q2->x + q1->z*q2->w;

// this method was arrived at basically by trying to factor the above
// expression to reduce the # of multiplies

float prd_0 = (q1->z - q1->y) * (q2->y - q2->z);
float prd_1 = (q1->w + q1->x) * (q2->w + q2->x);
float prd_2 = (q1->w - q1->x) * (q2->y + q2->z);
float prd_3 = (q1->y + q1->z) * (q2->w - q2->x);
float prd_4 = (q1->z - q1->x) * (q2->x - q2->y);
float prd_5 = (q1->z + q1->x) * (q2->x + q2->y);
float prd_6 = (q1->w + q1->y) * (q2->w - q2->z);
float prd_7 = (q1->w - q1->y) * (q2->w + q2->z);

float prd_8 = prd_5 + prd_6 + prd_7;
float prd_9 = 0.5 * (prd_4 + prd_8);

// and finally build up the result with the temporary products

qprod->w = prd_0 + prd_9 - prd_5;
qprod->x = prd_1 + prd_9 - prd_8;
qprod->y = prd_2 + prd_9 - prd_7;
qprod->z = prd_3 + prd_9 - prd_6;

} // end QUAT_Mul

///////////////////////////////////////////////////////////

void QUAT_Triple_Product(QUAT_PTR q1, QUAT_PTR q2, QUAT_PTR q3, 
                         QUAT_PTR qprod)
{
// this function computes q1*q2*q3 in that order and returns 
// the results in qprod

QUAT qtmp;
QUAT_Mul(q1,q2,&qtmp);
QUAT_Mul(&qtmp, q3, qprod);

} // end QUAT_Triple_Product

///////////////////////////////////////////////////////////

void VECTOR3D_Theta_To_QUAT(QUAT_PTR q, VECTOR3D_PTR v, float theta)
{
// initializes a quaternion based on a 3d direction vector and angle
// note the direction vector must be a unit vector
// and the angle is in rads

float theta_div_2 = (0.5)*theta; // compute theta/2

// compute the quaterion, note this is from chapter 4
// pre-compute to save time
float sinf_theta = sinf(theta_div_2);

q->x = sinf_theta * v->x;
q->y = sinf_theta * v->y;
q->z = sinf_theta * v->z;
q->w = cosf( theta_div_2 );

} // end VECTOR3D_Theta_To_QUAT

///////////////////////////////////////////////////////////////

 void VECTOR4D_Theta_To_QUAT(QUAT_PTR q, VECTOR4D_PTR v, float theta)
{
// initializes a quaternion based on a 4d direction vector and angle
// note the direction vector must be a unit vector
// and the angle is in rads

float theta_div_2 = (0.5)*theta; // compute theta/2

// compute the quaterion, note this is from chapter 4

// pre-compute to save time
float sinf_theta = sinf(theta_div_2);

q->x = sinf_theta * v->x;
q->y = sinf_theta * v->y;
q->z = sinf_theta * v->z;
q->w = cosf( theta_div_2 );

} // end VECTOR4D_Theta_to_QUAT

///////////////////////////////////////////////////////////////

void EulerZYX_To_QUAT(QUAT_PTR q, float theta_z, float theta_y, float theta_x)
{
// this function intializes a quaternion based on the zyx
// multiplication order of the angles that are parallel to the
// zyx axis respectively, note there are 11 other possibilities
// this is just one, later we may make a general version of the
// the function

// precompute values
float cos_z_2 = 0.5*cosf(theta_z);
float cos_y_2 = 0.5*cosf(theta_y);
float cos_x_2 = 0.5*cosf(theta_x);

float sin_z_2 = 0.5*sinf(theta_z);
float sin_y_2 = 0.5*sinf(theta_y);
float sin_x_2 = 0.5*sinf(theta_x);

// and now compute quaternion
q->w = cos_z_2*cos_y_2*cos_x_2 + sin_z_2*sin_y_2*sin_x_2;
q->x = cos_z_2*cos_y_2*sin_x_2 - sin_z_2*sin_y_2*cos_x_2;
q->y = cos_z_2*sin_y_2*cos_x_2 + sin_z_2*cos_y_2*sin_x_2;
q->z = sin_z_2*cos_y_2*cos_x_2 - cos_z_2*sin_y_2*sin_x_2;

} // EulerZYX_To_QUAT

///////////////////////////////////////////////////////////////

void QUAT_To_VECTOR3D_Theta(QUAT_PTR q, VECTOR3D_PTR v, float *theta)
{
// this function converts a unit quaternion into a unit direction
// vector and rotation angle about that vector

// extract theta
*theta = acosf(q->w);

// pre-compute to save time
float sinf_theta_inv = 1.0/sinf(*theta);

// now the vector
v->x    = q->x*sinf_theta_inv;
v->y    = q->y*sinf_theta_inv;
v->z    = q->z*sinf_theta_inv;

// multiply by 2
*theta*=2;

} // end QUAT_To_VECTOR3D_Theta

////////////////////////////////////////////////////////////

void QUAT_Print(QUAT_PTR q, char *name="q")
{
// this function prints out a quaternion
Write_Error("\n%s=%f+[(%f)i + (%f)j + (%f)k]", 
       name, q->w, q->x, q->y, q->z);

} // end QUAT_Print

///////////////////////////////////////////////////////////

float Fast_Sin(float theta)
{
// this function uses the sin_look[] lookup table, but
// has logic to handle negative angles as well as fractional
// angles via interpolation, use this for a more robust
// sin computation that the blind lookup, but with with
// a slight hit in speed

// convert angle to 0-359
theta = fmodf(theta,360);

// make angle positive
if (theta < 0) theta+=360.0;

// compute floor of theta and fractional part to interpolate
int theta_int    = (int)theta;
float theta_frac = theta - theta_int;

// now compute the value of sin(angle) using the lookup tables
// and interpolating the fractional part, note that if theta_int
// is equal to 359 then theta_int+1=360, but this is fine since the
// table was made with the entries 0-360 inclusive
return(sin_look[theta_int] + 
       theta_frac*(sin_look[theta_int+1] - sin_look[theta_int]));

} // end Fast_Sin

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
狠狠色狠狠色综合日日91app| 成人午夜av在线| 亚洲成人免费影院| 一区二区三区精品在线| 亚洲欧洲国产专区| 亚洲桃色在线一区| 亚洲夂夂婷婷色拍ww47| 亚洲一区二区视频| 韩国中文字幕2020精品| 免费av网站大全久久| 男人的天堂亚洲一区| 精品在线免费视频| 国精产品一区一区三区mba视频 | 久久久久久久av麻豆果冻| 日韩精品一区二区三区老鸭窝| 日韩一二三四区| 欧美xxx久久| 久久精品视频在线看| 国产精品美女久久久久av爽李琼| 国产精品久久影院| 一区二区三区四区在线| 亚洲国产成人高清精品| 蜜桃视频在线观看一区| 国产伦精品一区二区三区视频青涩 | 在线观看日韩国产| 欧美日韩国产中文| 精品国产一区二区三区av性色| 久久人人爽人人爽| 国产精品成人一区二区艾草| 亚洲综合免费观看高清完整版在线| 午夜精品福利久久久| 捆绑紧缚一区二区三区视频| 国产伦理精品不卡| 91行情网站电视在线观看高清版| 欧美老人xxxx18| 久久综合九色综合欧美就去吻| 国产精品乱子久久久久| 一区二区三区日韩在线观看| 日本特黄久久久高潮| 国产一区二区久久| 91小视频在线免费看| 欧美日韩国产欧美日美国产精品| 日韩欧美中文字幕制服| 国产精品国产三级国产aⅴ无密码| 亚洲视频一二三| 老司机午夜精品| 国产一区二区三区视频在线播放| 91亚洲国产成人精品一区二三| 欧美日韩视频专区在线播放| 国产欧美一区二区精品久导航| 最新欧美精品一区二区三区| 亚洲bt欧美bt精品| 成人少妇影院yyyy| 777亚洲妇女| 日韩精品每日更新| 国产福利一区二区三区视频在线| 色www精品视频在线观看| 欧美tk丨vk视频| 亚洲小少妇裸体bbw| 高清av一区二区| 91麻豆精品国产91久久久资源速度 | 91福利国产成人精品照片| 欧美电视剧在线看免费| 亚洲欧美色图小说| 久久99国产精品久久| 欧美伊人久久久久久午夜久久久久| 精品国产91久久久久久久妲己| 亚洲精品久久7777| 国产91丝袜在线18| 精品久久久久一区二区国产| 亚洲午夜影视影院在线观看| 国产成人精品免费在线| 91精品国产综合久久久久| 自拍偷拍亚洲综合| 国产东北露脸精品视频| 91精品国产综合久久久久久| 亚洲人xxxx| 成人黄动漫网站免费app| 26uuuu精品一区二区| 亚洲成人午夜电影| 在线一区二区三区做爰视频网站| 中文字幕免费不卡在线| 麻豆国产精品官网| 欧美精品日日鲁夜夜添| 一区二区三区在线免费观看| 成人性生交大片免费看在线播放| 欧美大胆人体bbbb| 日本中文字幕一区二区视频 | 欧美制服丝袜第一页| 国产精品欧美一级免费| 国产suv精品一区二区6| 欧美精品一区二区三区一线天视频 | 最新国产成人在线观看| 懂色av一区二区夜夜嗨| 久久久精品中文字幕麻豆发布| 丝袜美腿成人在线| 7777精品伊人久久久大香线蕉的 | 国产色产综合产在线视频| 久久国产麻豆精品| 日韩一区二区免费电影| 午夜精品福利一区二区三区av| 欧美综合一区二区| 伊人夜夜躁av伊人久久| 色乱码一区二区三区88| 亚洲精品国产视频| 色婷婷亚洲婷婷| 一区二区在线观看免费 | 国产精品视频看| 大胆亚洲人体视频| 国产女同互慰高潮91漫画| 国产成人在线电影| 国产欧美久久久精品影院| 成人综合日日夜夜| 日韩毛片精品高清免费| 色哟哟亚洲精品| 亚洲成av人片| 91精品国产综合久久久久久久久久 | 在线中文字幕一区| 午夜欧美电影在线观看| 欧美日韩一区二区在线观看 | 不卡在线观看av| 国产精品久久久久影院亚瑟| 91美女在线看| 亚洲va欧美va国产va天堂影院| 欧美一级免费大片| 97精品久久久午夜一区二区三区| 亚洲国产高清aⅴ视频| 91色|porny| 亚洲成人在线观看视频| 日韩欧美一级在线播放| 国产精品一区二区三区网站| 国产精品短视频| 在线观看一区二区视频| 奇米一区二区三区av| 久久这里只有精品6| 99久久婷婷国产综合精品电影| 亚洲一级电影视频| 精品国产一区久久| 91视频一区二区三区| 日韩不卡一二三区| 久久精品视频一区二区| 91国产免费看| 国产综合色视频| 亚洲一区国产视频| 日韩欧美一级在线播放| 成人a级免费电影| 日本一区中文字幕| 欧美国产丝袜视频| 欧美精品乱码久久久久久按摩| 国产综合色产在线精品| 亚洲女爱视频在线| 欧美一二区视频| 99re这里都是精品| 久久精品av麻豆的观看方式| 亚洲欧洲美洲综合色网| 777久久久精品| av电影天堂一区二区在线| 视频在线在亚洲| 综合av第一页| 精品国产成人系列| 日本精品视频一区二区三区| 精品一区二区三区在线观看| 亚洲激情六月丁香| 久久先锋影音av| 欧美日韩国产一级| 成人免费毛片高清视频| 日本亚洲三级在线| 成人免费小视频| 欧美精品一区二区三区久久久| 91久久精品日日躁夜夜躁欧美| 国产麻豆欧美日韩一区| 亚洲成人动漫精品| 亚洲欧美一区二区三区极速播放| 亚洲精品一区二区三区在线观看| 欧美在线看片a免费观看| 成人精品视频网站| 激情综合色综合久久综合| 亚洲精品美国一| 欧美国产一区在线| 欧美电影免费观看完整版| 亚洲精品视频在线观看网站| 亚洲一区二区偷拍精品| 久久国产生活片100| 久久综合色鬼综合色| 国产成人精品1024| 成人天堂资源www在线| 中文字幕在线观看不卡视频| 麻豆国产精品一区二区三区| 欧美日韩久久久一区| 久久午夜免费电影| 亚洲精选免费视频| 国产mv日韩mv欧美| 久久中文字幕电影| 喷水一区二区三区| 777午夜精品视频在线播放| 亚洲免费av在线| 日韩三级中文字幕| 亚洲国产一区视频| 欧美性大战久久久久久久蜜臀| 欧美日韩国产综合一区二区|