void DisplayObject::setRotation(float angle, glm::vec3 axis)
	{
		glm::vec3 normalized = normalize(axis);
		float alpha = angle / 2.0;
		float sinAlpha = sin(alpha);
		setRotationQuaternion(glm::quat(normalized.x * sinAlpha, normalized.y * sinAlpha, normalized.z * sinAlpha, cos(alpha)));
	}
Beispiel #2
0
TEST(TestNodeAAB, TestAABSimple) {
    MockLoader mock;

    auto node = std::make_shared<FTShaderNode<MockShader>>();
    node->setSize(glm::vec3(34, 88, 22));

    node->updateMatrices();
    node->updateAAB(node->getTransformMatrix());
    EXPECT_EQ(node->getAABCenter(), glm::vec3(17, 44, 11));
    EXPECT_EQ(node->getAABHalfExtents(), glm::vec3(17, 44, 11));

    node->setPosition(glm::vec3(542, 2, 7));
    node->updateMatrices();
    node->updateAAB(node->getTransformMatrix());

    EXPECT_EQ(node->getAABCenter(), glm::vec3(17 + 542, 44 + 2, 11 + 7.0f));
    EXPECT_EQ(node->getAABHalfExtents(), glm::vec3(17, 44, 11));

    node->setScale(glm::vec3(5, 2, 7));
    node->updateMatrices();
    node->updateAAB(node->getTransformMatrix());

    EXPECT_EQ(node->getAABCenter(), glm::vec3(17*5 + 542, 44*2 + 2, 11*7 + 7.0f));
    EXPECT_EQ(node->getAABHalfExtents(), glm::vec3(17*5, 44*2, 11*7));

    auto quat = glm::angleAxis((float)M_PI_2, glm::vec3(0, 0, 1));
    node->setRotationQuaternion(quat);
    node->updateMatrices();
    node->updateAAB(node->getTransformMatrix());

    EXPECT_EQ(node->getAABCenter(), glm::vec3(542 - 44 * 2, 2+17 * 5, 11 * 7 + 7.0f));
    EXPECT_EQ(node->getAABHalfExtents(), glm::vec3(44 * 2, 17 * 5, 11 * 7));
}
Beispiel #3
0
TEST(TestNodeAAB, TestAABAnchorPoint) {
    MockLoader mock;

    auto node = std::make_shared<FTShaderNode<MockShader>>();
    node->setAnchorPoint(glm::vec3(0.3f, 0.5f, 0.7f));
    node->setSize(glm::vec3(34, 88, 22));

    node->updateMatrices();
    node->updateAAB(node->getTransformMatrix());
    expectVectorEqual(node->getAABCenter(), glm::vec3(17 - 0.3f * 34, 0, 11 - 0.7f * 22));
    expectVectorEqual(node->getAABHalfExtents(), glm::vec3(17, 44, 11));

    node->setPosition(glm::vec3(542, 2, 7));
    node->updateMatrices();
    node->updateAAB(node->getTransformMatrix());

    expectVectorEqual(node->getAABCenter(), glm::vec3(17 - 0.3f * 34 + 542, 2, 11 - 0.7f * 22 + 7.0f));
    expectVectorEqual(node->getAABHalfExtents(), glm::vec3(17, 44, 11));

    node->setScale(glm::vec3(5, 2, 7));
    node->updateMatrices();
    node->updateAAB(node->getTransformMatrix());

    expectVectorEqual(node->getAABCenter(), glm::vec3((17 - 0.3f * 34) * 5 + 542, 2, (11 - 0.7f * 22) * 7 + 7.0f), 0.00001f);
    expectVectorEqual(node->getAABHalfExtents(), glm::vec3(17 * 5, 44 * 2, 11 * 7));


    auto quat = glm::angleAxis((float)M_PI_2, glm::vec3(0, 0, 1));
    node->setRotationQuaternion(quat);
    node->updateMatrices();
    node->updateAAB(node->getTransformMatrix());

    expectVectorEqual(node->getAABCenter(), glm::vec3(542, 2 + (17 - 0.3f * 34) * 5, (11 - 0.7f * 22) * 7 + 7.0f), 0.00001f);
    expectVectorEqual(node->getAABHalfExtents(), glm::vec3(44 * 2, 17 * 5, 11 * 7));
}
	glm::quat DisplayObject::rotate (float angle, glm::vec3 axis)
	{
		const glm::vec3 normalized = normalize(axis);
		const float alpha = angle / 2.0;
		const float sinAlpha = sin(alpha);
		const glm::quat rotation = glm::quat(normalized.x * sinAlpha, normalized.y * sinAlpha, normalized.z * sinAlpha, cos(alpha));
		setRotationQuaternion(normalize(_rotation * rotation));
		return _rotation;
	}
void RocketRenderer::nextStateEstimate(const state_estimate_t& current_state) {
    glm::quat rotation(current_state.orientation_q[3], current_state.orientation_q[0], current_state.orientation_q[1], current_state.orientation_q[2]);
    setRotationQuaternion(rotation);
    //setPosition(glm::vec3(current_state.pos[0], current_state.pos[1], current_state.pos[2]));
}