- mMaterial = Material::New("Material");
- mMaterial.SetDiffuseColor(Color::WHITE);
- mMaterial.SetAmbientColor(Vector4(0.0, 0.1, 0.1, 1.0));
-
- // Generate a square mesh with a point at the center:
-
- AnimatableMesh::Faces faces;
- // Create triangles joining up the verts
- faces.push_back(0); faces.push_back(1); faces.push_back(2);
- faces.push_back(0); faces.push_back(2); faces.push_back(3);
- faces.push_back(0); faces.push_back(3); faces.push_back(4);
- faces.push_back(0); faces.push_back(4); faces.push_back(5);
- faces.push_back(0); faces.push_back(5); faces.push_back(6);
-
- mMesh = AnimatableMesh::New(7, faces, mMaterial);
- mMesh[0].SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) ); // Center pt
-
- mStencilActor = MeshActor::New(mMesh);
- mStencilActor.SetAffectedByLighting(false);
- mStencilActor.SetCullFace(CullNone); // Allow clockwise & anticlockwise faces
-
- mStartAngleIndex = mStencilActor.RegisterProperty("start-angle", Property::Value(0.0f));
- mRotationAngleIndex = mStencilActor.RegisterProperty("rotation-angle", Property::Value(initialSector));
-
- Source srcStart( mStencilActor, mStartAngleIndex );
- Source srcRot( mStencilActor, mRotationAngleIndex );
-
- // Constrain the vertices of the square mesh to sweep out a sector as the
- // rotation angle is animated.
- mMesh.ApplyConstraint(Constraint::New<Vector3>( mMesh.GetPropertyIndex(1, AnimatableVertex::POSITION),
- srcStart, srcStart, SquareFanConstraint(0)));
- mMesh.ApplyConstraint(Constraint::New<Vector3>( mMesh.GetPropertyIndex(2, AnimatableVertex::POSITION),
- srcStart, srcRot, SquareFanConstraint(0)));
- mMesh.ApplyConstraint(Constraint::New<Vector3>( mMesh.GetPropertyIndex(3, AnimatableVertex::POSITION),
- srcStart, srcRot, SquareFanConstraint(1)));
- mMesh.ApplyConstraint(Constraint::New<Vector3>( mMesh.GetPropertyIndex(4, AnimatableVertex::POSITION),
- srcStart, srcRot, SquareFanConstraint(2)));
- mMesh.ApplyConstraint(Constraint::New<Vector3>( mMesh.GetPropertyIndex(5, AnimatableVertex::POSITION),
- srcStart, srcRot, SquareFanConstraint(3)));
- mMesh.ApplyConstraint(Constraint::New<Vector3>( mMesh.GetPropertyIndex(6, AnimatableVertex::POSITION),
- srcStart, srcRot, SquareFanConstraint(4)));
+ // Create the stencil mesh geometry
+ // 3-----2
+ // | \ / |
+ // | 0--1 , 6
+ // | / \ |
+ // 4-----5
+
+ struct VertexPosition { float angleIndex; Vector2 position1; Vector2 position2; };
+ VertexPosition vertexData[7] = { // With X coordinate inverted to make the animation go anti clockwise from left center
+ { 9.f, Vector2( 0.f, 0.f ), Vector2( 0.f, 0.f ) }, // center point, keep static
+ { 0.f, Vector2( -0.5f, 0.f ), Vector2( -0.5f, 0.f ) }, // vertex 1, 0 degree, keep static
+ { -1.f, Vector2( -0.5f, 0.5f ), Vector2( -0.5f, -0.5f ) }, // -45 ~ 45 degrees ( 0 ~ 45)
+ { 1.f, Vector2( -0.5f, -0.5f ), Vector2( 0.5f, -0.5f ) }, // 45 ~ 135 degrees
+ { 3.f, Vector2( 0.5f, -0.5f ), Vector2( 0.5f, 0.5f ) }, // 135 ~ 225 degrees
+ { 5.f, Vector2( 0.5f, 0.5f ), Vector2( -0.5f, 0.5f ) }, // 225 ~ 315 degrees
+ { 7.f, Vector2( -0.5f, 0.5f ), Vector2( -0.5f, -0.5f ) } // 315 ~ 405 degrees ( 315 ~ 359.999 )
+ };
+ Property::Map vertexFormat;
+ vertexFormat["aAngleIndex"] = Property::FLOAT;
+ vertexFormat["aPosition1"] = Property::VECTOR2;
+ vertexFormat["aPosition2"] = Property::VECTOR2;
+ PropertyBuffer vertices = PropertyBuffer::New( vertexFormat );
+ vertices.SetData( vertexData, 7u );
+
+ unsigned short indexData[15] = { 0,1,2,0,2,3,0,3,4,0,4,5,0,5,6 };
+
+ Geometry meshGeometry = Geometry::New();
+ meshGeometry.AddVertexBuffer( vertices );
+ meshGeometry.SetIndexBuffer( &indexData[0], sizeof( indexData )/sizeof(indexData[0]) );
+
+ // Create shader
+ std::ostringstream vertexShaderStringStream;
+ vertexShaderStringStream<<VERTEX_SHADER_PREFIX<<VERTEX_SHADER;
+ Shader shader = Shader::New( vertexShaderStringStream.str(), FRAGMENT_SHADER );
+
+ // Create renderer
+ Renderer renderer = Renderer::New( meshGeometry, shader );
+
+ mStencilActor = Actor::New();
+ mStencilActor.AddRenderer( renderer );
+ mStencilActor.SetSize(1.f, 1.f);
+
+ // register properties
+ mStartAngleIndex = mStencilActor.RegisterProperty("uStartAngle", 0.f);
+ mRotationAngleIndex = mStencilActor.RegisterProperty("uRotationAngle", initialSector.radian);