Beispiel #1
0
Handle<Value> Transforms_LookAt(const Arguments& args)
{
    HandleScope handle_scope;

    Transforms* ptr = GetPtr(args.This());
    assert(ptr);

    if (((args.Length() >= 1) && (args.Length() <= 3)) && isJSVector3(args[0]))
    {
        Vector3 targetPoint = fromJSVector3Unsafe(args[0]);

        Transforms::tTransformSpace relativeTo = Transforms::TS_LOCAL;
        if ((args.Length() >= 2) && args[1]->IsUint32())
            relativeTo = (Transforms::tTransformSpace) args[1]->Uint32Value();

        Vector3 localDirectionVector = Vector3::NEGATIVE_UNIT_Z;
        if ((args.Length() == 3) && isJSVector3(args[2]))
            localDirectionVector = fromJSVector3Unsafe(args[2]);

        ptr->lookAt(targetPoint, relativeTo, localDirectionVector);

        return Handle<Value>();
    }

    return ThrowException(String::New("Invalid parameters, syntax: lookAt(targetPoint [, relativeTo [, localDirectionVector]])"));
}
void getRMSD(MatrixWindow *_win1, MatrixWindow *_win2, System *_sys2){
    Transforms t;
    AtomVector ca1 = (*_win1).getSmallAVec();
    AtomVector ca2 = (*_win2).getSmallAVec();
    AtomVector a2 = (*_sys2).getAtoms();

    bool result = t.align(ca2, ca1, a2);
    if(!result){
	cout<<"Alignment has failed!"<<endl;
	exit(1211);
    }

    double r=ca1.rmsd(ca2);
    fprintf(stdout, "RMSD: %8.3f\n", r);

    //write out aligned pdb

    /*char a[80];
      sprintf(a, "/snap/cluster/jdegrado/pizza/%03d.aligned.%03d.pdb",j,i);

      PDBWriter w(a);
      w.write(a2);
      w.close();*/

}
Beispiel #3
0
void Transforms::translate(const Vector3& d, tTransformSpace relativeTo)
{
    Vector3 adjusted;

    switch(relativeTo)
    {
    case TS_LOCAL:
        // Position is relative to parent so transform downwards
        m_position += m_orientation * d;
        break;

    case TS_PARENT:
        m_position += d;
        break;

    case TS_WORLD:
        {
            // Position is relative to parent so transform upwards
            Transforms* pParent = getTransforms();
            if (pParent)
                m_position += (pParent->getWorldOrientation().Inverse() * d) / pParent->getWorldScale();
            else
                m_position += d;
            break;
        }
    }

    needUpdate();
}
Beispiel #4
0
 void setBaseTransform(const Transform& baseTransform)
 {
     assert (individualTransforms.size() == 1);
     assert (absoluteTransforms.size() == 1);
     
     individualTransforms.front() = absoluteTransforms.front() = baseTransform;
 }
Beispiel #5
0
Handle<Value> Transforms_Translate(const Arguments& args)
{
    HandleScope handle_scope;

    Transforms* ptr = GetPtr(args.This());
    assert(ptr);

    if (((args.Length() == 1) || (args.Length() == 2)) && isJSVector3(args[0]))
    {
        Vector3 d = fromJSVector3Unsafe(args[0]);

        Transforms::tTransformSpace relativeTo = Transforms::TS_LOCAL;
        if ((args.Length() == 2) && args[1]->IsUint32())
            relativeTo = (Transforms::tTransformSpace) args[1]->Uint32Value();

        ptr->translate(d, relativeTo);

        return Handle<Value>();
    }
    else if (((args.Length() == 3) || (args.Length() == 4)) &&
             args[0]->IsNumber() && args[1]->IsNumber() && args[2]->IsNumber())
    {
        Transforms::tTransformSpace relativeTo = Transforms::TS_LOCAL;
        if ((args.Length() == 4) && args[3]->IsUint32())
            relativeTo = (Transforms::tTransformSpace) args[3]->Uint32Value();

        ptr->translate(args[0]->NumberValue(), args[1]->NumberValue(), args[2]->NumberValue(), relativeTo);

        return Handle<Value>();
    }

    return ThrowException(String::New("Invalid parameters, syntax: translate(vector3 [, transform_space]) or translate(dx, dy, dz [, transform_space])"));
}
Beispiel #6
0
 void makeCurrent(const Transform& transform)
 {
     currentIterator =
         std::find(absolute.begin(), absolute.end(), transform);
     if (currentIterator == absolute.end())
         currentIterator = absolute.insert(absolute.end(), transform);
 }
Beispiel #7
0
 DrawOpQueue()
 {
     // Every queue has a base transform that is always the current transform.
     // This keeps the code a bit more uniform, and allows the window to
     // set a base transform in the main rendering queue.
     individualTransforms.push_back(scale(1));
     absoluteTransforms.push_back(scale(1));
 }
Beispiel #8
0
void Transforms_SetOrientation(Local<String> property, Local<Value> value, const AccessorInfo& info)
{
    HandleScope handle_scope;

    Transforms* ptr = GetPtr(info.This());
    assert(ptr);

    ptr->setOrientation(fromJSQuaternion(value));
}
Beispiel #9
0
void Body::getWorldTransform(btTransform& worldTrans) const
{
    Transforms* pTransforms = getTransforms();
    if (pTransforms)
    {
        worldTrans = btTransform(toBullet(pTransforms->getWorldOrientation()),
                                 toBullet(pTransforms->getWorldPosition()));
    }
}
Beispiel #10
0
Handle<Value> Transforms_GetInheritScale(Local<String> property, const AccessorInfo &info)
{
    HandleScope handle_scope;

    Transforms* ptr = GetPtr(info.This());
    assert(ptr);

    return handle_scope.Close(Boolean::New(ptr->inheritScale()));
}
Beispiel #11
0
 void reset()
 {
     // Every queue has a base transform that is always the current transform.
     // This keeps the code a bit more uniform, and allows the window to
     // set a base transform in the main rendering queue.
     individual.resize(1);
     absolute.resize(1);
     currentIterator = absolute.begin();
 }
Beispiel #12
0
void Transforms_SetInheritScale(Local<String> property, Local<Value> value, const AccessorInfo& info)
{
    HandleScope handle_scope;

    Transforms* ptr = GetPtr(info.This());
    assert(ptr);

    ptr->setInheritScale(value->BooleanValue());
}
Beispiel #13
0
Handle<Value> Transforms_GetOrientation(Local<String> property, const AccessorInfo &info)
{
    HandleScope handle_scope;

    Transforms* ptr = GetPtr(info.This());
    assert(ptr);

    return handle_scope.Close(toJavaScript(ptr->getOrientation()));
}
Beispiel #14
0
void Transforms::setDirection(const Vector3& vec, tTransformSpace relativeTo,
                              const Vector3& localDirectionVector)
{
    // Do nothing if given a zero vector
    if (vec == Vector3::ZERO)
        return;

    // The direction we want the local direction point to
    Vector3 targetDir = vec.normalisedCopy();

    // Retrieve the parent transforms of this component
    Transforms* pParentTransforms = getTransforms();

    // Transform target direction to world space
    switch (relativeTo)
    {
    case TS_LOCAL:
        targetDir = getWorldOrientation() * targetDir;
        break;

    case TS_PARENT:
        if (m_bInheritOrientation && pParentTransforms)
            targetDir = pParentTransforms->getWorldOrientation() * targetDir;
        break;

    case TS_WORLD:
        // default orientation
        break;
    }

    // Calculate target orientation relative to world space
    Quaternion targetOrientation;

    // Get current local direction relative to world space
    const Quaternion& currentOrient = getWorldOrientation();
    Vector3 currentDir = currentOrient * localDirectionVector;

    if ((currentDir + targetDir).squaredLength() < 0.00005f)
    {
        // Oops, a 180 degree turn (infinite possible rotation axes)
        // Default to yaw i.e. use current UP
        targetOrientation =
            Quaternion(-currentOrient.y, -currentOrient.z, currentOrient.w, currentOrient.x);
    }
    else
    {
        // Derive shortest arc to new direction
        Quaternion rotQuat = currentDir.getRotationTo(targetDir);
        targetOrientation = rotQuat * currentOrient;
    }

    // Set target orientation, transformed to parent space
    if (pParentTransforms && m_bInheritOrientation)
        setOrientation(pParentTransforms->getWorldOrientation().UnitInverse() * targetOrientation);
    else
        setOrientation(targetOrientation);
}
Beispiel #15
0
void Body::setWorldTransform(const btTransform& worldTrans)
{
    Transforms* pTransforms = getTransforms();
    if (pTransforms)
    {
        pTransforms->translate(fromBullet(worldTrans.getOrigin()) - pTransforms->getWorldPosition(), Transforms::TS_WORLD);

        if (m_bRotationEnabled)
            pTransforms->rotate(pTransforms->getWorldOrientation().rotationTo(fromBullet(worldTrans.getRotation())), Transforms::TS_WORLD);
    }
}
Beispiel #16
0
 void pop()
 {
     assert (individual.size() > 1);
     
     individual.pop_back();
     Transform result = scale(1);
     for (Transforms::reverse_iterator it = individual.rbegin(),
             end = individual.rend(); it != end; ++it)
         result = multiply(result, *it);
     makeCurrent(result);
 }
Beispiel #17
0
Handle<Value> Transforms_ResetOrientation(const Arguments& args)
{
    HandleScope handle_scope;

    Transforms* ptr = GetPtr(args.This());
    assert(ptr);

    ptr->resetOrientation();

    return Handle<Value>();
}
Beispiel #18
0
 void clear()
 {
     absoluteTransforms.resize(1);
     // Important!! Due to all the swapping, the first entry in the list is not necessarily
     // the base matrix. We need to restore it.
     absoluteTransforms.front() = scale(1);
     individualTransforms.resize(1);
     clipRectStack.clear();
     glBlocks.clear();
     ops.clear();
 }
Beispiel #19
0
void Transforms::update()
{
    if (!m_bDirty)
        return;

    Transforms* pParent = getTransforms();
    if (pParent)
    {
        // Update orientation
        const Quaternion& parentOrientation = pParent->getWorldOrientation();
        if (m_bInheritOrientation)
        {
            // Combine orientation with that of parent
            m_fullOrientation = parentOrientation * m_orientation;
            m_fullOrientation.normalise();
        }
        else
        {
            // No inheritence
            m_fullOrientation = m_orientation;
        }

        // Update scale
        const Vector3& parentScale = pParent->getWorldScale();
        if (m_bInheritScale)
        {
            // Scale own position by parent scale, NB just combine
            // as equivalent axes, no shearing
            m_fullScale = parentScale * m_scale;
        }
        else
        {
            // No inheritence
            m_fullScale = m_scale;
        }

        // Change position vector based on parent's orientation & scale
        m_fullPosition = parentOrientation * (parentScale * m_position);

        // Add altered position vector to parents
        m_fullPosition += pParent->getWorldPosition();
    }
    else
    {
        // No parent
        m_fullPosition      = m_position;
        m_fullOrientation   = m_orientation;
        m_fullScale         = m_scale;
    }

    m_bDirty = false;
}
Beispiel #20
0
 void popTransform()
 {
     assert (individualTransforms.size() > 1);
     
     individualTransforms.pop_back();
     // TODO: If currentTransform() wouldn't have to be .back(), then I think
     // this could be optimized away and just be pop_back too. Or not?
     Transform result = scale(1);
     for (Transforms::reverse_iterator it = individualTransforms.rbegin(),
             end = individualTransforms.rend(); it != end; ++it)
         result = multiply(result, *it);
     makeCurrentTransform(result);
 }
Beispiel #21
0
void Transforms_SetPosition(Local<String> property, Local<Value> value, const AccessorInfo& info)
{
    HandleScope handle_scope;

    Transforms* ptr = GetPtr(info.This());
    assert(ptr);

    if (!isJSVector3(value))
    {
        ThrowException(String::New("Invalid value, expected a Vector3"));
        return;
    }

    ptr->setPosition(fromJSVector3Unsafe(value));
}
Beispiel #22
0
 void updateBaseTransform()
 {
     if (orientation != currentOrientation())
     {
         orientation = currentOrientation();
         currentTransforms.front() = transformForOrientation(orientation);
     }
 }
Beispiel #23
0
Handle<Value> Transforms_Yaw(const Arguments& args)
{
    HandleScope handle_scope;

    Transforms* ptr = GetPtr(args.This());
    assert(ptr);

    if (((args.Length() >= 1) && (args.Length() <= 2)) && args[0]->IsNumber())
    {
        Transforms::tTransformSpace relativeTo = Transforms::TS_LOCAL;
        if ((args.Length() == 2) && args[1]->IsUint32())
            relativeTo = (Transforms::tTransformSpace) args[1]->Uint32Value();

        ptr->yaw(Radian(args[0]->NumberValue()), relativeTo);

        return Handle<Value>();
    }

    return ThrowException(String::New("Invalid parameters, syntax: yaw(angle [, relativeTo])"));
}
Beispiel #24
0
Handle<Value> Transforms_Rescale(const Arguments& args)
{
    HandleScope handle_scope;

    Transforms* ptr = GetPtr(args.This());
    assert(ptr);

    if ((args.Length() == 1) && isJSVector3(args[0]))
    {
        ptr->scale(fromJSVector3Unsafe(args[0]));
    }
    else if ((args.Length() == 3) &&
             args[0]->IsNumber() && args[1]->IsNumber() && args[2]->IsNumber())
    {
        ptr->scale(args[0]->NumberValue(), args[1]->NumberValue(), args[2]->NumberValue());
    }
    else
    {
        return ThrowException(String::New("Invalid parameters, syntax: scale(vector3) or scale(dx, dy, dz)"));
    }

    return Handle<Value>();
}
Beispiel #25
0
 void makeCurrentTransform(const Transform& transform)
 {
     Transforms::iterator oldPosition =
         std::find(absoluteTransforms.begin(), absoluteTransforms.end(), transform);
     if (oldPosition == absoluteTransforms.end())
         absoluteTransforms.push_back(transform);
     else
         absoluteTransforms.splice(absoluteTransforms.end(), absoluteTransforms, oldPosition);
 }
Beispiel #26
0
Handle<Value> Transforms_Rotate(const Arguments& args)
{
    HandleScope handle_scope;

    Transforms* ptr = GetPtr(args.This());
    assert(ptr);

    if (isJSVector3(args[0]))
    {
        if (args[1]->IsNumber())
        {
            Vector3 axis = fromJSVector3Unsafe(args[0]);

            Transforms::tTransformSpace relativeTo = Transforms::TS_LOCAL;
            if ((args.Length() == 3) && args[2]->IsUint32())
                relativeTo = (Transforms::tTransformSpace) args[2]->Uint32Value();

            ptr->rotate(axis, Radian(args[1]->NumberValue()), relativeTo);

            return Handle<Value>();
        }
    }
    else if (isJSQuaternion(args[0]))
    {
        Quaternion q = fromJSQuaternionUnsafe(args[0]);

        Transforms::tTransformSpace relativeTo = Transforms::TS_LOCAL;
        if ((args.Length() == 2) && args[1]->IsUint32())
            relativeTo = (Transforms::tTransformSpace) args[1]->Uint32Value();

        ptr->rotate(q, relativeTo);

        return Handle<Value>();
    }

    return ThrowException(String::New("Invalid parameters, syntax: rotate(axis, angle [, relativeTo]) or rotate(quaternion [, relativeTo])"));
}
Beispiel #27
0
 // Custom assignment to ensure valid currentIterator
 TransformStack& operator=(const TransformStack &other)
 {
     individual = other.individual;
     absolute = other.absolute;
     
     // Reset our currentIterator to point to the respective element
     // in our own 'absolute' transforms by iterating both lists up to
     // the other lists' current iterator
     currentIterator = absolute.begin();
     Transforms::const_iterator otherIterator = other.absolute.begin();
     while (otherIterator != other.currentIterator)
         ++currentIterator, ++otherIterator;
     
     return *this;
 }
/**
 * You need to fill this in!
 *
 * Draws each of the particles by making a call to glDrawArrays()
 * for each particle with a different ModelViewProjection matrix.
 */
void ParticleEmitter::drawParticlesVAO(Transforms transform, GLuint mvpLocation, GLuint colorLocation){
    if (!m_isInitialized){
        std::cout << "You must call initGL() before you can draw!" << std::endl;
    } else{
        // Bind the VAO
        glBindVertexArray(m_vao);

        glBlendFunc(GL_SRC_ALPHA, GL_ONE);
        glDepthMask(GL_FALSE);
        glEnable(GL_BLEND);

        GLfloat* color = new GLfloat[4];
        color[0] = 1;
        color[1] = 1;
        color[2] = 1;
        color[3] = 1;


        // @TODO: Render each particle
        for(int i = 0; i < m_maxParticles; ++i)
        {
            Particle &particle = m_particles[i];
            transform.model = glm::translate(glm::mat4(1.f), particle.pos);
            glUniformMatrix4fv(mvpLocation, 1, GL_FALSE, glm::value_ptr(transform.getTransform()));
            glUniform4f(colorLocation, particle.color.x, particle.color.y, particle.color.z, 2*sqrt(particle.life)/*1.f/glm::length(particle.pos)*/);
            glDrawArrays(GL_TRIANGLES, 0, 6);

        }

        glAccum(GL_MULT, 0.5);
        glAccum(GL_ACCUM, 1);
        glAccum(GL_RETURN, 1);


        // Unbind the VAO
        glBindVertexArray(0);
        delete[] color;
        color = NULL;

        glDepthMask(GL_TRUE);
        glDisable(GL_BLEND);

    }
}
Beispiel #29
0
 Transform& currentTransform()
 {
     return absoluteTransforms.back();
 }
Beispiel #30
0
 void pushTransform(const Transform& transform)
 {
     individualTransforms.push_back(transform);
     Transform result = multiply(transform, currentTransform());
     makeCurrentTransform(result);
 }