//-------------------------------------------
void ofxAssimpModelLoader::clear(){

    ofLogVerbose("ofxAssimpModelLoader") << "clear(): deleting GL resources";

    // clear out everything.
    modelMeshes.clear();
    animations.clear();
    pos.set(0,0,0);
    scale.set(1,1,1);
    rotAngle.clear();
    rotAxis.clear();
    lights.clear();

    scale = ofPoint(1, 1, 1);
    normalizeScale = true;
    bUsingMaterials = true;
    bUsingNormals = true;
    bUsingTextures = true;
    bUsingColors = true;

    currentAnimation = -1;

    textures.clear();

    updateModelMatrix();
    ofRemoveListener(ofEvents().exit,this,&ofxAssimpModelLoader::onAppExit);
}
//-------------------------------------------
void ofxAssimpModelLoader::clear(){

    ofLog(OF_LOG_VERBOSE, "deleting gl resources");

    // clear out everything.
    modelMeshes.clear();
    animations.clear();
    pos.set(0,0,0);
    scale.set(1,1,1);
    rotAngle.clear();
    rotAxis.clear();
    lights.clear();

    scale = ofPoint(1, 1, 1);
	if(scene){
		aiReleaseImport(scene);
		scene = NULL;
	}
    normalizeScale = true;
    bUsingMaterials = true;
    bUsingNormals = true;
    bUsingTextures = true;
    bUsingColors = true;
    
    currentAnimation = -1;
    
    updateModelMatrix();
}
//-------------------------------------------
void ofxAssimpModelLoader::setScale(float x, float y, float z){
    scale.x = x;
    scale.y = y;
    scale.z = z;

    updateModelMatrix();
}
//-------------------------------------------
void ofxAssimpModelLoader::setPosition(float x, float y, float z){
    pos.x = x;
    pos.y = y;
    pos.z = z;

    updateModelMatrix();
}
Beispiel #5
0
void Node::addRotation(float angle, glm::vec3 axis)
{
	glm::mat4 newRotationMatrix = glm::rotate(getRotationMatrix(), angle, axis);
	m_rotationMatrix = newRotationMatrix;

	updateModelMatrix(m_rotationMatrix);
}
Beispiel #6
0
/**
    Sets extent, the max rendering geometry of the plane
*/
void cwGLGridPlane::setExtent(double extent) {
    if(Extent != extent) {
        Extent = extent;
        updateModelMatrix();
        emit extentChanged();
    }
}
void HierarchicalRenderable::beforeDraw()
{
    //Each time m_localTransform is modified we need to update the model matrix of the instance.
    //Each time m_parentTransform is modified we need to udpate the model matrix of the instance and its children.
    //This could be implemented efficiently using a flag system to update the hierarchy whenever m_parentTransform is called.
    updateModelMatrix();
}
void HierarchicalRenderable::beforeDraw()
{
    //Each time m_localTransform is modified we need to update the model matrix of the instance.
    //Each time m_parentTransform is modified we need to udpate the model matrix of the instance and its children.
    //This could be implemented efficiently using a flag system to update the hierarchy whenever m_parentTransform is called.
    //However this is a simple implementation and we chose to pay the price of a brutal update before each draw.
    updateModelMatrix();
}
Beispiel #9
0
void Node::addScale(float x, float y, float z)
{
	glm::vec3 scale = glm::vec3(x, y, z);
	glm::mat4 newScaleMatrix = glm::scale(getScaleMatrix(), scale);
	m_scaleMatrix = newScaleMatrix;

	updateModelMatrix(m_scaleMatrix);
}
Beispiel #10
0
cwGLGridPlane::cwGLGridPlane(QObject* parent) :
    cwGLObject(parent),
    Plane(QPlane3D(QVector3D(0.0, 0.0, -75.0), QVector3D(0.0, 0.0, 1.0))),
    Extent(3000.0), //3km in the negitive and positive direction from origin
    Program(NULL)
{
    updateModelMatrix();
}
Beispiel #11
0
void Node::addTranslation(float x, float y, float z)
{
	glm::vec3 transfer = glm::vec3(x, y, z);
	glm::mat4 newTranslationMatrix = glm::translate(getTranslationMatrix(), transfer);
	m_translateMatrix = newTranslationMatrix;

	updateModelMatrix(m_translateMatrix);
}
	Transformable3D::Transformable3D() :
	m_position(0.f),
	m_scale(1.f),
	m_modelMatrix(1.f),
	m_offsetMatrix(1.f),
	m_parent(NULL) {
		updateModelMatrix();
	}
Beispiel #13
0
void csSurface::setData(const QVector<float>& x,
                        const QVector<float>& y,
                        const QVector<float>& z)
{
  // (0) Sanity Check ////////////////////////////////////////////////////////

  if( !_meshInfo.initialize(x, y, z) ) {
    return;
  }

  // (1) Create Surface Data /////////////////////////////////////////////////

  _surfaceData.resize(3 * _meshInfo.vertexCount());
  for(int i = 0; i < _meshInfo.vertexCount(); i++) {
    const int column = _meshInfo.column(i); // x
    const int row    = _meshInfo.row(i);    // y

    _surfaceData[i*3+0] = x[column];
    _surfaceData[i*3+1] = y[row];
    _surfaceData[i*3+2] = z[i];
  }

  // (2) Create Strip Data ///////////////////////////////////////////////////

  const int numStrips       =   _meshInfo.rowCount()   -1;
  const int numVertPerStrip = 2*_meshInfo.columnCount();
  _stripData.resize(numStrips*numVertPerStrip);

  for(int y = 0; y < numStrips; y++) { // Along y-Axis
    for(int x = 0; x < _meshInfo.columnCount(); x++) { // Along x-Axis
      const int index0 = (y+1)*_meshInfo.columnCount() + x;
      const int index1 =  y   *_meshInfo.columnCount() + x;

      _stripData[y*numVertPerStrip+2*x  ] = index0;
      _stripData[y*numVertPerStrip+2*x+1] = index1;
    }
  }

  // (3) Create Mesh Data (y-Direction) //////////////////////////////////////

  _meshYData.resize(_meshInfo.vertexCount());
  for(int x = 0; x < _meshInfo.columnCount(); x++) {
    for(int y = 0; y < _meshInfo.rowCount(); y++) {
      _meshYData[x*_meshInfo.rowCount()+y] = _meshInfo.index(x, y);
    }
  }

  // (4) Update Model Matrix /////////////////////////////////////////////////

  updateModelMatrix();

  // (5) Trigger Initialization //////////////////////////////////////////////

  _initRequired = true;
}
Beispiel #14
0
///////////////////////////////////////////////////////////////////////////////
// set the object position and rotation
///////////////////////////////////////////////////////////////////////////////
void ModelGL::setModelMatrix(float x, float y, float z, float rx, float ry, float rz)
{
    modelPosition[0] = x;
    modelPosition[1] = y;
    modelPosition[2] = z;
    modelAngle[0] = rx;
    modelAngle[1] = ry;
    modelAngle[2] = rz;

    updateModelMatrix();
}
Beispiel #15
0
	Entity::Entity(void){
		this->position = glm::vec3(0.0f, 0.0f, 0.0f);
		this->rotation = glm::vec3(0.0f, 0.0f, 0.0f);
		this->scale = glm::vec3(1.0f, 1.0f, 1.0f);
		this->visible = false;
		this->mesh = NULL;
		this->material = NULL;

		updateModelMatrix();

	}
//-------------------------------------------
void ofxAssimpModelLoader::setRotation(int which, float angle, float rot_x, float rot_y, float rot_z){
    if(which + 1 > (int)rotAngle.size()){
        int diff = 1 + (which - rotAngle.size());
        for(int i = 0; i < diff; i++){
            rotAngle.push_back(0);
            rotAxis.push_back(ofPoint());
        }
    }

    rotAngle[which]  = angle;
    rotAxis[which].x = rot_x;
    rotAxis[which].y = rot_y;
    rotAxis[which].z = rot_z;

    updateModelMatrix();
}
//-------------------------------------------
void ofxAssimpModelLoader::calculateDimensions(){
	if(!scene) return;
	ofLog(OF_LOG_VERBOSE, "initted scene with %i meshes & %i animations", scene->mNumMeshes, scene->mNumAnimations);

	getBoundingBoxWithMinVector(&scene_min, &scene_max);
	scene_center.x = (scene_min.x + scene_max.x) / 2.0f;
	scene_center.y = (scene_min.y + scene_max.y) / 2.0f;
	scene_center.z = (scene_min.z + scene_max.z) / 2.0f;

	// optional normalized scaling
	normalizedScale = scene_max.x-scene_min.x;
	normalizedScale = MAX(scene_max.y - scene_min.y,normalizedScale);
	normalizedScale = MAX(scene_max.z - scene_min.z,normalizedScale);
	normalizedScale = 1.f / normalizedScale;
	normalizedScale *= normalizeFactor;
    
    updateModelMatrix();
}
Beispiel #18
0
	GlModel::GlModel(const GLuint& programId, const Camera* cameraPtr, const std::string& modelFilePath, const std::string& modelBasePath)
	:	m_programId(programId)
	,	m_position(0.0f, 0.0f, 0.0f)
	,	m_rotation(0.0f, 0.0f, 0.0f)
	,	m_scale(1.0f, 1.0f, 1.0f)
	,	m_modelMatrix()
	,	m_cameraPtr(cameraPtr)
	,	m_modelViewMatrix()
	,	m_normMatrix()
	,	m_modelFilePath(modelFilePath)
	,	m_modelBasePath(modelBasePath)
	,	m_textureManager(modelBasePath)
#ifdef SEPARATE_VBO
	,	m_glModelShapes()
#else
	,	m_glModelData(programId, &m_textureManager)
#endif // SEPARATE_VBO
	{
//----------------------------------------------------------------------------//
		std::vector<tinyobj::shape_c_t> shapes_c;
		std::string error = tinyobj::LoadModelCompact(shapes_c, modelFilePath.c_str(), modelBasePath.c_str(), false);

		if (error.empty())
		{
			glUseProgram(m_programId);

#ifdef SEPARATE_VBO
			for (std::vector<tinyobj::shape_c_t>::iterator it = shapes_c.begin(); it != shapes_c.end(); ++it)
			{
				m_glModelShapes.push_back(new GlModelShape(*it, m_programId, &m_textureManager));
			}
#else
			m_glModelData.initialize(shapes_c);
#endif // SEPARATE_VBO

			glUseProgram(0);
		}
		else
		{
			std::cerr << error;
		}
//----------------------------------------------------------------------------//
		updateModelMatrix();
	}
//-------------------------------------------
void ofxAssimpModelLoader::calculateDimensions(){
	if(!scene) return;
	ofLogVerbose("ofxAssimpModelLoader") << "calculateDimensions(): inited scene with "
		<< scene->mNumMeshes << " meshes & " << scene->mNumAnimations << " animations";

	getBoundingBoxWithMinVector(&scene_min, &scene_max);
	scene_center.x = (scene_min.x + scene_max.x) / 2.0f;
	scene_center.y = (scene_min.y + scene_max.y) / 2.0f;
	scene_center.z = (scene_min.z + scene_max.z) / 2.0f;

	// optional normalized scaling
	normalizedScale = scene_max.x-scene_min.x;
	normalizedScale = MAX(scene_max.y - scene_min.y,normalizedScale);
	normalizedScale = MAX(scene_max.z - scene_min.z,normalizedScale);
	normalizedScale = 1.f / normalizedScale;
	normalizedScale *= normalizeFactor;
    
    updateModelMatrix();
}
//-------------------------------------------
void ofxAssimpModelLoader::clear(){

    ofLogVerbose("ofxAssimpModelLoader") << "clear(): deleting GL resources";

    // clear out everything.
    modelMeshes.clear();
    animations.clear();
    pos.set(0,0,0);
    scale.set(1,1,1);
    rotAngle.clear();
    rotAxis.clear();
    lights.clear();

    scale = ofPoint(1, 1, 1);
	if(scene){
		aiReleaseImport(scene);
		scene = NULL;
	}
    normalizeScale = true;
    bUsingMaterials = true;
    bUsingNormals = true;
    bUsingTextures = true;
    bUsingColors = true;
    
    currentAnimation = -1;
    
    for(int i=0; i<textures.size(); i++) {
        if(textures[i]->hasTexture()) {
            ofTexture * tex = textures[i]->getTexturePtr();
            delete tex;
        }
    }
    textures.clear();
    
    updateModelMatrix();
    ofRemoveListener(ofEvents().exit,this,&ofxAssimpModelLoader::onAppExit);
}
//-------------------------------------------
void ofxAssimpModelLoader::calculateDimensions(){
	if(!scene) return;
	ofLogVerbose("ofxAssimpModelLoader") << "calculateDimensions(): inited scene with "
		<< scene->mNumMeshes << " meshes & " << scene->mNumAnimations << " animations";

	getBoundingBoxWithMinVector(&scene_min, &scene_max);
	scene_center.x = (scene_min.x + scene_max.x) / 2.0f;
	scene_center.y = (scene_min.y + scene_max.y) / 2.0f;
	scene_center.z = (scene_min.z + scene_max.z) / 2.0f;

	// optional normalized scaling
	normalizedScale = scene_max.x-scene_min.x;
	normalizedScale = MAX(scene_max.y - scene_min.y,normalizedScale);
	normalizedScale = MAX(scene_max.z - scene_min.z,normalizedScale);
    if (abs(normalizedScale) < std::numeric_limits<float>::epsilon()){
        ofLogWarning("ofxAssimpModelLoader") << "Error calculating normalized scale of scene" << endl;
        normalizedScale = 1.0;
    } else {
        normalizedScale = 1.f / normalizedScale;
        normalizedScale *= normalizeFactor;
    }
    
    updateModelMatrix();
}
//-------------------------------------------
void ofxAssimpModelLoader::setScaleNormalization(bool normalize) {
    normalizeScale = normalize;

    updateModelMatrix();
}
Beispiel #23
0
void PS3_setPositionX(float posX) {
	translator.setX(posX);
	updateModelMatrix();
}
Beispiel #24
0
void PS3_setPositionY(float posY) {
	translator.setY(posY);
	updateModelMatrix();
}
Beispiel #25
0
	void GlModel::setScale(const Vec3& scale)
	{
		m_scale = scale;
		updateModelMatrix();
	}
Beispiel #26
0
	void GlModel::setRotation(const Vec3& rotation)
	{
		m_rotation = rotation;
		updateModelMatrix();
	}
Beispiel #27
0
void PS3_setVideoSizeV(float size) {
	scaler.setY(size);
	updateModelMatrix();
}
Beispiel #28
0
void cwGLGridPlane::setPlane(QPlane3D plane) {
    if(plane != Plane) {
        plane = Plane;
        updateModelMatrix();
    }
}
Beispiel #29
0
	void GlModel::setPosition(const Vec3& position)
	{
		m_position = position;
		updateModelMatrix();
	}
Beispiel #30
0
 void Component::setParent(Component* component)
 {
     m_parent = component;
     updateModelMatrix();
 }