#include "pw/geometry/primitives.hpp"

namespace pw {

geometry primitives::box(real_t size_x,real_t size_y, real_t size_z)
{
    geometry m;

    geometry::vertex3array_t vertices;

//    vertices.push_back( { -size_x / 2,-size_y / 2, size_z / 2 } ); // 0
//    vertices.push_back( { size_x / 2,-size_y / 2, size_z / 2 } ); // 1
//    vertices.push_back( { size_x / 2, size_y / 2, size_z / 2 } ); // 2
//    vertices.push_back( {-size_x / 2, size_y / 2, size_z / 2} ); // 3

//    vertices.push_back( {-size_x / 2,-size_y / 2,-size_z / 2} ); // 4
//    vertices.push_back( { size_x / 2,-size_y / 2,-size_z / 2}); // 5
//    vertices.push_back( { size_x / 2, size_y / 2,-size_z / 2}); // 6
//    vertices.push_back( {-size_x / 2, size_y / 2,-size_z / 2}); // 7

//	mesh::indexarray_t indices = {
//		0, 1, 2, //  0
//		2, 3, 0, //  1
//		1, 5, 6, //  2
//		6, 2, 1, //  3
//		5, 4, 7, //  4
//		7, 6, 5, //  5
//		4, 0, 3, //  6
//		3, 7, 4, //  7
//		3, 2, 6, //  8
//		6, 7, 3, //  9
//		4, 5, 1, // 10
//		1, 0, 4  // 11
//	};

//	m.set_indices(indices);

	return m;
}

geometry primitives::sphere(real_t radius,int divisions_latitude,int divisions_longitude)
{
	using std::cos;
	using std::sin;

	const real_t _division_lat = real_t(360.0) / divisions_latitude;
	const real_t _division_lon = real_t(360.0) / divisions_longitude;

    geometry geom;

    geom.set_topology(geometry::topology_type::triangle_strip);

	real_t x, y, z;

	for (real_t _latitude = 0; _latitude < 360; _latitude += _division_lat)
	{
		for (real_t _longitude = 0; _longitude < 360; _longitude += _division_lon)
		{
			x = sin ( deg_to_rad(_longitude) ) * cos ( (_latitude + _division_lat) );
			y = sin ( deg_to_rad(_latitude + _division_lat) );
			z = cos ( deg_to_rad(_longitude) * cos ( deg_to_rad(_latitude + _division_lat) ) );

//			geom.
			// assign the second normal and vertex
//			res->addVertexNormal(tpVec3r(x * radius,y * radius,z * radius),
//								 tpVec3r(x,y,z)
//								 );

			// calculate the coordinates
			x = sin ( deg_to_rad(_longitude) ) * cos (deg_to_rad(_latitude) );
			y = sin ( deg_to_rad(_latitude) );
			z = cos ( deg_to_rad(_longitude) ) * cos (deg_to_rad(_latitude) );

			// assign a normal and a vertex
//			res->addVertexNormal(
//						tpVec3r(x * radius,y * radius,z * radius),
//						tpVec3r(x,y,z)
//						);

		}
	}

	return geom;
}

}
