그래서 개체 (구)가 있고 구의 y 축을 사용 된 벡터와 정렬하려고합니다. 그것의 중간 점을 그렸다.개체의 Y 축을 부모의 중심점에서 방사하는 벡터로 맞추는 방법
생성 된 모든 객체의 축은 아래와 같이 설정되어 있으므로 월드 공간에서 생성 된 모든 객체는 아래 그림과 같이 축 방향을 갖습니다. 그러나 지역 좌표계의 구체 축이 부모 개체 (서라운드 영역)의 방향으로 y 축을 갖기를 원하지만이 변환을 위해 각 개체에 대해 수행 할 수있는 블랭킷 변환을 확신 할 수 없습니다. 나오다. 아래 그림
은 개체의 원하는 방향이다.
나는이 방향을 필요로하므로 아이는 모두 위쪽을 가리키는들은 아래 두 그림에서처럼, 퐁은 바깥쪽으로 방향을 기준 대신 분야. 따라서 바닥에 구를 생성하려고하면 자식 구가 x 축 상단에서 생성되고 큰 구면과 병합되면서 큰 중심 구에서 바깥쪽으로 향합니다.
아래는 내가 지금 아래
bool static CreateSphereLevels(Sphere *parent, float childRadiusRatio, int levels,
Material** materials)
{
if (levels == 1) {
for (int i = 0; i < 6; i++) {
Sphere * s = new Sphere(childRadiusRatio, materials[i % 6]);
parent->AddChild(s);
float rm = parent->GetRadius() + s->GetRadius();
if (i == 0)
s->SetPosition(vec3(0.0f, rm, 0.0f));
if (i >= 1 && i < 6)
s->SetPosition(vec3(RotationY(60 * i) * vec4(0.0f, rm, 0.0f, 0.0f)));
if (i == 1 || i == 3 || i == 5) {
Sphere * sn = new Sphere(childRadiusRatio, materials[i]);
parent->AddChild(sn);
sn->SetPosition(vec3(RotationY(60 * i) * RotationZ(60) * vec4(0.0f, rm, 0.0f, 0.0f)));
}
}
return true;
}
else {
for (int i = 0; i < 6; i++) {
Sphere * s = new Sphere(childRadiusRatio, materials[i % 6]);
parent->AddChild(s);
int newLevels = levels - 1;
CreateSphereLevels(s, (childRadiusRatio/3), newLevels, materials);
float rm = parent->GetRadius() + s->GetRadius();
if (i == 0)
s->SetPosition(vec3(0.0f, rm, 0.0f));
if (i >= 1 && i < 6)
s->SetPosition(vec3(RotationY(60 * i) * vec4(0.0f, rm, 0.0f, 0.0f)));
if (i == 1 || i == 3 || i == 5) {
Sphere * sn = new Sphere(childRadiusRatio, materials[i]);
parent->AddChild(sn);
CreateSphereLevels(sn, (childRadiusRatio/3), newLevels, materials);
sn->SetPosition(vec3(RotationY(60 * i) * RotationZ(60) * vec4(0.0f, rm, 0.0f, 0.0f)));
}
}
}
return true;
}
(I, 즉 9 그림에 있지만 설명의 사진에 존재하는 구체의 양이 줄어들 이미지를 혼란하지 않는 것보다이 코드에 더 구체를 생성) 구체를 생성하는 코드는 내 개체에서 수행 할 수있는 가능한 변환
#ifndef RAYTRACER_SCENES_SCENEOBJECT_H
#define RAYTRACER_SCENES_SCENEOBJECT_H
#include <Raytracer/Scenes/SceneObjectType.h>
#include <vector>
namespace Raytracer
{
namespace Scenes
{
class SceneObject
{
private:
/**
* The transformation matrix to transform a point from world coordinates to local
* coordinates.
*/
glm::mat4x4 globalTransformation;
glm::mat4x4 transformation;
glm::mat4x4 globalToLocal;
/**
* Updates the global transformation based on the current transformation. This
* includes child objects.
*/
void UpdateTransformations();
std::vector<SceneObject *> children;
SceneObject * parent;
public:
/**
* Constructs a new SceneObject.
*/
SceneObject();
/**
* Destructs a SceneObject and deletes all child objects.
*/
virtual ~SceneObject();
/**
* Adds a new child to this object.
*
* @param child The new child object. This object becomes child's parent object. This
* object takes ownership of child.
* @return true if the child was added successfully, false otherwise.
*/
bool AddChild(SceneObject *child);
/**
* Retrieves a list of all children of this object.
*
* @return A list of all children of this object
*/
const std::vector<SceneObject *> &GetChildren() const;
/**
* Retrieves the position of this object in world space, i.e. the translation component
* of the global transformation matrix.
*
* @return The global position of this object
*/
const glm::vec3 GetGlobalPosition() const;
/**
* Retrieves a matrix that can be used to transform coordinates from world space to
* object space. This is the inverse of the global transformation matrix.
*
* @return The inverse of the global transformation matrix
*/
const glm::mat4x4 &GetGlobalToLocal() const;
/**
* Retrieves the global transformation matrix. The global transformation matrix is used
* to transform coordinates from object space to world space.
*
* @return The global transformation matrix
*/
const glm::mat4x4 &GetGlobalTransformation() const;
/**
* Retrieves the parent object of this object.
*
* @param The parent object of this object or NULL if this object has no parent
*/
SceneObject *GetParent() const;
/**
* Retrieves the position of this object, i.e. the translation component of the
* transformation matrix.
*
* @return The position of the object
*/
const glm::vec3 GetPosition() const;
/**
* Retrieves the transformation matrix. The transformation matrix is used to transform
* coordinates from object space to the object space of the parent object (or world
* space if this object has no parent).
*
* @return The transformation matrix
*/
const glm::mat4x4 &GetTransformation() const;
/**
* Checks whether this instance is of the given type.
*
* @param type The type to check against
* @return true if this object is of type type, false otherwise
*/
virtual bool IsInstanceOf(SceneObjectType type) const = 0;
/**
* Sets the global transformation matrix. The global transformation matrix is used
* to transform coordinates from object space to world space.
*
* @param transformation The new global transformation matrix
*/
void SetGlobalTransformation(const glm::mat4x4 &transformation);
/**
* Sets the position of this object, i.e. the translation component of the
* transformation matrix.
*
* @param position The new position
*/
void SetPosition(const glm::vec3 &position);
/**
* Sets the transformation matrix. The transformation matrix is used to transform
* coordinates from object space to the object space of the parent object (or world
* space if this object has no parent).
*
* @param transformation The new transformation matrix
*/
void SetTransformation(const glm::mat4x4 &transformation);
void ChildRemove(SceneObject * child);
};
}
}
#endif // RAYTRACER_SCENES_SCENEOBJECT_H