00001 /*! \file 00002 * X-Forge Util <br> 00003 * Copyright 2000-2003 Fathammer Ltd 00004 * 00005 * \brief UV Coordinate manipulation routines 00006 * 00007 * $Id: XFuUVManipulator.cpp,v 1.7 2003/08/12 13:34:08 lars Exp $ 00008 * $Date: 2003/08/12 13:34:08 $ 00009 * $Revision: 1.7 $ 00010 */ 00011 00012 #include <xfcore/XFcCore.h> 00013 #include <xfutil/XFuUVManipulator.h> 00014 00015 void XFuUVManipulator::generateEnvmapCoordinates(XFcGLVertexBuffer *aVertexBuffer, XFcGL *aGL) 00016 { 00017 if (aVertexBuffer->getFlags() == (XFCGLVF_XYZ | 00018 XFCGLVF_NORMAL | 00019 XFCGLVF_DIFFUSECOLOR | 00020 XFCGLVF_TEXTURE1)) 00021 { 00022 INT32 *v = (INT32*)aVertexBuffer->lock(XFCGLVBLOCK_MODIFY); 00023 if (v != NULL) 00024 { 00025 INT32 t = aVertexBuffer->getNumVertices(); 00026 INT32 i; 00027 00028 XFcMatrix4 m, tm; 00029 aGL->getMatrix(XFCGLMAT_VIEW, tm); 00030 aGL->getMatrix(XFCGLMAT_WORLD, m); 00031 m *= tm; 00032 00033 // remove translation from above matrix 00034 m.m[3][0] = REALi(0); 00035 m.m[3][1] = REALi(0); 00036 m.m[3][2] = REALi(0); 00037 m.m[3][3] = REALi(1); 00038 00039 // cycle through all vertices in buffer 00040 for (i = 0; i < t; i++) 00041 { 00042 00043 XFcVector4 vec, rvec; 00044 // fetch normal value 00045 #ifndef XFC_USE_FLOAT 00046 vec.x.mValue = v[3]; 00047 vec.y.mValue = v[4]; 00048 vec.z.mValue = v[5]; 00049 #else 00050 vec.x = *((REAL*)&v[3]); 00051 vec.y = *((REAL*)&v[4]); 00052 vec.z = *((REAL*)&v[5]); 00053 #endif 00054 vec.w = REALi(1); 00055 00056 // rotate normals to the camera direction 00057 XFcMath::matrixProject(m, vec, rvec); 00058 00059 REAL w2 = rvec.w * 2; 00060 00061 rvec.x /= w2; // scale rotated normals to -0.5 - 0.5 00062 rvec.y /= w2; 00063 rvec.x += REALf(0.5f); // translate rotated normals to 0 - 1.0 00064 rvec.y += REALf(0.5f); 00065 00066 // overwrite UV coordinates with normal values 00067 #ifndef XFC_USE_FLOAT 00068 v[7] = rvec.x.mValue; 00069 v[8] = rvec.y.mValue; 00070 #else 00071 *((REAL*)&v[7]) = rvec.x; 00072 *((REAL*)&v[8]) = rvec.y; 00073 #endif 00074 v += aVertexBuffer->getVertexStride() / 4; 00075 } 00076 aVertexBuffer->unlock(); 00077 } 00078 } 00079 } 00080
![]() | ||||
![]() |
Confidential Copyright © 2002-2003 Fathammer | with doxygen by Dimitri van Heesch |