|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
На страницу группы практики...
/* FILE NAME: SICOASM.C * PROGRAMMER: VG4 * DATE: 08.06.2011 * PURPOSE: Assembler usage at C * for 3D math optimization. * * Автор: Виталий Галинский. * Дата: 08.06.2011 * Летняя учебно-исследовательская практика ФМЛ № 30, 2011 год. * Группа компьютерной графики. * Copyright © 2011 * Computer Graphics Support Group of 30 Phys-Math Lyceum * © 2011 Физико-математический лицей № 30, Санкт-Петербург. */ #define DEGREE2RADIANL 0.01745329251994329576L /* Base float-point data type */ typedef double DBL; /* Vector representation type */ typedef struct tagVEC { DBL X, Y, Z; /* Vector coordinates */ } VEC; /* Matrix represetation type */ typedef struct tagMATR { /* Matrix elements */ DBL A11, A12, A13, A21, A22, A23, A31, A32, A33, A41, A42, A43; } MATR; /*** * Global data ***/ /* Unit matrix constant */ MATR UnitMatrix = { 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 }; /* Multiplyer degree to radian constant */ long double MultiplierDegree2Radian = DEGREE2RADIANL; /* Vector rotation to Z function. * ARGUMENTS: * - vector to rotation: * tarVEC V; * - angle to rotation; * RETURNS: * (tarVEC) result vector. */ VEC VecRotateZ( VEC V, DBL AngleInDegree ) { DBL sine, cosine, tmp; __asm { /* FST(0) Angle (from degree to radian) */ fld AngleInDegree fmul MultiplierDegree2Radian /* FST(0) - cos, FST(1) - sin */ fsincos fstp cosine /* cos -> cosine */ fstp sine /* sin -> sine */ } tmp = V.X * cosine - V.Y * sine; V.Y = V.X * sine + V.Y * cosine; V.X = tmp; return V; } /* End of 'VecRotateZ' function */ /* Create rotate matrix around Z axis function. * ARGUMENTS: * - rotation angle in degrees: * DBL AngleInDegree; * RETURNS: * (tarMATR) created matrix. */ MATR MatrSetRotateZ( DBL AngleInDegree ) { MATR m = UnitMatrix; __asm { /* FST(0) Angle (from degree to radian) */ fld AngleInDegree fmul MultiplierDegree2Radian /* FST(0) - cos, FST(1) - sin */ fsincos fld st(0) fstp m.A11 /* cos -> a11 */ fstp m.A22 /* cos -> a22 */ fld st(0) /* duplicate st(0) */ fstp m.A12 /* sin -> a12 */ fldz /* push 0 (st(0) = 0) */ fsubr /* st(0) = 0 - sin() */ fstp m.A21 /* -sin -> a21 */ } return m; } /* End of 'MatrSetRotateZ' function */ /* The main program function */ void main( void ) { VEC v = {1, 2, 3}; MATR m; m = MatrSetRotateZ(30); v = VecRotateZ(v, 30); } /* End of 'main' function */ /* END OF 'SICOASM.C' FILE */ |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|