Esempio n. 1
0
bool CollisionVolume::testCollision(const VC3 &objectPosition, const VC3 &angles, CollisionData &collisionData, float epsilon)
{
	QUAT rotation = getRotation(angles);
	//rotation.MakeFromAngles(0, -yRotation, 0);
	
	Matrix tm;
	tm.CreateRotationMatrix(rotation);

	// Everything's relative etc
	VC3 rayOrigin = tm.GetTransformedVector(collisionData.rayOrigin - objectPosition) + objectPosition;
	VC3 rayDirection = tm.GetWithoutTranslation().GetTransformedVector(collisionData.rayDirection);

	if(!data->possibleCollision(objectPosition, collisionData))
		return false;
	if(!data->accurateCollision(objectPosition, collisionData, rayOrigin, rayDirection))
		return false;

	float collisionDistance = objectPosition.GetRangeTo(collisionData.rayOrigin);
	VC3 pos = tm.GetInverse().GetTransformedVector(collisionData.collisionPosition - objectPosition) + objectPosition;

	if(collisionData.hasCollision)
	if(collisionDistance > pos.GetRangeTo(collisionData.rayOrigin))
		return false;

	collisionData.rayLength = collisionDistance;
	collisionData.hasCollision = true;
	collisionData.collisionPosition = objectPosition;
	collisionData.objectData = data->data;

	return true;
}
void PointArrayParticleSystem::init(IStorm3D* s3d, IStorm3D_Scene* scene)
{
    defaultInit(s3d, scene, *m_eds);

    std::string fileName = m_eds->modelFile;
    if(fileName.empty())
        return;

    Matrix sm;
    Matrix rm;
    QUAT q;
    q.MakeFromAngles(m_eds->rotation.x, m_eds->rotation.y, m_eds->rotation.z);
    rm.CreateRotationMatrix(q);
    sm.CreateScaleMatrix(m_eds->scale);
    sm.Multiply(rm);
    IStorm3D_Model* model = s3d->CreateNewModel();
    assert(model != NULL);

    if(model->LoadS3D(fileName.c_str()))
    {
        Iterator<IStorm3D_Model_Object*>* obj = model->ITObject->Begin();
        assert(obj != NULL);

        boost::shared_ptr<PointArray> pm(new PointArray());
        for(; !obj->IsEnd(); obj->Next())
        {
            IStorm3D_Mesh* mesh = obj->GetCurrent()->GetMesh();
            VC3 opos = obj->GetCurrent()->GetPosition();

            if(mesh)
            {
                int base = pm->verts.size();
                pm->verts.resize(base + mesh->GetVertexCount());
                pm->normals.resize(base + mesh->GetVertexCount());

                Storm3D_Vertex *v = mesh->GetVertexBuffer();
                for(int i = 0; i < mesh->GetVertexCount(); i++)
                {
                    Vector pos = v[i].position + opos;
                    Vector nor = v[i].normal;
                    sm.TransformVector(pos);
                    rm.RotateVector(nor);

                    pm->verts[base + i] = pos;
                    pm->normals[base + i] = nor;
                }
            }
        }

        m_parray.swap(pm);
        if(m_eds->firstVertex < 0)
            m_eds->firstVertex = 0;
        if(m_eds->lastVertex >= (int)m_parray->verts.size())
            m_eds->lastVertex = m_parray->verts.size()-1;

        delete obj;
    }
    delete model;
}
Esempio n. 3
0
/*!
	\param position bone position
	\param rotation bone rotation
	\param model_position parent model position
	\param model_rotation parent model rotation
*/
void Storm3D_Bone::SetOriginalProperties(const Vector &position, const Rotation &rotation, const Vector &model_position, const Rotation &model_rotation)
{
	this->position = position;
	this->rotation = rotation;

	// We need original orientations inverse to create vertex tm
	Matrix r;
	r.CreateRotationMatrix(model_rotation);
	Matrix t;
	t.CreateTranslationMatrix(model_position);
	
	original_inverse_tm = r * t;
	original_inverse_tm.Inverse();
}