Example #1
0
void Window::processMouseActiveMotion(int x, int y)
{
    Vector3 currPoint;
    Vector3 direction;
    float rotAngle;
    
    switch (Movement) {
        case GLUT_LEFT_BUTTON: {   // rotation
            //std::cout << "GLU LEFT BUTTON" << std::endl;
            currPoint = trackBallMapping(x, y); //map mouse to logical sphere location
            currPoint = currPoint.normalize();
            lastPoint = lastPoint.normalize();
            direction = currPoint - lastPoint;
            float velocity = direction.magnitude();
            if (velocity > 0.0001) {
                Vector3 rotAxis;
                rotAxis = lastPoint.cross(currPoint);
                rotAxis = rotAxis.normalize();
//                rotAngle = lastPoint.angle(currPoint);
                rotAngle = velocity * 0.025;
                Matrix4 lol;
                lol.makeRotateArbitrary(rotAxis, rotAngle);
                if (source == 0) {
                    Globals::objdraw->toWorld = lol.multiply(Globals::objdraw->toWorld);
                    //displayPosition();
                } 
            }
            break;
        }
        case GLUT_RIGHT_BUTTON: {   // x/y translation
            //std::cout << "GLU RIGHT BUTTON" << std::endl;
            currPoint = Vector3(x, y, 0);
            direction.set((currPoint[0] - lastPoint[0]) *  0.001,
                          (currPoint[1] - lastPoint[1]) * -0.001, 0);
            
            Matrix4 lol;
            lol.makeTranslate(direction);
            if (source == 0) {
                Globals::objdraw->toWorld = lol.multiply(Globals::objdraw->toWorld);
               // displayPosition();
            }
            
            break;
        }
        case 3:    { // mouse wheel -- scale
            // std::cout << "MOUSE WHEEL" << std::endl;
            currPoint = Vector3(x, y, 0);
            direction.set(0, 0, (currPoint[1] - lastPoint[1]) * -0.001);
            Matrix4 lol;
            lol.makeTranslate(direction);
            if (source == 0) {
                Globals::objdraw->toWorld = lol.multiply(Globals::objdraw->toWorld);
                // displayPosition();
            }

            break;
        }
            
    }
}
Example #2
0
void Camera :: rotate(Vector3* axis, float angle)
{
	float cs = cos(3.14159265/180 * angle);
	float sn = sin(3.14159265/180 * angle);

	Vector3* t;
	Vector3* s;
	if(axis == v) {
		t = u;
		s = n;
	}
	else if(axis == u) {
		t = n;
		s = v;
	}
	else if(axis == n) {
		t = u;
		s = v;
	}

	Vector3* temp = new Vector3(t);

	t->set(cs*t->x + sn*s->x, cs*t->y + sn*s->y, cs*t->z + sn*s->z);
	s->set(cs*s->x - sn*temp->x, cs*s->y - sn*temp->y, cs*s->z - sn*temp->z);
	setModelViewMatrix();
}
Example #3
0
	void mouse (EditorViewWindow *view, int msg, Point move)
	{
		if ((fltk::event_state () & fltk::ALT) && !(fltk::event_state() & fltk::CTRL))
		{
			CameraTool.mouse (view, msg, move);
			return;
		}

		if ((msg == fltk::DRAG || msg == fltk::MOVE) && (fltk::event_state () & fltk::BUTTON1))
		{
			Vector3 rot;
			float r = AngleMod * move.x / 180.0f * M_PI;
			switch (view->GetMode())
			{
			case MAP_3D:
				return;
			case MAP_XY:
				rot.set(0, 0, -r);
				break;
			case MAP_XZ:
				rot.set(0, -r, 0);
				break;
			case MAP_YZ:
				rot.set(-r, 0, 0);
				break;
			}
			
			BACKUP_MERGEABLE_OP("Object(s) rotated", OT_Rotate, ApplyRotateOp, &rot);
			editor->RedrawViews();
		}
		else if(fltk::event_state() & fltk::BUTTON2)
			view->cam.MouseEvent(view, msg, move);
	}
void
Camera::calcApertureAxes() //this function need to be call if change the camera property
{
	// we need a point in the plane OTHER than the eye point. choose a x,y and solve z!
	Vector3 point;
	if (m_viewDir.z != 0){
		point.set(m_eye.x + 1, m_eye.y + 1, 0);
		// m_viewDir is normal to the aperture plane
		point.z = m_eye.z - (m_viewDir.x * (point.x - m_eye.x) - m_viewDir.y * (point.y - m_eye.y)) / m_viewDir.z;
	}
	else if (m_viewDir.y !=0){
		point.set(m_eye.x + 1, 0, m_eye.z + 1);
		// m_viewDir is normal to the aperture plane
		point.y = m_eye.y - (m_viewDir.x * (point.x - m_eye.x) - m_viewDir.z * (point.z - m_eye.z)) / m_viewDir.y;
	}
	else {
		point.set(0, m_eye.y+1, m_eye.z + 1);
		// m_viewDir is normal to the aperture plane
		point.x = m_eye.x - (m_viewDir.y * (point.y - m_eye.y) - m_viewDir.y * (point.y - m_eye.y)) / m_viewDir.x;
	}

	// now we can get our first axis
	m_aperture_plane_axis_x = point - m_eye;
	m_aperture_plane_axis_x.normalize();

	// make the second axis orthonormal to the first
	m_aperture_plane_axis_y = cross(m_viewDir, m_aperture_plane_axis_x);
	m_aperture_plane_axis_y.normalize();

	// now make the length of each axis the radius of the aperture
	m_aperture_plane_axis_x *= m_aperture;
	m_aperture_plane_axis_y *= m_aperture;
}
Example #5
0
// static/instance method to calculate barycoordinates
// based on: http://www.blackpawn.com/texts/pointinpoly/default.html
Vector3 Triangle::barycoordFromPoint( const Vector3& point,
        const Vector3& a, const Vector3& b, const Vector3& c )
{

    Vector3 v0, v1, v2;

    v0.subVectors( c, a );
    v1.subVectors( b, a );
    v2.subVectors( point, a );

    float dot00 = v0.dot( v0 );
    float dot01 = v0.dot( v1 );
    float dot02 = v0.dot( v2 );
    float dot11 = v1.dot( v1 );
    float dot12 = v1.dot( v2 );

    float denom = ( dot00 * dot11 - dot01 * dot01 );

    Vector3 result;

    // colinear or singular triangle
    if( denom == 0 ) {
        // arbitrary location outside of triangle?
        // not sure if this is the best idea, maybe should be returning undefined
        return result.set( -2.0f, -1.0f, -1.0f );
    }

    float invDenom = 1.0f / denom;
    float u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
    float v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;

    // barycoordinates must always sum to 1
    return result.set( 1.0f - u - v, v, u );

}
bool CollisionManager::checkLineOfSightInParentCell(SceneObject* object, Vector3& endPoint) {
	ManagedReference<SceneObject*> parent = object->getParent();

	if (parent == NULL || !parent->isCellObject())
		return true;

	CellObject* cell = cast<CellObject*>( parent.get());

	SharedObjectTemplate* objectTemplate = parent->getRootParent().get()->getObjectTemplate();
	PortalLayout* portalLayout = objectTemplate->getPortalLayout();
	MeshAppearanceTemplate* appearanceMesh = NULL;

	if (portalLayout == NULL)
		return true;

	try {
		appearanceMesh = portalLayout->getMeshAppearanceTemplate(cell->getCellNumber());
	} catch (Exception& e) {
		return true;
	}

	if (appearanceMesh == NULL) {
		//info("null appearance mesh ");
		return true;
	}

	AABBTree* aabbTree = appearanceMesh->getAABBTree();

	if (aabbTree == NULL)
		return true;

	//switching Y<->Z, adding 0.1 to account floor
	Vector3 startPoint = object->getPosition();
	startPoint.set(startPoint.getX(), startPoint.getY(), startPoint.getZ() + 0.1f);

	endPoint.set(endPoint.getX(), endPoint.getY(), endPoint.getZ() + 0.1f);

	Vector3 dir = endPoint - startPoint;
	dir.normalize();

	float distance = endPoint.distanceTo(startPoint);
	float intersectionDistance;

	Ray ray(startPoint, dir);

	Triangle* triangle = NULL;

	//nothing in the middle
	if (aabbTree->intersects(ray, distance, intersectionDistance, triangle, true))
		return false;

	Ray ray2(endPoint, Vector3(0, -1, 0));

	//check if we are in the cell with dir (0, -1, 0)
	if (!aabbTree->intersects(ray2, 64000.f, intersectionDistance, triangle, true))
		return false;

	return true;
}
//<<<<<<<<<<<<<<<<<<<<<<<< rotAxes >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
void Camera:: rotAxes(Vector3& a, Vector3& b, float angle) 
{ // rotate orthogonal vectors a (like x axis) and b(like y axia) through angle degrees 
    float ang = 3.14159265/180*angle; 
    float C = cos(ang), S = sin(ang); 
    Vector3 t(C * a.x + S * b.x, C * a.y + S * b.y, C * a.z + S * b.z); b.set(-S * a.x + C * b.x, -S * a.y + C * b.y, 
    -S * a.z + C * b.z); 
    a.set(t.x, t.y, t.z); // put tmp into a' 
} 
Example #8
0
void TriMesh::GetAABB(Vector3& bmin, Vector3& bmax) const
{
  bmin.set(Inf);
  bmax.set(-Inf);
  for(size_t i=0;i<verts.size();i++) {
    bmin.setMinimum(verts[i]);
    bmax.setMaximum(verts[i]);
  } 
}
Example #9
0
void Window::funcMouseCallback(int button, int state, int x, int y) {
	double tempX = (2.0*x - Window::width) / Window::width;
	double tempY = (Window::height - 2.0*y) / Window::height;
	mouse.set(tempX, tempY, 0);
	double d = mouse.length();
	d = (d < 1.0) ? d : 1.0;
	mouse.set(tempX, tempY, sqrtf(1.001 - d*d));
	mouse.normalize();
}
Example #10
0
void processMotion(int x, int y)
{
	xf = (float)x/((float)window::width/2.0) - 1;
	yf = 1 - (float)y/((float)window::height/2.0);
	if (pressedLeft)
	{
		zf = findZ(xf,yf);
		Vector3 prev = Vector3(prevX,prevY,prevZ);
		Vector3 curr = Vector3(xf,yf,zf);
		
		Vector3 p = prev.normalize();
		Vector3 c = curr.normalize();
		prev.set(p.get(0), p.get(1), p.get(2));
		curr.set(c.get(0), c.get(1), c.get(2));

		theta = getTheta(prev, curr);
		Vector3 axis3 = prev.cross(prev, curr);
		Vector3 a = axis3.normalize();
		axis3.set(a.get(0), a.get(1), a.get(2));

		Vector4 axis4 = Vector4(axis3.get(0), axis3.get(1), axis3.get(2), 0);

		temp.getMatrix().setMatrix(temp.getMatrix().rotateAA(axis4,theta));
	}
	else if (pressedMiddle)
	{
		temp.getMatrix().identity();
		temp.getMatrix().setMatrix(temp.getMatrix().translate((xf-prevX)*15,(yf-prevY)*15,0));
	}
	else if (pressedRight)
	{
		float s;
		if (prevY < yf)
		{
			s = 1-(yf-prevY)*-2;
			temp.getMatrix().identity();
			temp.getMatrix().setMatrix(temp.getMatrix().scale(s,s,s));
		}
		else
		{
			float s = 1+(yf-prevY)*0.5;
			if (s < 0)
			{
				s = 0.0001;
			}
			temp.getMatrix().identity();
			temp.getMatrix().setMatrix(temp.getMatrix().scale(s,s,s));
		}
	}
}
Example #11
0
    void SpriteBatcher3D::pushSprite(const Vector3 position, const Vector3 &normal, const Vector2 &size, const TextureRegion *region)
  {
    //画像の上方向を表すベクトル(これがそのまま上方向になる訳ではない)
    Vector3 up;
    //通常はy軸が画像の上, 画像が上か下を向いている時はz軸が画像の上
    if( normal.x == 0 && normal.z == 0)
      up.set(0,0,1);
    else
      up.set(0,1,0);  

    //X軸
    Vector3 axis1 = up.cross(normal);
    axis1.normalize();

    //Y軸
    Vector3 axis2 = normal.cross(axis1);
    axis2.normalize();

    axis1 *= size.x/2;
    axis2 *= size.y/2;
    const Vector3 leftBottom  = position - axis1 - axis2;
    const Vector3 rightBottom = position + axis1 - axis2;
    const Vector3 rightTop    = position + axis1 + axis2;
    const Vector3 leftTop     = position - axis1 + axis2;

    verticesBuffer[bufferIndex++] = leftBottom.x;
    verticesBuffer[bufferIndex++] = leftBottom.y;
    verticesBuffer[bufferIndex++] = leftBottom.z;
    verticesBuffer[bufferIndex++] = region->u1;
    verticesBuffer[bufferIndex++] = region->v2;

    verticesBuffer[bufferIndex++] = rightBottom.x;
    verticesBuffer[bufferIndex++] = rightBottom.y;
    verticesBuffer[bufferIndex++] = rightBottom.z;
    verticesBuffer[bufferIndex++] = region->u2;
    verticesBuffer[bufferIndex++] = region->v2;

    verticesBuffer[bufferIndex++] = rightTop.x;
    verticesBuffer[bufferIndex++] = rightTop.y;
    verticesBuffer[bufferIndex++] = rightTop.z;
    verticesBuffer[bufferIndex++] = region->u2;
    verticesBuffer[bufferIndex++] = region->v1;

    verticesBuffer[bufferIndex++] = leftTop.x;
    verticesBuffer[bufferIndex++] = leftTop.y;
    verticesBuffer[bufferIndex++] = leftTop.z;  
    verticesBuffer[bufferIndex++] = region->u1;
    verticesBuffer[bufferIndex++] = region->v1;
    numSprite++;  
  }
Example #12
0
void findCenter ()
{
  int count = 0;
  center.set( 0,0,0 );
  boundsMin.set( 0,0,0 );
  boundsMax.set( 0,0,0 );

  SkinTriMesh *mesh = character->mesh;
  for (UintSize v=0; v<mesh->data.size(); ++v) {
    center += mesh->getVertex( v )->point;
    count++;
  }
  
  center /= (Float)count;
}
Example #13
0
void EquilibriumTester::GetValidCOM(Vector3& com) const
{
  Assert(testingAnyCOM);
  int base = lp.A.n - 3;
  com.set(lps.xopt(base),lps.xopt(base+1),lps.xopt(base+2));
  com += conditioningShift;
}
Example #14
0
Vector3<T> Vector3<T>::cross(const Vector3<T> &v) const {
    Vector3<T> res;
    res.set(y * v.z - z * v.y,
            z * v.x - x * v.z,
            x * v.y - y * v.x);
    return res;
}
Example #15
0
void URDFConverter::processTParentTransformations(vector<URDFLinkNode>& linkNodes){
	for(int i = 0; i < linkNodes.size(); i++){
	  linkNodes[i].GetGeometryProperty(useVisGeom);
		RigidTransform T0, T1, T2;
		T0.setIdentity();
		Vector3 tmpaxis;
		if(linkNodes[i].joint){
			urdf::Pose pose = linkNodes[i].joint->parent_to_joint_origin_transform;
			T0.t.set(pose.position.x, pose.position.y, pose.position.z);
			Vector4 quat(pose.rotation.x, pose.rotation.y, pose.rotation.z, pose.rotation.w);
			QuatToRotationMat(quat, T0.R);

			tmpaxis.set( linkNodes[i].joint->axis.x, linkNodes[i].joint->axis.y, linkNodes[i].joint->axis.z);
			if(tmpaxis.norm() > 0){
				linkNodes[i].axis.set( linkNodes[i].joint->axis.x, linkNodes[i].joint->axis.y, linkNodes[i].joint->axis.z);
			}

		}
		linkNodes[i].T_parent.set(T0);

		RigidTransform G0, G1;
		G1.setIdentity();
		if(useVisGeom) {
		  G0.mul(linkNodes[i].T_link_to_inertia_inverse, linkNodes[i].T_link_to_visgeom);
		  G1.mul(linkNodes[i].T_link_to_visgeom, linkNodes[i].geomScale);
		}
		else {
		  G0.mul(linkNodes[i].T_link_to_inertia_inverse, linkNodes[i].T_link_to_colgeom);
		  G1.mul(linkNodes[i].T_link_to_colgeom, linkNodes[i].geomScale);
		}
		linkNodes[i].geomScale.set(G1);
	}
}
Vector3 SpawnAreaImplementation::getRandomPosition(SceneObject* player) {
	Vector3 position;
	bool positionFound = false;
	int retries = 10;

	while (!positionFound && retries-- > 0) {
		position = areaShape->getRandomPosition(player->getWorldPosition(), 64.0f, 256.0f);

		positionFound = true;

		for (int i = 0; i < noSpawnAreas.size(); ++i) {
			SpawnArea* noSpawnArea = noSpawnAreas.get(i);

			if (noSpawnArea->containsPoint(position.getX(), position.getY())) {
				positionFound = false;
				break;
			}
		}
	}

	if (!positionFound) {
		position.set(0, 0, 0);
	}

	return position;
}
void Emitter::PSOInit(double x, double y, double z)
{
	for (int i=0; i <= MAXPARTICLES; i++)
	{
		particle[i].xpos = x + (rand()%10)/1.0;
		particle[i].ypos = y + (rand()%10)/1.0;
		particle[i].zpos = z + (rand()%10)/1.0;

		particle[i].xspeed = 0;
		particle[i].yspeed = 0;
		particle[i].zspeed = 0;

		Vector3 distance;
		distance.set(x - particle[i].xpos,
					 y - particle[i].ypos,
					 z - particle[i].zpos);

		particle[i].pBest = distance.magnitude();

		if (particle[i].pBest < globalBest)
		{
			globalBest = particle[i].pBest;
		}
	}
}
//initialise the display settings
void myInit()
{
    createMesh();
    generateWinterMesh();
    generateFallMesh();
    generateSummerMesh();
    generateSpringMesh();
	produceTrees_spring();
	produceTrees_summer();
	produceTrees_autumn();
	produceTrees_winter();
  generateCloud();
	drawTrees();
    GLfloat lightIntensity[] = { 0.8, 0.8, 0.8, 1.0f};
	GLfloat lightIntensity2[] = { 0.8, 0.8, 0.8, 1.0f };
    GLfloat lightPosition[] = {0.0f, 1.0f, 0.0f, 0.0f};
	GLfloat lightPosition2[] = { 0.0f, -1.0f, 0.0f, 0.0f };
    glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
    glLightfv(GL_LIGHT0, GL_AMBIENT, lightIntensity);
	glLightfv(GL_LIGHT1, GL_POSITION, lightPosition2);
	glLightfv(GL_LIGHT1, GL_AMBIENT, lightIntensity2);
    Point3 eye, look;
    Vector3 up;
    eye.set(1,1,1); //set the eye location
    look.set(0,0,0); //set the look at coord
    up.set(0,1,0); //specify the up vector
    cam.set(eye, look, up); // make the initial camera
    cam.slide(0,0, 1.5);
    cam.setShape(30.0f, 1.0f, 0.5f, 50.0f);
}
// Keyboard for handling keyboard key down presses
void myKeyboard(unsigned char key, int x, int y)
{/*
        if(key == 's') {
            cam.slide(0,0, 0.1);
        } else if(key == 'w') {
            cam.slide(0,0, -0.1);
        } */
        if(key == 'w') {
            lookUp = true;
        } else if(key == 's') {
            lookDown = true;
        } else if(key == 'a') {
            lookLeft = true;
        } else if(key == 'd') {
            lookRight = true;
        }

        if(key == 'q') {
            rollLeft = true;
        } else if(key == 'e') {
            rollRight = true;
        }

        if(key == 'h') {
            Point3 eye, look;
            Vector3 up;
            eye.set(1,1,1); //set the eye location
            look.set(0,0,0); //set the look at coord
            up.set(0,1,0); //specify the up vector
            cam.set(eye, look, up); // make the initial camera
            cam.slide(0,0, 1.5);
            cam.setShape(30.0f, 1.0f, 0.5f, 50.0f);
        }
    glutPostRedisplay(); // draw it again
}
Example #20
0
Vector3 PhysicsConstraint::getWorldCenterOfMass(const Model* model)
{
    Vector3 center;

    const BoundingBox& box = model->getMesh()->getBoundingBox();
    if (!(box.min.isZero() && box.max.isZero()))
    {
        Vector3 bMin, bMax;
        model->getNode()->getWorldMatrix().transformPoint(box.min, &bMin);
        model->getNode()->getWorldMatrix().transformPoint(box.max, &bMax);
        center.set(bMin, bMax);
        center.scale(0.5f);
        center.add(bMin);
    }
    else
    {
        const BoundingSphere& sphere = model->getMesh()->getBoundingSphere();
        if (!(sphere.center.isZero() && sphere.radius == 0))
        {
            model->getNode()->getWorldMatrix().transformPoint(sphere.center, &center);
        }
        else
        {
            // Warn the user that the model has no bounding volume.
            WARN_VARG("Model \'%s\' has no bounding volume - center of mass is defaulting to local coordinate origin.", model->getNode()->getId());
            model->getNode()->getWorldMatrix().transformPoint(&center);
        }
    }

    return center;
}
Example #21
0
void GetFreeTransform(const RigidTransform& xform, Vector3& pos, Vector3& rot)
{
  EulerAngleRotation r;
  r.setMatrixZXY(xform.R);
  rot.set(r.z,r.y,r.x);
  pos = xform.t;
}
Example #22
0
File: Matrix.cpp Project: cn00/MJ
void Matrix::getCol(int idx, Vector3& col) const
{
    if (idx > 4)
        return;
    idx *= 4;
    col.set(m[idx], m[idx+1], m[idx+2]);
}
Vector3 PathFinderManager::transformToModelSpace(const Vector3& point, SceneObject* building) {
	// we need to move world position into model space
	Vector3 switched(point.getX(), point.getZ(), point.getY());
	Matrix4 translationMatrix;
	translationMatrix.setTranslation(-building->getPositionX(), -building->getPositionZ(), -building->getPositionY());

	float rad = -building->getDirection()->getRadians();
	float cosRad = cos(rad);
	float sinRad = sin(rad);

	Matrix3 rot;
	rot[0][0] = cosRad;
	rot[0][2] = -sinRad;
	rot[1][1] = 1;
	rot[2][0] = sinRad;
	rot[2][2] = cosRad;

	Matrix4 rotateMatrix;
	rotateMatrix.setRotationMatrix(rot);

	Matrix4 modelMatrix;
	modelMatrix = translationMatrix * rotateMatrix;

	Vector3 transformedPosition = switched * modelMatrix;

	transformedPosition.set(transformedPosition.getX(), transformedPosition.getY(), transformedPosition.getZ());

	return transformedPosition;
}
Example #24
0
bool OrXmlTransformation::ComputeTransform(){
	if(T)
		return true;
	Vector3 t;
	t.setZero();
	for(int i = 0; i < this->translation.size(); i++){
		t.set(t + *translation[i]);
	}
	Matrix3 R;
	R.setIdentity();
	assert(rotationorder.size() == rotationindex.size());
	int nRotation = rotationorder.size();
	for(int i = 0; i < nRotation; i++){
		int index = rotationindex[i];
		if(rotationorder[i] == 1){
			R.set((*rotationmat[ index ]) * R);
		}else if(rotationorder[i] == 2){
			Matrix3 tmp;
			tmp.setIdentity();
			axisAngle2RotationMat(*rotationaxis[ index ], tmp);
			R.set(tmp * R);
		}else if(rotationorder[i] == 3){
			Matrix3 tmp;
			tmp.setIdentity();
			quat2RotationMat(*quat[ index ], tmp);
			R.set(tmp * R);
		}
	}

	this->T = new RigidTransform(R,t);
	return false;
}
Example #25
0
void Transform::look_at(const Vector3 & eye, const Vector3 & center,
                        const Vector3 & up, Matrix4 * m)
{
	Vector3 forward;
	forward.set(center);
	forward.sub(eye);
	forward.normalize();

	Vector3 side;
	side.cross(forward, up);
	side.normalize();

	Vector3 upvec;
	upvec.cross(side, forward);

	Matrix4 xform;
	xform.identity();
	xform.set_row(0, side);
	xform.set_row(1, upvec);

	forward.negate();
	xform.set_row(2, forward);

	m->mul(xform);

	Vector3 neg_eye;
	neg_eye.set(eye);
	neg_eye.negate();

	Matrix4 xlate;
	xlate.translate(neg_eye);
	m->mul(xlate);
}
bool CollisionManager::checkMovementCollision(CreatureObject* creature, float x, float z, float y, Zone* zone) {
	SortedVector<ManagedReference<QuadTreeEntry*> > closeObjects;
	zone->getInRangeObjects(x, y, 128, &closeObjects, true);

	//Vector3 rayStart(x, z + 0.25, y);
	//Vector3 rayStart(creature->getWorldPositionX(), creature->getWorldPositionZ(), creature->getPos)
	Vector3 rayStart = creature->getWorldPosition();
	rayStart.set(rayStart.getX(), rayStart.getY(), rayStart.getZ() + 0.25f);
	//Vector3 rayEnd(x + System::random(512), z + 0.3f, y + System::random(512));

	/*Vector3 rayEnd;
	rayEnd.set(targetPosition.getX(), targetPosition.getY(), targetPosition.getZ());*/

	Vector3 rayEnd(x, z + 0.25, y);

	float maxDistance = rayEnd.distanceTo(rayStart);

	if (maxDistance == 0)
		return false;

	printf("%f\n", maxDistance);

	SortedVector<IntersectionResult> results;
	results.setAllowDuplicateInsertPlan();

	printf("starting test\n");

	Triangle* triangle;

	for (int i = 0; i < closeObjects.size(); ++i) {
		SceneObject* object = dynamic_cast<SceneObject*>(closeObjects.get(i).get());

		if (object == NULL)
			continue;

		AABBTree* tree = getAABBTree(object, 255);

		if (tree == NULL)
			continue;

		Ray ray = convertToModelSpace(rayStart, rayEnd, object);

		//results.removeAll(10, 10);

		//ordered by intersection distance
		//tree->intersects(ray, maxDistance, results);

		float intersectionDistance;

		if (tree->intersects(ray, maxDistance, intersectionDistance, triangle, true)) {
			String str = object->getObjectTemplate()->getFullTemplateString();

			object->info("intersecting with me " + str, true);
			return true;
		}
	}

	return false;
}
Example #27
0
void Cube::rotationCounter(){
	Matrix4 rotation;
	Vector3 zaxis;
	zaxis.set(0, 0, 1);
	rotation = rotation.makeRotateArbitrary(zaxis, 0.1);
	toWorld =  rotation * toWorld;
	position = rotation * position;
}
Example #28
0
Vector3 Drawable::getLoc() {
	Vector3 r;
	float x = toWorld.get(3, 0);
	float y = toWorld.get(3, 1);
	float z = toWorld.get(3, 2);
	r.set(x, y, z);
	return r;
}
Vector3 CircularAreaShapeImplementation::getRandomPosition() {
	float distance = System::random((int)radius);
	float angle = System::random(360) * Math::DEG2RAD;

	Vector3 position;
	position.set(areaCenter.getX() + distance * Math::cos(angle), 0, areaCenter.getY() + distance * Math::sin(angle));

	return position;
}
Example #30
0
File: Matrix.cpp Project: cn00/MJ
Vector3 Matrix::getCol(int idx) const
{
    if (idx > 4)
        return Vector3::zero();
    static Vector3 col;
    idx *= 4;
    col.set(m[idx], m[idx+1], m[idx+2]);
    return col;
}