diff -r 000000000000 -r bde4ae8d615e os/graphics/graphicstest/uibench/s60/src/geometrystructs.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os/graphics/graphicstest/uibench/s60/src/geometrystructs.cpp Fri Jun 15 03:10:57 2012 +0200 @@ -0,0 +1,251 @@ +// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +/* + * Portions of this code, in particular the fghCircleTable function and the code to + * calculate the vertices for the solid sphere, is ported from freeglut_geometry.cpp + * which is distributed under the following terms: + * + ****************************************************************** + * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved. + * Written by Pawel W. Olszta, + * Creation date: Fri Dec 3 1999 + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + ********************************************************************* + * Apart from porting to use Open GL ES instead of Open GL the other major change is + * to separate out the code that calculates vertices from the code that draws the shape. + */ + + +#include "geometrystructs.h" + +#include +#include + + +float sin(float x) + { + double t = x; + double r; + TInt error = Math::Sin(r,t); + ASSERT(error==KErrNone); + return r; + } + +float cos(float x) + { + double t = x; + double r; + TInt error = Math::Cos(r,t); + ASSERT(error==KErrNone); + return r; + } + +int abs(int x) + { + return Abs(x); + } + +Vertex3F::Vertex3F(float x, float y, float z) + :iX(x), iY(y), iZ(z) + { + } + +Vertex3F::Vertex3F() +:iX(0), iY(0), iZ(0) + { + } + +int fghCircleTable(float **sint,float **cost,const int n) +{ + int i; + + /* Table size, the sign of n flips the circle direction */ + const int size = abs(n); + + /* Determine the angle between samples */ + const float angle = 2*KPi/(float)( ( n == 0 ) ? 1 : n ); + + /* Allocate memory for n samples, plus duplicate of first entry at the end */ + *sint = new float[sizeof(float) * size+1]; + + if(*sint==NULL) + { + return KErrNoMemory; + } + + *cost = new float[sizeof(float) * size+1]; + + if(*cost==NULL) + { + delete[] sint; + return KErrNoMemory; + } + + /* Compute cos and sin around the circle */ + (*sint)[0] = 0.0; + (*cost)[0] = 1.0; + + for (i=1; iConstructL(aRadius); + return self; + } + +CSolidSphere::~CSolidSphere() + { + delete[] iTopVertices; + delete[] iTopNormals; + delete[] iBottomVertices; + delete[] iBottomNormals; + delete[] iStackVertices; + delete[] iStackNormals; + } + +void CSolidSphere::Draw() const + { +//top fan + glVertexPointer(3, GL_FLOAT, 0, iTopVertices); + glNormalPointer(GL_FLOAT, 0, iTopNormals); + glDrawArrays(GL_TRIANGLE_FAN, 0, iSlices+2); +//stacks, one at a time + glVertexPointer(3, GL_FLOAT, 0, iStackVertices); + glNormalPointer(GL_FLOAT, 0, iStackNormals); + TInt offset = 0; + TInt verticesPerStack = (iSlices+1)*2; + for(TInt i=1; i0)?1:0]; + r0 = 0.0; + r1 = sint2[(iStacks>0)?1:0]; + + iTopVertices = new (ELeave) Vertex3F[iSlices+2]; + iTopNormals = new (ELeave) Vertex3F[iSlices+2]; + TInt topVerticesIndex = 0; + iTopVertices[topVerticesIndex] = Vertex3F(0,0,aRadius); + iTopNormals[topVerticesIndex] = Vertex3F(0,0,1); + for(j=iSlices; j>=0; j--) + { + topVerticesIndex++; + Vertex3F vertex(cost1[j]*r1*aRadius, sint1[j]*r1*aRadius, z1*aRadius); + iTopVertices[topVerticesIndex] = vertex; + Vertex3F normal(cost1[j]*r1, sint1[j]*r1, z1 ); + iTopNormals[topVerticesIndex] = normal; + } + + //*calculate the vertices for each stack + TInt stackVertexCount = ((iSlices+1)*2) *iStacks; + iStackVertices = new (ELeave) Vertex3F[stackVertexCount]; + iStackNormals = new (ELeave) Vertex3F[stackVertexCount]; + TInt stackIndex = 0; + for( i=1; i