void VoxelTreeGenerator::generateSegments()
{
	int width = mpTargetChunk->getWidth();
	int height = mpTargetChunk->getWidth();
	int depth = mpTargetChunk->getDepth();

	vec3 startPoint = vec3(width / 2.0f, 0.0f, depth / 2.0f);
	vec3 direction = glm::normalize(vec3(0.1f, 1.0f, 0.1f));

	float length = height / 5.0f;

	generateSegments(startPoint, direction, length, 0);
}
vector<Segment> generateCollection(vector<Trajectory> &trajs, double epsilon){
	vector<Segment> ret;
	int i = 0;
	progress::begin();
	for(Trajectory &t : trajs){
		progress::step("building segs ", i, 1, trajs.size());
		vector<Segment> segs = generateSegments(t, epsilon, i);
		t.start_index = ret.size()-1;
		t.fragments_size = segs.size();
		ret.insert(ret.end(), segs.begin(), segs.end());
		i++;
	}
	progress::done();
	return ret;
}
void VoxelTreeGenerator::generateSegments(const vec3& startPoint, const vec3& direction, float length, int itCount)
{
	if (itCount < 7)
	{
		LineSegment segment;
		segment.start = startPoint;
		segment.end = startPoint + direction * length;

		mSegments.push_back(segment);

		float nextLength = length / 1.2f;

		vec3 xRotationVec = glm::normalize(glm::cross(direction, vec3(1.0f, 0.0f, 0.0f)));
		vec3 yRotationVec = glm::normalize(glm::cross(direction, vec3(0.0f, 1.0f, 0.0f)));
		vec3 zRotationVec = glm::normalize(glm::cross(direction, vec3(0.0f, 0.0f, 1.0f)));

		mat4 identity = mat4(1.0f);

		for (int i = 0; i < 6; i++)
		{
			vec3 newDirection = direction;
		
			float randX = ((rand() / (float)RAND_MAX) - 0.5f) * 10.0f * (5 - itCount);
			float randY = ((rand() / (float)RAND_MAX) - 0.5f) * 10.0f * (5 - itCount);
			float randZ = ((rand() / (float)RAND_MAX) - 0.5f) * 10.0f * (5 - itCount);

			mat4 rotationMatrix(1.0f);

			rotationMatrix = glm::rotate(rotationMatrix, randX, xRotationVec);
			rotationMatrix = glm::rotate(rotationMatrix, randY, yRotationVec);
			rotationMatrix = glm::rotate(rotationMatrix, randZ, zRotationVec); 

			newDirection = (mat3)rotationMatrix * newDirection;

			newDirection = glm::normalize(newDirection);

			generateSegments(segment.end, newDirection, nextLength, itCount + 1);
		}
	}
}
示例#4
0
文件: logic.cpp 项目: genau7/openGL
FigL::FigL(){
	generateSegments(123);
	//angle
}
示例#5
0
文件: logic.cpp 项目: genau7/openGL
FigT::FigT(){
	generateSegments(124);
}
示例#6
0
文件: logic.cpp 项目: genau7/openGL
FigStrip::FigStrip(){
	generateSegments(379);
}
示例#7
0
文件: logic.cpp 项目: genau7/openGL
FigS::FigS(){
	generateSegments(1234);
}
示例#8
0
文件: logic.cpp 项目: genau7/openGL
FigSquare::FigSquare( ){
	generateSegments(134);
}