void chaos::BitmapFontSprite::drawChar(int c, int x, int y) {
    if(bitmapFont->mapChars.find(c) == bitmapFont->mapChars.end())return;
    CharData data = bitmapFont->mapChars[c];
    bitmapFont->vecPages[data.page]->bind(GL_TEXTURE_2D);
    shader->run();
    GLint winWidth = renderer->getTargetWindow()->getWidth();
    GLint winHeight = renderer->getTargetWindow()->getHeight();
    glm::mat4 mx = glm::mat4();
    if(fitToScreen){
        //-> punkt(0,0) jest w lewym dolnym rogu, os y dodatnia do gory
        mx = glm::translate(mx, glm::vec3(-1.0f, -1.0f, 0.0f));
        mx = glm::translate(mx, glm::vec3((2.0f*x)/winWidth, (2.0f*y)/winHeight, 0.0f));
        mx = glm::scale(mx, glm::vec3((2.0f*data.width)/winWidth, (2.0f*data.height)/winHeight, 1.0));
        mx = getGlobalTransformMatrix() * mx;
    }
    else{
        mx = glm::translate(mx, glm::vec3((2.0f*x)/winWidth, (2.0f*y)/winHeight, 0.0f));
        mx = glm::scale(mx, glm::vec3((2.0f*data.width)/winWidth, (2.0f*data.height)/winHeight, 1.0));
        mx = getGlobalTransformMatrix() * mx;
        mx = renderer->getCamCombined()*mx;
    }


    shader->setUniform("mvp", mx);
    shader->setUniform("minx", data.x/(float)bitmapFont->scaleW);
    shader->setUniform("maxx", (data.x+data.xadvance)/(float)bitmapFont->scaleW);
    shader->setUniform("miny", (bitmapFont->scaleH-data.y-bitmapFont->lineHeight)/(float)bitmapFont->scaleH);
    shader->setUniform("maxy", (bitmapFont->scaleH-data.y)/(float)bitmapFont->scaleH);
    shader->setUniform("uniColor", color);
    vao->bind();
    vao->draw(shader);
    vao->unbind();
}
Example #2
0
void ofxBone::customDraw(){

	

	ofVec3f p1(0);
	ofVec3f p2(0);

	if (tr1::shared_ptr<ofxBone> p = parent.lock()){
		p1 = p1 * p->getGlobalTransformMatrix() * ofMatrix4x4::getInverseOf(getGlobalTransformMatrix());
	} else {
//		ofMatrix4x4 m4 = getGlobalTransformMatrix();
//		p1 = ofVec3f(0) * m4;
		p1 = p1 * ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()) ;
	}
	
	ofSetColor(ofColor::white);
	ofDrawArrow(p1, p2, 4);
	ofSphere(2);
	
	// draw x axis
	ofSetColor(ofColor::red);
	ofLine(0, 0, 0, 10, 0, 0);
	
	// draw y axis
	ofSetColor(ofColor::green);
	ofLine(0, 0, 0, 0, 10, 0);
	
	// draw z axis
	ofSetColor(ofColor::blue);
	ofLine(0, 0, 0, 0, 0, 10);

	
}
void VoroNode::draw(OrganicMaterial * m, bool changeMat) {
    if(m != nullptr){
        m->setWorldMatrix(getGlobalTransformMatrix());
        
        //m->setAmbientColor(tint);
        
        
        if(changeMat) {
            if(bTintSet) m->setDiffuseColor(tint);
        
            /*for( auto & c : mesh.getColors()) {
            c = tint;
             }*/
        
            m->begin();
        }
    }
    
    ofNode::draw();
    
    if(m != nullptr){
        if(changeMat) {
            m->end();
        }
    }
    
    for(auto c : getChildren()) {
        c->draw(m, changeMat);
    }
};
Example #4
0
const ofVec3f ofxBone::getGlobalJointPosition() const {
	if (tr1::shared_ptr<ofxBone> p = parent.lock()){
		return (getJointTransformMatrix() * getGlobalTransformMatrix()).getTranslation();
	} else {
		return ofVec3f(0);
	}
}
Example #5
0
//----------------------------------------
void ofCamera::begin(ofRectangle viewport) {
	if(!isActive) ofPushView();
	isActive = true;

	ofSetCoordHandedness(OF_RIGHT_HANDED);

	// autocalculate near/far clip planes if not set by user
	calcClipPlanes(viewport);

	glMatrixMode(GL_PROJECTION);
	ofLoadIdentityMatrix();
	
	if(isOrtho) {
		//			if(vFlip) glOrtho(0, width, height, 0, nearDist, farDist);
		//			else
#ifndef TARGET_OPENGLES
		glOrtho(0, viewport.width, 0, viewport.height, nearClip, farClip);
#else
		ofMatrix4x4 ortho;
		ortho.makeOrthoMatrix(0, viewport.width, 0, viewport.height, nearClip, farClip);
		ofLoadMatrix( ortho );
#endif
	} else {
		
		ofMatrix4x4 persp;
		persp.makePerspectiveMatrix( fov, viewport.width/viewport.height, nearClip, farClip );
		ofLoadMatrix( persp );
		//gluPerspective(fov, viewport.width/viewport.height, nearClip, farClip);
	}

	glMatrixMode(GL_MODELVIEW);
	ofLoadMatrix( ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()) );
	ofViewport(viewport);
}
Example #6
0
//----------------------------------------
void ofCamera::begin(ofRectangle rect) {
	if(!isActive) ofPushView();
	isActive = true;
	
	ofSetCoordHandedness(OF_RIGHT_HANDED);
	
	// autocalculate near/far clip planes if not set by user
	float nc = nearClip, fc = farClip;
	if(nearClip == 0 || farClip == 0) {
		float dist = rect.height * 0.5f / tanf(PI * fov / 360.0f);
		nc = (nearClip == 0) ? dist / 100.0f : nearClip;
		fc = (farClip == 0) ? dist * 10.0f : farClip;
	}
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	if(isOrtho) {
		//			if(vFlip) glOrtho(0, width, height, 0, nearDist, farDist);
		//			else 
#ifndef TARGET_OPENGLES
		glOrtho(0, rect.width, 0, rect.height, nc, fc);
#endif		
	} else {
		gluPerspective(fov, rect.width/rect.height, nc, fc);
	}
	
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()).getPtr());
	//ofViewport(rect.x, rect.y, rect.width, rect.height);
}
Example #7
0
//----------------------------------------
void ofNode::transformGL(ofBaseRenderer * renderer) const {
	if( renderer == nullptr ) {
		renderer = ofGetCurrentRenderer().get();
	}
	renderer->pushMatrix();
	renderer->multMatrix( getGlobalTransformMatrix() );
}
Example #8
0
void chaos::Model::draw(){
    shader->run();
    if(!isLighting){
        shader->setUniform("uniColor", color);
        shader->setUniform("mx",renderer->getCamCombined()*getGlobalTransformMatrix());
    }
    else{
        shader->setUniform("model", getGlobalTransformMatrix());
        shader->setUniform("mx",renderer->getCamCombined()*getGlobalTransformMatrix());
        shader->setUniform("uniViewPos", renderer->getActiveCamera()->getPosition());

        shader->setUniform("ambientStrength", 0.0f);
        shader->setUniform("ambientColor", glm::vec4(0, 1, 0, 1));

        shader->setUniform("uniMaterial.diffuseColor", material.getDiffuseColor());
        shader->setUniform("uniMaterial.specularColor", material.getSpecularColor());
        shader->setUniform("uniMaterial.shininess", material.getShininess());
        shader->setUniform("uniObjectColor", getColor());


        GLuint pointLightCtr=0, dirLightCtr=0, spotlightCtr=0;
        for(GLuint i = 0; i < renderer->getLightCastersVector()->size(); i++){
            if(renderer->getLightCastersVector()->at(i)->isEnabled() && renderer->getLightCastersVector()->at(i)->getLightType() == LightCaster::PointLight){
                renderer->getLightCastersVector()->at(i)->setupUniforms(shader, this, pointLightCtr);
                pointLightCtr++;
            }
            if(renderer->getLightCastersVector()->at(i)->isEnabled() && renderer->getLightCastersVector()->at(i)->getLightType() == LightCaster::DirectionalLight){
                renderer->getLightCastersVector()->at(i)->setupUniforms(shader, this, dirLightCtr);
                dirLightCtr++;
            }
            if(renderer->getLightCastersVector()->at(i)->isEnabled() && renderer->getLightCastersVector()->at(i)->getLightType() == LightCaster::Spotlight){
                renderer->getLightCastersVector()->at(i)->setupUniforms(shader, this, spotlightCtr);
                spotlightCtr++;
            }
        }

        shader->setUniform("uniPointLightsCount", pointLightCtr);
        shader->setUniform("uniDirLightsCount", dirLightCtr);
        shader->setUniform("uniSpotlightsCount", spotlightCtr);
    }

    vao->bind();
    vao->draw(shader);
    vao->unbind();
}
CC3Plane CC3PlaneNode::getPlane()
{
	CC3Box bb = getMesh()->getBoundingBox();
	
	// Get three points on the plane by using three corners of the mesh bounding box.
	CC3Vector p1 = bb.minimum;
	CC3Vector p2 = bb.maximum;
	CC3Vector p3 = bb.minimum;
	p3.x = bb.maximum.x;
	
	// Transform these points.
	p1 = getGlobalTransformMatrix()->transformLocation( p1 );
	p2 = getGlobalTransformMatrix()->transformLocation( p2 );
	p3 = getGlobalTransformMatrix()->transformLocation( p3 );
	
	// Create and return a plane from these points.
	return CC3Plane::planeFromLocations( p1, p2, p3 );
}
Example #10
0
//----------------------------------------
void ofNode::clearParent(bool bMaintainGlobalTransform) {
    if(bMaintainGlobalTransform) {
        ofMatrix4x4 globalTransform(getGlobalTransformMatrix());
        this->parent = NULL;
        setTransformMatrix(globalTransform);
    } else {
        this->parent = NULL;
    }
}
Example #11
0
//----------------------------------------
void ofNode::setParent(ofNode& parent, bool bMaintainGlobalTransform) {
    if(bMaintainGlobalTransform) {
        ofMatrix4x4 globalTransform(getGlobalTransformMatrix());
        this->parent = &parent;
        setTransformMatrix(globalTransform);
    } else {
        this->parent = &parent;
    }
}
Example #12
0
// ----------------------------------------------------------------------
const ofMatrix4x4 ofxBone::getGlobalJointTransformMatrix() const {
	ofMatrix4x4 m;
	if (tr1::shared_ptr<ofxBone> p = parent.lock()){
		m = getJointTransformMatrix() * getGlobalTransformMatrix();
	} else {
		m.setTranslation(0, 0, 0);
		m = m * localJointTransformMatrix;
	}
	return m;
}
Example #13
0
//----------------------------------------
void ofNode::setParent(ofNode& parent, bool bMaintainGlobalTransform) {
    if(bMaintainGlobalTransform) {
		ofMatrix4x4 postParentGlobalTransform = getGlobalTransformMatrix() * parent.getGlobalTransformMatrix().getInverse();
		parent.addListener(*this);
		setTransformMatrix(postParentGlobalTransform);
	} else {
		parent.addListener(*this);
	}
	this->parent = &parent;
}
ofVboMesh & VoroNode::getBakedMesh() {
    
    bakedMesh = mesh;
    // todo cache if node didn't change
    int iv = 0;
    for(auto v : mesh.getVertices()) {
        bakedMesh.setVertex(iv++, v*getGlobalTransformMatrix());
    }
    
    return bakedMesh;
}
Example #15
0
//----------------------------------------
void ofNode::clearParent(bool bMaintainGlobalTransform) {
	if(parent){
		parent->removeListener(*this);
	}
    if(bMaintainGlobalTransform) {
        ofMatrix4x4 globalTransform(getGlobalTransformMatrix());
        this->parent = nullptr;
        setTransformMatrix(globalTransform);
    } else {
        this->parent = nullptr;
    }
}
Example #16
0
//----------------------------------------
void ofLight::onOrientationChanged() {
	if(data->glIndex==-1) return;
	// if we are a directional light and not positional, update light position (direction)
	if(getIsDirectional()) {
		// (tig) takes into account global orientation should node be parented.
		ofVec3f lookAtDir = ( getGlobalTransformMatrix().getInverse() * ofVec4f(0,0,-1, 1) ).getNormalized();
		data->position = ofVec4f(lookAtDir.x,lookAtDir.y,lookAtDir.z,0);
		ofGetGLRenderer()->setLightPosition(data->glIndex,data->position);
	}else if(getIsSpotlight() || getIsAreaLight()) {
		// determines the axis of the cone light //

		// (tig) takes into account global orientation should node be parented.
		ofVec3f lookAtDir = ( getGlobalTransformMatrix().getInverse() * ofVec4f(0,0,-1, 1) ).getNormalized();
		data->direction = ofVec3f(lookAtDir.x,lookAtDir.y,lookAtDir.z);
		ofGetGLRenderer()->setLightSpotDirection(data->glIndex,data->direction);
	}
	if(getIsAreaLight()){
		data->up = getUpDir();
		data->right = getXAxis();
	}
}
 void Creature::draw(const ofCamera& cam)
 {
     ofPushMatrix();
     if (cam.getPosition().z - getPosition().z > Creature::fogEnd)
     {
         ofTranslate(0, 0, Creature::fogEnd * floor((cam.getPosition().z - getPosition().z) / Creature::fogEnd));
     }
     else if (getPosition().z > cam.getPosition().z)
     {
         ofTranslate(0, 0, -Creature::fogEnd * ceil((getPosition().z - cam.getPosition().z) / Creature::fogEnd));
     }
     ofMultMatrix(getGlobalTransformMatrix());
     customDraw();
     ofPopMatrix();
 }
//----------------------------------------
void ofLight::customDraw() {
    ofPushMatrix();
    glMultMatrixf(getGlobalTransformMatrix().getPtr());
    if(getIsPointLight()) {
        ofSphere( 0,0,0, 10);
    } else if (getIsSpotlight()) {
        float coneHeight = (sin(spotCutOff*DEG_TO_RAD) * 30.f) + 1;
        float coneRadius = (cos(spotCutOff*DEG_TO_RAD) * 30.f) + 8;
        ofCone(0, 0, -(coneHeight*.5), coneHeight, coneRadius);
    } else {
        ofBox(10);
    }
    ofDrawAxis(20);
    ofPopMatrix();
}
Example #19
0
//----------------------------------------
void ofNode::setParent(ofNode& parent, bool bMaintainGlobalTransform) {
	if (this->parent)
	{
		// we need to make sure to clear before
		// re-assigning parenthood.
		clearParent(bMaintainGlobalTransform);
	}
	if(bMaintainGlobalTransform) {
		auto postParentGlobalTransform = glm::inverse(parent.getGlobalTransformMatrix()) * getGlobalTransformMatrix();
		parent.addListener(*this);
		setTransformMatrix(postParentGlobalTransform);
	} else {
		parent.addListener(*this);
	}
	this->parent = &parent;
}
Example #20
0
CC3Ray CC3Camera::unprojectPoint( const CCPoint& cc2Point )
{
    // Scale from UI points to GL points
    CCPoint glPoint = ccpMult(cc2Point, CCDirector::sharedDirector()->getContentScaleFactor());

    // Express the glPoint X & Y as proportion of the viewport dimensions.
    CC3Viewport vp = getViewport();
    GLfloat xp = ((2.0f * glPoint.x) / vp.w) - 1;
    GLfloat yp = ((2.0f * glPoint.y) / vp.h) - 1;

    // Ensure that the camera's frustum is up to date, and then map the proportional point
    // on the viewport to its position on the near clipping rectangle. The Z-coordinate is
    // negative because the camera points down the negative Z axis in its local coordinates.
    buildProjection();
    CC3Vector pointLocNear = cc3v(_frustum->getRight() * xp, _frustum->getTop() * yp, -_frustum->getNear());

    CC3Ray ray;
    if ( isUsingParallelProjection() )
    {
        // The location on the near clipping plane is relative to the camera's
        // local coordinates. Convert it to global coordinates before returning.
        // The ray direction is straight out from that global location in the
        // camera's globalForwardDirection.
        ray.startLocation =  getGlobalTransformMatrix()->transformLocation( pointLocNear );
        ray.direction = getGlobalForwardDirection();
    }
    else
    {
        // The location on the near clipping plane is relative to the camera's local
        // coordinates. Since the camera's origin is zero in its local coordinates,
        // this point on the near clipping plane forms a directional vector from the
        // camera's origin. Rotate this directional vector with the camera's rotation
        // matrix to convert it to a global direction vector in global coordinates.
        // Thanks to Cocos3D forum user Rogs for suggesting the use of the globalRotationMatrix.
        ray.startLocation = getGlobalLocation();
        ray.direction = getGlobalRotationMatrix()->transformDirection( pointLocNear );
    }

    // Ensure the direction component is normalized before returning.
    ray.direction = ray.direction.normalize();

    //LogTrace(@"%@ unprojecting point %@ to near plane location %@ and to ray starting at %@ and pointing towards %@",
    //			  [self class], NSStringFromCGPoint(glPoint), NSStringFromCC3Vector(pointLocNear),
    //			  NSStringFromCC3Vector(ray.startLocation), NSStringFromCC3Vector(ray.direction));

    return ray;
}
Example #21
0
//----------------------------------------
void ofCamera::begin(ofRectangle viewport) {
	if(!isActive) ofPushView();
	isActive = true;

	ofSetCoordHandedness(OF_RIGHT_HANDED);

	// autocalculate near/far clip planes if not set by user
	calcClipPlanes(viewport);

	ofSetMatrixMode(OF_MATRIX_PROJECTION);
	ofLoadIdentityMatrix();

	ofLoadMatrix( this->getProjectionMatrix(viewport) );

	ofSetMatrixMode(OF_MATRIX_MODELVIEW);
	ofLoadMatrix( ofMatrix4x4::getInverseOf(getGlobalTransformMatrix()) );
	ofViewport(viewport);
}
void Astrolabe::draw()
{
	ofSetColor( color );
	
	ofPushMatrix();
	ofMultMatrix( getGlobalTransformMatrix() );
	
	if(adoptedVbo != NULL)
	{
		adoptedVbo->draw(GL_QUADS, 0, numVertices );
	}
	else if( vbo.getIsAllocated() )
	{
		vbo.draw(GL_QUADS, 0, numVertices );
	}
	
	ofPopMatrix();
}
Example #23
0
GLuint CC3MeshNode::findFirstGlobal( GLuint maxHitCount, CC3MeshIntersection* intersections, CC3Ray aRay, bool acceptBackFaces, bool acceptBehind )
{
	if ( !_mesh ) 
		return 0;

	// Convert the array to local coordinates and find intersections.
	CC3Ray localRay = getGlobalTransformMatrixInverted()->transformRay( aRay );
	GLuint hitCount = findFirst( maxHitCount, intersections, localRay, acceptBackFaces, acceptBehind );

	// Convert the intersections to global coordinates.
	for (GLuint hitIdx = 0; hitIdx < hitCount; hitIdx++) 
	{
		CC3MeshIntersection* hit = &intersections[hitIdx];
		hit->location = getGlobalTransformMatrix()->transformLocation( hit->location );
		hit->distance = hit->location.distance( aRay.startLocation );
	}

	return hitCount;
}
CC3Box CC3LocalContentNode::getLocalContentBoundingBoxRelativeTo( CC3Node* ancestor )
{
	CC3Box lcbb = getLocalContentBoundingBox();
	if (ancestor == this)
		return lcbb;

	CC3Matrix4x3 tMtx;
	getGlobalTransformMatrix()->populateCC3Matrix4x3( &tMtx );

	if ( ancestor )
		ancestor->getGlobalTransformMatrixInverted()->leftMultiplyIntoCC3Matrix4x3( &tMtx );
	
	// The eight vertices of the transformed local bounding box
	CC3Vector bbVertices[8];
	
	// Get the corners of the local bounding box
	CC3Vector bbMin = lcbb.minimum;
	CC3Vector bbMax = lcbb.maximum;
	
	// Construct all 8 corner vertices of the local bounding box and transform each
	// to the coordinate system of the ancestor. The result is an oriented-bounding-box.
	bbVertices[0] = CC3Matrix4x3TransformLocation(&tMtx, cc3v(bbMin.x, bbMin.y, bbMin.z));
	bbVertices[1] = CC3Matrix4x3TransformLocation(&tMtx, cc3v(bbMin.x, bbMin.y, bbMax.z));
	bbVertices[2] = CC3Matrix4x3TransformLocation(&tMtx, cc3v(bbMin.x, bbMax.y, bbMin.z));
	bbVertices[3] = CC3Matrix4x3TransformLocation(&tMtx, cc3v(bbMin.x, bbMax.y, bbMax.z));
	bbVertices[4] = CC3Matrix4x3TransformLocation(&tMtx, cc3v(bbMax.x, bbMin.y, bbMin.z));
	bbVertices[5] = CC3Matrix4x3TransformLocation(&tMtx, cc3v(bbMax.x, bbMin.y, bbMax.z));
	bbVertices[6] = CC3Matrix4x3TransformLocation(&tMtx, cc3v(bbMax.x, bbMax.y, bbMin.z));
	bbVertices[7] = CC3Matrix4x3TransformLocation(&tMtx, cc3v(bbMax.x, bbMax.y, bbMax.z));
	
	// Construct a transformed mesh bounding box that surrounds the eight global vertices
	CC3Box bb = CC3Box::kCC3BoxNull;
	for (int i = 0; i < 8; i++) 
		bb = bb.boxEngulfLocation( bbVertices[i] );
	return bb;
}
Example #25
0
//----------------------------------------
glm::quat ofNode::getGlobalOrientation() const {
	auto rot = glm::scale(getGlobalTransformMatrix(), 1.f/getGlobalScale());
	return glm::toQuat(rot);
}
Example #26
0
//----------------------------------------
glm::vec3 ofNode::getGlobalPosition() const {
	return getGlobalTransformMatrix()[3].xyz();
}
Example #27
0
//----------------------------------------
ofMatrix4x4 ofCamera::getModelViewMatrix() const {
	return ofMatrix4x4::getInverseOf(getGlobalTransformMatrix());
}
Example #28
0
//----------------------------------------
ofQuaternion ofNode::getGlobalOrientation() const {
    return getGlobalTransformMatrix().getRotate();
}
Example #29
0
//----------------------------------------
ofVec3f ofNode::getGlobalPosition() const {
    return getGlobalTransformMatrix().getTranslation();
}
Example #30
0
//----------------------------------------
ofMatrix4x4 ofCamera::getModelViewMatrix() const {
	ofMatrix4x4 matModelView;
	matModelView.makeInvertOf(getGlobalTransformMatrix());
	return matModelView;
}