void SimpleCamera::setTo(const PVRTVec3& vec) { // find angle from horizontal m_fElevation = f2vt((float) atan(VERTTYPEDIV(vec.y,f2vt(sqrt(vt2f(vec.z*vec.z+vec.x*vec.x)))))); // find principle angle from straight ahead m_fHeading = f2vt((float) atan2(vt2f(vec.x),vt2f(vec.z))); m_fHeading -= PVRT_PI; while(m_fHeading < 0.0f) m_fHeading+=PVRT_TWO_PI; }
/*!**************************************************************************** @Function CreateMorphData @Description Creates the data used for the morphing ******************************************************************************/ void OGLESEvilSkull::CreateMorphData() { unsigned int i,j; unsigned int ui32VertexNo = m_Scene.pMesh[eSkull].nNumVertex; delete[] m_pMorphedVertices; delete[] m_pAVGVertices; m_pMorphedVertices = new VERTTYPE[ui32VertexNo * 3]; m_pAVGVertices = new float[ui32VertexNo * 3]; for(i = 0; i < g_ui32NoOfMorphTargets; ++i) { delete[] m_pDiffVertices[i]; m_pDiffVertices[i] = new float[ui32VertexNo * 3]; memset(m_pDiffVertices[i], 0, sizeof(float) * ui32VertexNo * 3); } unsigned char* pData[g_ui32NoOfMorphTargets]; for(j = 0; j < g_ui32NoOfMorphTargets; ++j) pData[j] = m_Scene.pMesh[eSkull + j].pInterleaved; VERTTYPE *pVertexData; // Calculate AVG Model for Morphing for(i = 0; i < ui32VertexNo * 3; i += 3) { m_pAVGVertices[i + 0] = 0.0f; m_pAVGVertices[i + 1] = 0.0f; m_pAVGVertices[i + 2] = 0.0f; for(j = 0; j < g_ui32NoOfMorphTargets; ++j) { pVertexData = (VERTTYPE*) pData[j]; m_pAVGVertices[i + 0] += vt2f(pVertexData[0]) * 0.25f; m_pAVGVertices[i + 1] += vt2f(pVertexData[1]) * 0.25f; m_pAVGVertices[i + 2] += vt2f(pVertexData[2]) * 0.25f; pData[j] += m_Scene.pMesh[eSkull + j].sVertex.nStride; } } for(j = 0; j < g_ui32NoOfMorphTargets; ++j) pData[j] = m_Scene.pMesh[eSkull + j].pInterleaved; // Calculate Differences for Morphing for(i = 0; i < ui32VertexNo * 3; i += 3) { for(j = 0; j < g_ui32NoOfMorphTargets; ++j) { pVertexData = (VERTTYPE*) pData[j]; m_pDiffVertices[j][i + 0] = m_pAVGVertices[i + 0] - vt2f(pVertexData[0]); m_pDiffVertices[j][i + 1] = m_pAVGVertices[i + 1] - vt2f(pVertexData[1]); m_pDiffVertices[j][i + 2] = m_pAVGVertices[i + 2] - vt2f(pVertexData[2]); pData[j] += m_Scene.pMesh[eSkull + j].sVertex.nStride; } } }
/******************************************************************************* * Function Name : RenderScene * Returns : true if no error occured * Description : Main rendering loop function of the program. The shell will * call this function every frame. *******************************************************************************/ bool OGLESAntialiasedLines::RenderScene() { glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // set up render states glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_uiTexture); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); // translate to centre, animate rotation and scale glMatrixMode(GL_MODELVIEW); glLoadIdentity(); myglTranslate(f2vt(m_iWidth * 0.5f), f2vt(m_iHeight * 0.5f), f2vt(0)); unsigned long ulTime = PVRShellGetTime() % 36000; myglRotate(f2vt(ulTime * 0.01f), f2vt(0), f2vt(0), f2vt(1)); float fScale = vt2f(PVRTSIN(VERTTYPEMUL(PVRT_PI, f2vt(ulTime / 9000.f)))) * 0.5f + 0.6f; myglScale(f2vt(fScale), f2vt(fScale), f2vt(1)); if ((ulTime / 2250) & 1) { // render aliased lines glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, m_uiVbos[2]); glVertexPointer(2, VERTTYPEENUM, sizeof(SVertex), (GLvoid*)offsetof(SVertex, vPosition)); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(SVertex), (GLvoid*)offsetof(SVertex, uiColor)); glLineWidth(c_fLineWidth * fScale); glDrawArrays(GL_LINES, 0, c_iNumLines * 2); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, 0); m_Print3D.DisplayDefaultTitle("Antialiased Lines", "GL_LINES (aliased)", ePVRTPrint3DSDKLogo); } else { // Render antialiased lines with blending glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, m_uiVbos[0]); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_uiVbos[1]); glVertexPointer(2, VERTTYPEENUM, sizeof(STexVertex), (GLvoid*)offsetof(STexVertex, vPosition)); glTexCoordPointer(2, VERTTYPEENUM, sizeof(STexVertex), (GLvoid*)offsetof(STexVertex, vTexcoord)); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(STexVertex), (GLvoid*)offsetof(STexVertex, uiColor)); glDrawElements(GL_TRIANGLES, c_iNumLines * 18, GL_UNSIGNED_SHORT, 0); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glDisable(GL_BLEND); m_Print3D.DisplayDefaultTitle("Antialiased Lines", "Textured rectangles (antialiased)", ePVRTPrint3DSDKLogo); } // Flush all Print3D commands m_Print3D.Flush(); return true; }