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();*/ }
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(); }
void setBaseTransform(const Transform& baseTransform) { assert (individualTransforms.size() == 1); assert (absoluteTransforms.size() == 1); individualTransforms.front() = absoluteTransforms.front() = baseTransform; }
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])")); }
void makeCurrent(const Transform& transform) { currentIterator = std::find(absolute.begin(), absolute.end(), transform); if (currentIterator == absolute.end()) currentIterator = absolute.insert(absolute.end(), transform); }
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)); }
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)); }
void Body::getWorldTransform(btTransform& worldTrans) const { Transforms* pTransforms = getTransforms(); if (pTransforms) { worldTrans = btTransform(toBullet(pTransforms->getWorldOrientation()), toBullet(pTransforms->getWorldPosition())); } }
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())); }
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(); }
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()); }
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())); }
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); }
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); } }
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); }
Handle<Value> Transforms_ResetOrientation(const Arguments& args) { HandleScope handle_scope; Transforms* ptr = GetPtr(args.This()); assert(ptr); ptr->resetOrientation(); return Handle<Value>(); }
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(); }
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; }
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); }
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)); }
void updateBaseTransform() { if (orientation != currentOrientation()) { orientation = currentOrientation(); currentTransforms.front() = transformForOrientation(orientation); } }
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])")); }
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>(); }
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); }
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])")); }
// 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); } }
Transform& currentTransform() { return absoluteTransforms.back(); }
void pushTransform(const Transform& transform) { individualTransforms.push_back(transform); Transform result = multiply(transform, currentTransform()); makeCurrentTransform(result); }