예제 #1
0
//----------------------------------------------------------
//void ofxObject::draw(float *_matrix){
void ofxObject::draw(ofxObjectMaterial *iMaterial, float *iMatrix, int iSelect, bool iDrawAlone)
{
	//if(id == 1) printf("i am a circle %f - %f, %f, %f\n", ofGetElapsedTimef(), color.r, color.g, color.b);
  
	//call idle whether or not the object is shown
	//PEND: this might have to move down, so it doesn't get called multiple times
	//idle(ofGetElapsedTimef());
  
  
	if(shown) {
		
		//printf("ofxObject::draw()\n");
		if(!iDrawAlone){
			float *mat = updateMatrix(iMatrix);
			ofxObjectMaterial *m = updateMaterial(iMaterial);	//v4.0
      
			predraw();
      
			if ((iSelect == OF_RENDER_TRANSPARENT) && !hasTransparency()) {
				//Don't render — Transparent render pass, but this object is opaque
			}else if ((iSelect == OF_RENDER_OPAQUE) && hasTransparency()) {
				//Don't render — Opaque render pass, but this object is transparent
			}else if ((iSelect != OF_RENDER_ONTOP) && renderOntop) {
				//Don't render — Regular pass, but this is an on top object
			}else {
				//Render!
				render();
				//for (unsigned int i = 0; i < children.size(); i++)
        //children[i]->draw(m, mat, iSelect);
			}
			//v4.0 - to get alpha inheritance working
			for (unsigned int i = 0; i < children.size(); i++)
				children[i]->draw(m, mat, iSelect);
      
			postdraw();
		}
		else{
			//iDrawAlone is true — just draw this object (no children)
			//PEND idle of children won't get called for these objects! live with it or fix it
			//v4.0 (moving children draw loop above might have fixed it)
			predraw();
			render();
			postdraw();
		}
	}
	
}
예제 #2
0
void Mesh2DView::
generateSceneGraph(
  bool /*bForce*/)
{
  m_material->diffuseColor.setValue(obj->sbColour());
  updateMaterial();
  root->addChild(m_material);
  root->addChild(m_drawStyle);

  SoGroup *cache;
  if(obj->isCachedVisualisation())
  {
    cache = obj->cachedVisualisation();
  }
  else
  {
    cache = new SoGroup;
    WlzErrorNum errNum = WLZ_ERR_NONE;

    SoCoordinate3 * nodes;                   // nodes of the mesh
    SoIndexedFaceSet * faceset;              // lines of the mesh

    nodes = Vertices2D(new SoCoordinate3, errNum);
    if(errNum == WLZ_ERR_NONE)
    {
      faceset = Faces2D(new SoIndexedFaceSet, errNum);
    }
    if( (errNum != WLZ_ERR_NONE) || (nodes == NULL) || (faceset == NULL))
    {
      return ;
    }

    SoShapeHints *h1= new SoShapeHints;
    Q_ASSERT(h1);
    h1->vertexOrdering = SoShapeHints::CLOCKWISE;
    h1->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
    cache->addChild(h1);
    cache->addChild(nodes);
    cache->addChild(faceset);
    obj->setVisualisation(cache);
  }
  root->addChild(cache);
}
예제 #3
0
파일: Water.cpp 프로젝트: Argos86/dt2370
    WaterListener(RenderWindow* win, Camera* cam,
		WaterMesh *waterMesh, Entity *waterEntity)
        : ExampleFrameListener(win, cam)
    {
		this->waterMesh = waterMesh ;
		this->waterEntity = waterEntity ;
		materialNumber = 8;
		timeoutDelay = 0.0f;
		headDepth = 2.0f;
		skyBoxOn = false ;

		updateMaterial();
		updateInfoParamC();
		updateInfoParamD();
		updateInfoParamU();
		updateInfoParamT();
		updateInfoNormals();
		updateInfoHeadDepth();
		updateInfoSkyBox();
    }
예제 #4
0
void RenderMeshExample::unpackUpdate(NetConnection *conn, BitStream *stream)
{
   // Let the Parent read any info it sent
   Parent::unpackUpdate(conn, stream);

   if ( stream->readFlag() )  // TransformMask
   {
      mathRead(*stream, &mObjToWorld);
      mathRead(*stream, &mObjScale);

      setTransform( mObjToWorld );
   }

   if ( stream->readFlag() )  // UpdateMask
   {
      stream->read( &mMaterialName );

      if ( isProperlyAdded() )
         updateMaterial();
   }
}
예제 #5
0
파일: Water.cpp 프로젝트: Argos86/dt2370
	void updateMaterial()
	{
		String materialName = MATERIAL_PREFIX+StringConverter::toString(materialNumber);
		MaterialPtr material = MaterialManager::getSingleton().getByName(materialName);
		if (material.isNull())
        {
			if(materialNumber)
            {
				materialNumber = 0 ;
				updateMaterial();
				return ;
			}
            else
            {
				OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
					"Material "+materialName+"doesn't exist!",
					"WaterListener::updateMaterial");
			}
		}
		waterEntity->setMaterialName(materialName);
		OverlayManager::getSingleton().getOverlayElement("Example/Water/Material") \
			->setCaption(String("[M]Material: ")+materialName);
	}
예제 #6
0
파일: Water.cpp 프로젝트: Argos86/dt2370
	void switchMaterial()
	{
		materialNumber++;
		updateMaterial();
	}
예제 #7
0
void EnlightedNode::update(QFixture* fixture, Light* light) {
  updateMatrix(fixture);
  updateMaterial(light);
}
예제 #8
0
	void LightningManager::update(const Ogre::Real& timeSinceLastFrame)
	{
		if (!mCreated)
		{
			return;
		}

		if (mEnabled)
		{
			mRemainingTime -= timeSinceLastFrame;

			if (mRemainingTime <= 0)
			{
				mRemainingTime = Ogre::Math::RangeRandom(0, 2*mAverageLightningApparitionTime);

				// Select a random camera to place the lightning
				if (!mVClouds->_getCamerasData().empty())
				{
					Ogre::Camera* c = mVClouds->_getCamerasData().at(mVClouds->_getCamerasData().size()*0.999).camera;

					Ogre::Real prob = Ogre::Math::RangeRandom(0,1);
					
					// Cloud-to-ground
					if (prob < 0.5)
					{
						addLightning(
							// Ray position
							Ogre::Vector3(c->getDerivedPosition().x + Ogre::Math::RangeRandom(-c->getFarClipDistance()*0.5,c->getFarClipDistance()*0.5)/Ogre::Math::RangeRandom(1,5), mVClouds->getGeometrySettings().Height.x + 0.2*mVClouds->getGeometrySettings().Height.y, c->getDerivedPosition().z + Ogre::Math::RangeRandom(-c->getFarClipDistance()*0.5,c->getFarClipDistance()*0.5)/Ogre::Math::RangeRandom(1,5)), 
							// Ray direction
							Ogre::Vector3(0,-1,0), 
							// Ray length
							mVClouds->getGeometrySettings().Height.x + 0.1*mVClouds->getGeometrySettings().Height.y);
					}
					// Cloud-to-cloud
					else if (prob < 0.7)
					{
						addLightning(
							// Ray position
							Ogre::Vector3(c->getDerivedPosition().x + Ogre::Math::RangeRandom(-c->getFarClipDistance()*0.5,c->getFarClipDistance()*0.5)/Ogre::Math::RangeRandom(1,5), mVClouds->getGeometrySettings().Height.x + 0.2*mVClouds->getGeometrySettings().Height.y, c->getDerivedPosition().z + Ogre::Math::RangeRandom(-c->getFarClipDistance()*0.5,c->getFarClipDistance()*0.5)/Ogre::Math::RangeRandom(1,5)), 
							// Ray direction
							Ogre::Vector3(Ogre::Math::RangeRandom(-1,1),Ogre::Math::RangeRandom(-0.1,0.1),Ogre::Math::RangeRandom(-1,1)).normalisedCopy(), 
							// Ray length
							Ogre::Math::RangeRandom(0.5,1.5f)*0.2*mVClouds->getGeometrySettings().Height.y);
					}
					// Cloud-to-ground + cloud-to-cloud
					else
					{
						addLightning(
							// Ray position
							Ogre::Vector3(c->getDerivedPosition().x + Ogre::Math::RangeRandom(-c->getFarClipDistance()*0.5,c->getFarClipDistance()*0.5)/Ogre::Math::RangeRandom(1,5), mVClouds->getGeometrySettings().Height.x + 0.2*mVClouds->getGeometrySettings().Height.y, c->getDerivedPosition().z + Ogre::Math::RangeRandom(-c->getFarClipDistance()*0.5,c->getFarClipDistance()*0.5)/Ogre::Math::RangeRandom(1,5)), 
							// Ray direction
							Ogre::Vector3(0,-1,0), 
							// Ray length
							mVClouds->getGeometrySettings().Height.x + 0.1*mVClouds->getGeometrySettings().Height.y);

						addLightning(
							// Ray position
							Ogre::Vector3(c->getDerivedPosition().x + Ogre::Math::RangeRandom(-c->getFarClipDistance()*0.5,c->getFarClipDistance()*0.5)/Ogre::Math::RangeRandom(1,5), mVClouds->getGeometrySettings().Height.x + 0.2*mVClouds->getGeometrySettings().Height.y, c->getDerivedPosition().z + Ogre::Math::RangeRandom(-c->getFarClipDistance()*0.5,c->getFarClipDistance()*0.5)/Ogre::Math::RangeRandom(1,5)), 
							// Ray direction
							Ogre::Vector3(Ogre::Math::RangeRandom(-1,1),Ogre::Math::RangeRandom(-0.1,0.1),Ogre::Math::RangeRandom(-1,1)).normalisedCopy(), 
							// Ray length
							Ogre::Math::RangeRandom(0.5,1.5f)*0.2*mVClouds->getGeometrySettings().Height.y);
					}

					updateMaterial();
				}
			}
		}

		for(std::vector<Lightning*>::iterator it = mLightnings.begin(); it != mLightnings.end();)
		{
			if ((*it)->isFinished())
			{
				Ogre::SceneNode* sn = (*it)->getSceneNode();

				delete (*it);
				it = mLightnings.erase(it);

				// Remove the associated scene node
				for(std::vector<Ogre::SceneNode*>::iterator it2 = mSceneNodes.begin(); it2 != mSceneNodes.end(); it2++)
				{
					if ((*it2) == sn)
					{
						sn->getParentSceneNode()->removeAndDestroyChild(sn);
						mSceneNodes.erase(it2);
						break;
					}
				}
			}
			else
			{
				(*it)->update(timeSinceLastFrame);
				it++;
			}
		}
	}
예제 #9
0
void GLLineIlluminator::enableLighting(GLContextData& contextData) const
	{
	/* Get a pointer to the context data item: */
	DataItem* dataItem=contextData.retrieveDataItem<DataItem>(this);
	
	/* Update the material texture if it is outdated: */
	if(dataItem->materialVersion!=materialVersion)
		updateMaterial(dataItem);
	
	GLenum previousMatrixMode=glGet<GLint>(GL_MATRIX_MODE);
	
	Geometry::Matrix<GLfloat,4,4> modelView;
	if(autoViewDirection||autoLightDirection)
		{
		/* Get the modelview matrix from OpenGL: */
		GLfloat matrixArray[16];
		glGetFloatv(GL_MODELVIEW_MATRIX,matrixArray);
		modelView=Geometry::Matrix<GLfloat,4,4>::fromColumnMajor(matrixArray);
		}
	
	/* Determine the view direction: */
	Geometry::ComponentArray<GLfloat,3> viewDir(viewDirection.getXyzw());
	if(autoViewDirection)
		{
		/* Get the projection matrix from OpenGL: */
		GLfloat matrixArray[16];
		glGetFloatv(GL_PROJECTION_MATRIX,matrixArray);
		Geometry::Matrix<GLfloat,4,4> projection=Geometry::Matrix<GLfloat,4,4>::fromColumnMajor(matrixArray);
		
		/* Calculate the view direction from the OpenGL projection and modelview matrices: */
		Geometry::ComponentArray<GLfloat,4> viewPos(0.0f,0.0f,1.0f,0.0f);
		viewPos=viewPos/projection;
		viewPos=viewPos/modelView;
		
		/* Check if it's an orthogonal or perspective projection: */
		if(Math::abs(viewPos[3])<1.0e-8f)
			{
			/* Just copy the view direction: */
			viewDir=viewPos;
			}
		else
			{
			/* Calculate the direction from the view point to the scene center: */
			for(int i=0;i<3;++i)
				viewDir[i]=viewPos[i]/viewPos[3]-sceneCenter[i];
			}
		GLfloat viewDirLen=GLfloat(Geometry::mag(viewDir));
		for(int i=0;i<3;++i)
			viewDir[i]/=viewDirLen;
		}
	
	/* Determine the light direction: */
	Geometry::ComponentArray<GLfloat,3> lightDir(lightDirection.getXyzw());
	if(autoLightDirection)
		{
		/* Query the light direction from OpenGL and transform it to model coordinates: */
		Geometry::ComponentArray<GLfloat,4> lightPos;
		glGetLightPosition(autoLightIndex,lightPos.getComponents());
		lightPos=lightPos/modelView;
		
		/* Check if it's a directional or point light: */
		if(Math::abs(lightPos[3])<1.0e-8f)
			{
			/* Just copy the light direction: */
			lightDir=lightPos;
			}
		else
			{
			/* Calculate the direction from the light source to the scene center: */
			for(int i=0;i<3;++i)
				lightDir[i]=lightPos[i]/lightPos[3]-sceneCenter[i];
			}
		GLfloat lightDirLen=GLfloat(Geometry::mag(lightDir));
		for(int i=0;i<3;++i)
			lightDir[i]/=lightDirLen;
		}
	
	/* Set up the OpenGL texture matrix: */
	glMatrixMode(GL_TEXTURE);
	glPushMatrix();
	GLfloat matrix[4][4];
	for(int j=0;j<3;++j)
		{
		matrix[j][0]=lightDir[j];
		matrix[j][1]=viewDir[j];
		matrix[j][2]=0.0f;
		matrix[j][3]=0.0f;
		}
	matrix[3][0]=1.0f;
	matrix[3][1]=1.0f;
	matrix[3][2]=0.0f;
	matrix[3][3]=2.0f;
	glLoadMatrixf((const GLfloat*)matrix);
	
	/* Set the OpenGL rendering mode: */
	glPushAttrib(GL_TEXTURE_BIT);
	glBindTexture(GL_TEXTURE_2D,dataItem->materialTextureId);
	glEnable(GL_TEXTURE_2D);
	if(dataItem->materialType==INTENSITY)
		glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
	else
		glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
	
	/* Clean up: */
	glMatrixMode(previousMatrixMode);
	}
예제 #10
0
void SubassemblyView::init ( void )
{
  setObjectName( subassembly_->name().toLatin1() );

  drawer_ = Space3D::OCSubassemblyDrawFactory::drawer( subassembly_, view() );

  modify_input_ = new SubassemblyModifyInput( this );

  dimensions_[0] = dimensions_[1] = dimensions_[2] = 0;

  dimension_name_ = view()->genSelectionName();

  ListViewItem* previous_item = parent()->previousItem( parent()->listViewItem(),
							 subassembly_->id() );

  list_view_item_ = new ListViewItem( parent()->listViewItem(), previous_item );

  list_view_item_->setData( lC::formatName( subassembly_->name() )
                + QString( " <%1>" ).arg( subassembly_->id() ),
                            lC::NAME );
  list_view_item_->setData( trC( subassembly_->type() ), lC::TYPE );
  list_view_item_->setData( tr( "Model: %1.%2 <%3>" ).
		    arg( lC::formatName( subassembly_->subassembly()->name()) ).
		    arg( trC( subassembly_->subassembly()->type() ) ).
            arg( lC::idToString( subassembly_->subassembly()->ID() ) ),
                            lC::DETAIL );
  //TODO
  //list_view_item_->listView()->ensureItemVisible( list_view_item_ );

  QListIterator<std::shared_ptr<AssemblyConstraint>> constraint =
    subassembly_->constraints().constraints();

  ListViewItem* constraint_item = 0;
  while ( constraint.hasNext() ) {
    constraint_item = new ListViewItem( list_view_item_, constraint_item );
    constraint_item->setData( trC( lC::STR::CONSTRAINT ), lC::NAME );
    constraint_item->setData( trC( constraint.peekNext()->type() ), lC::TYPE );
    constraint_item->setData( QVariant(), lC::DETAIL );

    updateChangedConstraint( 0, constraint.peekNext().get() );

    // Are there any offset constraints which need dimensions?
    if ( constraint.peekNext()->type() == lC::STR::MATE_OFFSET ||
     constraint.peekNext()->type() == lC::STR::ALIGN_OFFSET )
      updateChangedOffset( constraint.peekNext().get() );
    constraint.next();
  }

#if 0
  connect( subassembly_, SIGNAL( locationChanged() ), SLOT( updateLocation() ) );
  connect( subassembly_, SIGNAL( solidChanged() ), SLOT( updateTessellation() ) );
#else
  connect( subassembly_, SIGNAL( locationChanged() ), SLOT( updateTessellation() ) );
#endif
  connect( subassembly_, SIGNAL( materialChanged() ), SLOT( updateMaterial() ) );

  connect( subassembly_, SIGNAL( constraintCreated( const AssemblyConstraint*) ),
	   SLOT( updateNewConstraint( const AssemblyConstraint* ) ) );
  connect( subassembly_, SIGNAL( constraintChanged( const AssemblyConstraint*,
						    const AssemblyConstraint*) ),
	   SLOT( updateChangedConstraint( const AssemblyConstraint*,
					  const AssemblyConstraint* ) ) );
  connect( subassembly_, SIGNAL( constraintOffsetChanged( const AssemblyConstraint*) ),
	   SLOT( updateChangedOffset( const AssemblyConstraint* ) ) );

 connect( subassembly_, SIGNAL( constraintCanceled() ),
	   SLOT( updateCanceledConstraint() ) );

  connect( subassembly_->subassembly(), SIGNAL( nameChanged(const QString&) ),
	   SLOT( updateModelName( const QString& ) ) );

  connect( parent(), SIGNAL( orientationChanged( const GLdouble* ) ),
	   SLOT( updateViewNormal( const GLdouble* ) ) );

  if ( offset_info_dialog_ == 0 )
    offset_info_dialog_ = new OffsetInfoDialog( parent()->lCMW() );
}
예제 #11
0
void TexturedRectangle::Node::synchronize(const TexturedRectangle* item) {
  updateMaterial(item);
  updateGeometry(item);
}
예제 #12
0
/**
 * Change the material name
 * @note This function requires that the overlayElement has been set before
 */
void ExtraAction::changeMaterial(const Ogre::String &matName)
{
	ASSERT(mCont);
	updateMaterial(matName);
	enableAction();
}