From 9a101018b965996248f79817d289c4dc94f454e8 Mon Sep 17 00:00:00 2001 From: Andrew Poor Date: Thu, 21 Jul 2016 11:57:52 +0100 Subject: [PATCH] Primitive sphere is now generated top-down, so that its orientation is what would be expected. It is now in line with how the other shapes are handled. Change-Id: I44dafac9f4f16e0a11d348a6ff905f9a827ce056 --- .../renderers/primitive/primitive-renderer.cpp | 21 ++++++++++----------- .../control-renderers.md | 4 ++-- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/dali-toolkit/internal/controls/renderers/primitive/primitive-renderer.cpp b/dali-toolkit/internal/controls/renderers/primitive/primitive-renderer.cpp index 1ed6404..8f30a74 100644 --- a/dali-toolkit/internal/controls/renderers/primitive/primitive-renderer.cpp +++ b/dali-toolkit/internal/controls/renderers/primitive/primitive-renderer.cpp @@ -74,7 +74,7 @@ const char * const BEVELLED_CUBE_LABEL( "BEVELLED_CUBE" ); const char * const OBJECT_MATRIX_UNIFORM_NAME( "uObjectMatrix" ); const char * const COLOR_UNIFORM_NAME( "uColor" ); const char * const OBJECT_DIMENSIONS_UNIFORM_NAME( "uObjectDimensions" ); -const char * const STAGE_SIZE_UNIFORM_NAME( "uStageSize" ); +const char * const STAGE_OFFSET_UNIFORM_NAME( "uStageOffset" ); //Vertex properties const char * const POSITION( "aPosition"); @@ -95,7 +95,7 @@ const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( uniform mediump mat3 uNormalMatrix;\n uniform mediump mat4 uObjectMatrix;\n uniform mediump vec3 uLightPosition;\n - uniform mediump vec3 uStageSize;\n + uniform mediump vec2 uStageOffset;\n void main()\n {\n @@ -111,8 +111,7 @@ const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n vec3 normal = uNormalMatrix * mat3( uObjectMatrix ) * aNormal;\n - vec3 stageOffset = vec3( uStageSize.xy, 0 ) / 2.0;\n - vec4 lightPosition = vec4( ( uLightPosition - stageOffset ), 1.0 );\n + vec4 lightPosition = vec4( ( uLightPosition.xy - uStageOffset ), uLightPosition.z, 1.0 );\n lightPosition = uViewMatrix * lightPosition;\n vec3 vectorToLight = normalize( lightPosition.xyz - mvVertexPosition.xyz );\n @@ -437,7 +436,7 @@ void PrimitiveRenderer::UpdateShaderUniforms() Matrix scaleMatrix; scaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) ); - mShader.RegisterProperty( STAGE_SIZE_UNIFORM_NAME, Vector3( width, height, std::min( width, height ) ) ); + mShader.RegisterProperty( STAGE_OFFSET_UNIFORM_NAME, Vector2( width, height ) / 2.0f ); mShader.RegisterProperty( LIGHT_POSITION_UNIFORM_NAME, mLightPosition ); mShader.RegisterProperty( OBJECT_MATRIX_UNIFORM_NAME, scaleMatrix ); mShader.RegisterProperty( COLOR_UNIFORM_NAME, mColor ); @@ -600,8 +599,8 @@ void PrimitiveRenderer::ComputeSphereVertices( Vector& vertices, int sli float z; //Top stack. - vertices[vertexIndex].position = Vector3( 0.0, 0.0, 0.5 ); - vertices[vertexIndex].normal = Vector3( 0.0, 0.0, 1.0 ); + vertices[vertexIndex].position = Vector3( 0.0, 0.5, 0.0 ); + vertices[vertexIndex].normal = Vector3( 0.0, 1.0, 0.0 ); vertexIndex++; //Middle stacks. @@ -610,8 +609,8 @@ void PrimitiveRenderer::ComputeSphereVertices( Vector& vertices, int sli for( int j = 0; j < slices; j++, vertexIndex++ ) { x = cosTable1[j] * sinTable2[i]; - y = sinTable1[j] * sinTable2[i]; - z = cosTable2[i]; + y = cosTable2[i]; + z = sinTable1[j] * sinTable2[i]; vertices[vertexIndex].position = Vector3( x / 2.0f, y / 2.0f, z / 2.0f ); vertices[vertexIndex].normal = Vector3( x, y, z ); @@ -619,8 +618,8 @@ void PrimitiveRenderer::ComputeSphereVertices( Vector& vertices, int sli } //Bottom stack. - vertices[vertexIndex].position = Vector3( 0.0, 0.0, -0.5 ); - vertices[vertexIndex].normal = Vector3( 0.0, 0.0, -1.0 ); + vertices[vertexIndex].position = Vector3( 0.0, -0.5, 0.0 ); + vertices[vertexIndex].normal = Vector3( 0.0, -1.0, 0.0 ); } void PrimitiveRenderer::FormSphereTriangles( Vector& indices, int slices, int stacks ) diff --git a/docs/content/shared-javascript-and-cpp-documentation/control-renderers.md b/docs/content/shared-javascript-and-cpp-documentation/control-renderers.md index 010a385..2e1f063 100644 --- a/docs/content/shared-javascript-and-cpp-documentation/control-renderers.md +++ b/docs/content/shared-javascript-and-cpp-documentation/control-renderers.md @@ -538,14 +538,14 @@ Bevel percentage ranges from 0.0 to 1.0. It affects the ratio of the outer face ### Slices {#slices-details} -For spheres and conical frustrums, 'slices' determines how many divisions there are as you go around the object. Note that spheres are rendered along the Z-axis, and so will appear rotated. +For spheres and conical frustrums, 'slices' determines how many divisions there are as you go around the object. ![ ](../assets/img/renderers/slices.png) ![ ](renderers/slices.png) ### Stacks {#stacks-details} -For spheres, 'stacks' determines how many layers there are as you go down the object. Note that spheres are rendered along the Z-axis, and so will appear rotated. +For spheres, 'stacks' determines how many layers there are as you go down the object. ![ ](../assets/img/renderers/stacks.png) ![ ](renderers/stacks.png) -- 2.7.4