Esempio n. 1
0
//Mouse drag, calculate rotation
void    ArcBall_t::drag(const Point2fT* NewPt, Quat4fT* NewRot)
{
    //Map the point to the sphere
    this->_mapToSphere(NewPt, &this->EnVec);

    //Return the quaternion equivalent to the rotation
    if (NewRot)
    {
        Vector3fT  Perp;

        //Compute the vector perpendicular to the begin and end vectors
        Vector3fCross(&Perp, &this->StVec, &this->EnVec);

        //Compute the length of the perpendicular vector
        if (Vector3fLength(&Perp) > Epsilon)    //if its non-zero
        {
            //We're ok, so return the perpendicular vector as the transform after all
            NewRot->s.X = Perp.s.X;
            NewRot->s.Y = Perp.s.Y;
            NewRot->s.Z = Perp.s.Z;
            //In the quaternion values, w is cosine (theta / 2), where theta is rotation angle
            NewRot->s.W= Vector3fDot(&this->StVec, &this->EnVec);
        }
        else                                    //if its zero
        {
            //The begin and end vectors coincide, so return an identity transform
            NewRot->s.X = 
            NewRot->s.Y = 
            NewRot->s.Z = 
            NewRot->s.W = 0.0f;
        }
    }
}
Esempio n. 2
0
//Mouse drag, calculate rotation
inline void ArcBallDrag(ArcBall_t *a, double x, double y, Quat4fT* NewRot) {
    //Map the point to the sphere
    ArcBallMapToSphere(a, x, y, &(a->EnVec));

    //Return the quaternion equivalent to the rotation
    if (NewRot) {
        Vector3fT  Perp;

        //Compute the vector perpendicular to the begin and end vectors
        Vector3fCross(&Perp, &(a->StVec), &(a->EnVec));

        //Compute the length of the perpendicular vector
        if (Vector3fLength(&Perp) > ArcBallEpsilon) {    //if its non-zero
            //We're ok, so return the perpendicular vector as the transform after all
            NewRot->s.X = Perp.s.X;
            NewRot->s.Y = Perp.s.Y;
            NewRot->s.Z = Perp.s.Z;
            //In the quaternion values, w is cosine (theta / 2), where theta is rotation angle
            NewRot->s.W= Vector3fDot(&(a->StVec), &(a->EnVec));
        } else {                                    //if its zero
            //The begin and end vectors coincide, so return an identity transform
            NewRot->s.X = 0.0f;
            NewRot->s.Y = 0.0f;
            NewRot->s.Z = 0.0f;
            NewRot->s.W = 0.0f;
        }
    }
}
Esempio n. 3
0
void Vector3fNormalize(struct Vector3f * Vector)
{
	if (Vector)
	{
		float Length = Vector3fLength(Vector);
		Vector3fDivide(Vector, Length);
	}
}
Esempio n. 4
0
void Objects::timber4(float width, float fromX, float fromY, float toX, float toY) {
	float ir=width/(float)2;
	Tuple3fT a; a.s.X=fromX-toX; a.s.Y=fromY-toY; a.s.Z=0;
	Tuple3fT b; b.s.X=0; b.s.Y=0; b.s.Z=-1;
	Tuple3fT normal, dir;
	Vector3fCross(&normal, &a, &b);
	GLfloat l=Vector3fLength(&normal);
	normal.s.X=normal.s.X/l; normal.s.Y=normal.s.Y/l; normal.s.Z=normal.s.Z/l;
	dir.s.X=normal.s.X*ir; dir.s.Y=normal.s.Y*ir; dir.s.Z=normal.s.Z*ir;
	l=Vector3fLength(&a);
	a.s.X=a.s.X/l; a.s.Y=a.s.Y/l; a.s.Z=a.s.Z/l;

	glBegin(GL_TRIANGLES);
		// If it's too slow, leave these 4 triangles away
		// 4 triangles to model the two caps
		glNormal3f(a.s.X,a.s.Y,a.s.Z);
		glVertex3f(fromX+dir.s.X,fromY+dir.s.Y,-ir);
		glNormal3f(a.s.X,a.s.Y,a.s.Z);
		glVertex3f(fromX+dir.s.X,fromY+dir.s.Y,ir);
		glNormal3f(a.s.X,a.s.Y,a.s.Z);
		glVertex3f(fromX-dir.s.X,fromY-dir.s.Y,ir);

		glNormal3f(a.s.X,a.s.Y,a.s.Z);
		glVertex3f(fromX+dir.s.X,fromY+dir.s.Y,-ir);
		glNormal3f(a.s.X,a.s.Y,a.s.Z);
		glVertex3f(fromX-dir.s.X,fromY-dir.s.Y,-ir);
		glNormal3f(a.s.X,a.s.Y,a.s.Z);
		glVertex3f(fromX-dir.s.X,fromY-dir.s.Y,ir);

		glNormal3f(-a.s.X,-a.s.Y,-a.s.Z);
		glVertex3f(toX+dir.s.X,toY+dir.s.Y,-ir);
		glNormal3f(-a.s.X,-a.s.Y,-a.s.Z);
		glVertex3f(toX+dir.s.X,toY+dir.s.Y,ir);
		glNormal3f(-a.s.X,-a.s.Y,-a.s.Z);
		glVertex3f(toX-dir.s.X,toY-dir.s.Y,ir);

		glNormal3f(-a.s.X,-a.s.Y,-a.s.Z);
		glVertex3f(toX-dir.s.X,toY-dir.s.Y,ir);
		glNormal3f(-a.s.X,-a.s.Y,-a.s.Z);
		glVertex3f(toX-dir.s.X,toY-dir.s.Y,-ir);
		glNormal3f(-a.s.X,-a.s.Y,-a.s.Z);
		glVertex3f(toX+dir.s.X,toY+dir.s.Y,-ir);

		// 4 triangles for 2 sides
		glNormal3f(0,0,1);
		glVertex3f(fromX+dir.s.X,fromY+dir.s.Y,ir);
		glNormal3f(0,0,1);
		glVertex3f(fromX-dir.s.X,fromY-dir.s.Y,ir);
		glNormal3f(0,0,1);
		glVertex3f(toX+dir.s.X,toY+dir.s.Y,ir);

		glNormal3f(0,0,1);
		glVertex3f(fromX-dir.s.X,fromY-dir.s.Y,ir);
		glNormal3f(0,0,1);
		glVertex3f(toX+dir.s.X,toY+dir.s.Y,ir);
		glNormal3f(0,0,1);
		glVertex3f(toX-dir.s.X,toY-dir.s.Y,ir);

		glNormal3f(0,0,-1);
		glVertex3f(fromX+dir.s.X,fromY+dir.s.Y,-ir);
		glNormal3f(0,0,-1);
		glVertex3f(fromX-dir.s.X,fromY-dir.s.Y,-ir);
		glNormal3f(0,0,-1);
		glVertex3f(toX+dir.s.X,toY+dir.s.Y,-ir);

		glNormal3f(0,0,-1);
		glVertex3f(fromX-dir.s.X,fromY-dir.s.Y,-ir);
		glNormal3f(0,0,-1);
		glVertex3f(toX+dir.s.X,toY+dir.s.Y,-ir);
		glNormal3f(0,0,-1);
		glVertex3f(toX-dir.s.X,toY-dir.s.Y,-ir);

		// Schiefe Ebene
		glNormal3f(-normal.s.X,-normal.s.Y,-normal.s.Z);
		glVertex3f(fromX-dir.s.X,fromY-dir.s.Y,-ir);
		glNormal3f(-normal.s.X,-normal.s.Y,-normal.s.Z);
		glVertex3f(fromX-dir.s.X,fromY-dir.s.Y,ir);
		glNormal3f(-normal.s.X,-normal.s.Y,-normal.s.Z);
		glVertex3f(toX-dir.s.X,toY-dir.s.Y,ir);

		glNormal3f(-normal.s.X,-normal.s.Y,-normal.s.Z);
		glVertex3f(fromX-dir.s.X,fromY-dir.s.Y,-ir);
		glNormal3f(-normal.s.X,-normal.s.Y,-normal.s.Z);
		glVertex3f(toX-dir.s.X,toY-dir.s.Y,ir);
		glNormal3f(-normal.s.X,-normal.s.Y,-normal.s.Z);
		glVertex3f(toX-dir.s.X,toY-dir.s.Y,-ir);

		glNormal3f(normal.s.X,normal.s.Y,normal.s.Z);
		glVertex3f(fromX+dir.s.X,fromY+dir.s.Y,-ir);
		glNormal3f(normal.s.X,normal.s.Y,normal.s.Z);
		glVertex3f(fromX+dir.s.X,fromY+dir.s.Y,ir);
		glNormal3f(normal.s.X,normal.s.Y,normal.s.Z);
		glVertex3f(toX+dir.s.X,toY+dir.s.Y,ir);

		glNormal3f(normal.s.X,normal.s.Y,normal.s.Z);
		glVertex3f(fromX+dir.s.X,fromY+dir.s.Y,-ir);
		glNormal3f(normal.s.X,normal.s.Y,normal.s.Z);
		glVertex3f(toX+dir.s.X,toY+dir.s.Y,ir);
		glNormal3f(normal.s.X,normal.s.Y,normal.s.Z);
		glVertex3f(toX+dir.s.X,toY+dir.s.Y,-ir);
	glEnd();
}