GLTeapot: normalize quaternion
Quaternions representing rotation should have unit length. Multiplying quaternions cause error accumulation and length change. Normalizing quaternion after rotation will avoid that. Fixes #7160. Change-Id: I82f1f2b89c326a4d2c956c03296600e79ac267c2 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2270 Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
/*
|
/*
|
||||||
* Original Be Sample source modified to use a quaternion for the object's orientation
|
* Original Be Sample source modified to use a quaternion for the object's orientation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 1999, Be Incorporated. All Rights Reserved.
|
Copyright 1999, Be Incorporated. All Rights Reserved.
|
||||||
This file may be used under the terms of the Be Sample Code License.
|
This file may be used under the terms of the Be Sample Code License.
|
||||||
@@ -84,9 +84,9 @@ GLObject::GLObject(ObjectView* ov)
|
|||||||
z(-2.0),
|
z(-2.0),
|
||||||
fRotation(0.0f, 0.0f, 0.0f, 1.0f),
|
fRotation(0.0f, 0.0f, 0.0f, 1.0f),
|
||||||
spinX(2),
|
spinX(2),
|
||||||
spinY(2),
|
spinY(2),
|
||||||
solidity(0),
|
solidity(0),
|
||||||
color(4),
|
color(4),
|
||||||
changed(false),
|
changed(false),
|
||||||
fObjView(ov)
|
fObjView(ov)
|
||||||
{
|
{
|
||||||
@@ -136,7 +136,7 @@ GLObject::MenuInvoked(BPoint point)
|
|||||||
i = m->Go(point);
|
i = m->Go(point);
|
||||||
int32 index = m->IndexOf(i);
|
int32 index = m->IndexOf(i);
|
||||||
delete m;
|
delete m;
|
||||||
|
|
||||||
if (index < 5) {
|
if (index < 5) {
|
||||||
color = index+1;
|
color = index+1;
|
||||||
} else if (index > 5) {
|
} else if (index > 5) {
|
||||||
@@ -160,10 +160,10 @@ GLObject::SpinIt()
|
|||||||
{
|
{
|
||||||
bool c = changed;
|
bool c = changed;
|
||||||
c = c || ((spinX != 0.0f) || (spinY != 0.0f));
|
c = c || ((spinX != 0.0f) || (spinY != 0.0f));
|
||||||
|
|
||||||
if (c)
|
if (c)
|
||||||
RotateWorldSpace(spinY, spinX);
|
RotateWorldSpace(spinY, spinX);
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ void
|
|||||||
GLObject::Spin(float rx, float ry)
|
GLObject::Spin(float rx, float ry)
|
||||||
{
|
{
|
||||||
spinX = rx;
|
spinX = rx;
|
||||||
spinY = ry;
|
spinY = ry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -180,7 +180,8 @@ void
|
|||||||
GLObject::RotateWorldSpace(float rx, float ry)
|
GLObject::RotateWorldSpace(float rx, float ry)
|
||||||
{
|
{
|
||||||
fRotation = Quaternion(Vector3(0.0f, 1.0f, 0.0f), 0.01f * rx) * fRotation;
|
fRotation = Quaternion(Vector3(0.0f, 1.0f, 0.0f), 0.01f * rx) * fRotation;
|
||||||
fRotation = Quaternion(Vector3(1.0f, 0.0f, 0.0f), 0.01f * ry) * fRotation;
|
fRotation = Quaternion(Vector3(1.0f, 0.0f, 0.0f), 0.01f * ry) * fRotation;
|
||||||
|
fRotation.normalize();
|
||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,15 +191,15 @@ GLObject::Draw(bool forID, float IDcolor[])
|
|||||||
{
|
{
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(x, y, z);
|
glTranslatef(x, y, z);
|
||||||
|
|
||||||
float mat[4][4];
|
float mat[4][4];
|
||||||
fRotation.toOpenGLMatrix(mat);
|
fRotation.toOpenGLMatrix(mat);
|
||||||
glMultMatrixf((GLfloat*)mat);
|
glMultMatrixf((GLfloat*)mat);
|
||||||
|
|
||||||
if (forID) {
|
if (forID) {
|
||||||
glColor3fv(IDcolor);
|
glColor3fv(IDcolor);
|
||||||
}
|
}
|
||||||
|
|
||||||
DoDrawing(forID);
|
DoDrawing(forID);
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
@@ -208,7 +209,7 @@ GLObject::Draw(bool forID, float IDcolor[])
|
|||||||
|
|
||||||
|
|
||||||
TriangleObject::TriangleObject(ObjectView* ov)
|
TriangleObject::TriangleObject(ObjectView* ov)
|
||||||
:
|
:
|
||||||
GLObject(ov),
|
GLObject(ov),
|
||||||
fStatus(B_NO_INIT),
|
fStatus(B_NO_INIT),
|
||||||
fPoints(100, 100),
|
fPoints(100, 100),
|
||||||
|
|||||||
Reference in New Issue
Block a user