예제 #1
0
QShadowDataModel::QShadowDataModel(QAbstractItemModel *src_mdl, int target_col, int shadow_col, QObject *parent) :
  qMirrorModel(src_mdl, parent),
  targetColumn(target_col),
  shadowColumn(shadow_col)
{
  makeShadow();
}
예제 #2
0
void
ShadowMgr::init( void )
{
	StringList shadow_list;
	StringList checked_shadow_list;
	Shadow* tmp_shadow;
	shadows.Rewind();
	while( shadows.Next(tmp_shadow) ) {
		delete( tmp_shadow );
		shadows.DeleteCurrent();
	}

	char *tmp, *shadow_path;
	tmp = param( "SHADOW_LIST" );
	if( ! tmp ) {
			// Not defined, give them a default
		tmp = strdup( "SHADOW, SHADOW_STANDARD" );
		dprintf(D_ALWAYS,
				"WARNING: SHADOW_LIST not defined in config file, "
				"using default: %s\n", tmp);
	}
	shadow_list.initializeFromString( tmp );
	free( tmp );

	shadow_list.rewind();
	while( (tmp = shadow_list.next()) ) {
		shadow_path = param( tmp );
		if( ! shadow_path ) {
			dprintf( D_ALWAYS, "Shadow specified in SHADOW_LIST "
					 "\"%s\" not found in config file, ignoring.\n",
					 tmp ); 
			continue;
		}
		if( checked_shadow_list.contains(shadow_path) ) {
			dprintf( D_ALWAYS, "Shadow pointed to by \"%s\" (%s) is "
					 "in SHADOW_LIST more than once, ignoring.\n", 
					 tmp, shadow_path );
			free( shadow_path );
			continue;
		}
		
			// now, we've got a path to a binary we want to use as a
			// shadow.  try to run it with a -classad option and grab
			// the output (which should be a classad), and construct
			// the appropriate Shadow object for it.
		tmp_shadow = makeShadow( shadow_path );
		if( tmp_shadow ) {
			shadows.Append( tmp_shadow );
		}
			// record the fact that we've already considered this
			// shadow, even if it failed to give us a classad. 
		checked_shadow_list.append( shadow_path );
		free( shadow_path );
	}
}
예제 #3
0
/** \brief The constructor.
 *
 *  Loads an airplane model from an xml description. The 3D model
 *  will be added to the specified scenegraph.
 *
 *  \param  xml   XML model description file
 *  \param  graph Pointer to the scenegraph which shall render the model
 */
CRRCAirplaneLaRCSimSSG::CRRCAirplaneLaRCSimSSG(SimpleXMLTransfer* xml, ssgBranch *graph)
  : CRRCAirplaneLaRCSim(xml), initial_trans(NULL), 
    model_trans(NULL), model(NULL),
    shadow(NULL), shadow_trans(NULL)
{
  printf("CRRCAirplaneLaRCSimSSG(xml, branch)\n");
  
  std::string s;      
  s = XMLModelFile::getGraphics(xml)->getString("model");
        
  // plib automatically loads the texture file, but it does not know which directory to use.
  {
    // where is the object file?
    std::string    of  = FileSysTools::getDataPath("objects/" + s);
    // compile and set relative texture path
    std::string    tp  = of.substr(0, of.length()-s.length()-1-7) + "textures";    
    ssgTexturePath(tp.c_str());
    // load model
    model = ssgLoad(of.c_str());
  }

  if (model != NULL)
  {
    // Offset of center of gravity
    CRRCMath::Vector3  pCG;         
    pCG = CRRCMath::Vector3(0, 0, 0);
    if (xml->indexOfChild("CG") >= 0)
    {
      SimpleXMLTransfer* i;
      i = xml->getChild("CG");
      pCG.r[0] = i->attributeAsDouble("x", 0);
      pCG.r[1] = i->attributeAsDouble("y", 0);
      pCG.r[2] = i->attributeAsDouble("z", 0);
      
      if (i->attributeAsInt("units") == 1)
        pCG *= M_TO_FT;
    }
    
    // transform model from SSG coordinates to CRRCsim coordinates
    initial_trans = new ssgTransform();
    model_trans = new ssgTransform();
    graph->addKid(model_trans);
    model_trans->addKid(initial_trans);
    initial_trans->addKid(model);
    
    sgMat4 it = {  {1.0,  0.0,  0.0,  0},
                   {0.0,  0.0, -1.0,  0},
                   {0.0,  1.0,  0.0,  0},
                   {pCG.r[1],  pCG.r[2],  -pCG.r[0],  1.0} };
    
    initial_trans->setTransform(it);

    // add a simple shadow
    shadow = (ssgEntity*)initial_trans->clone(SSG_CLONE_RECURSIVE | SSG_CLONE_GEOMETRY | SSG_CLONE_STATE);
    makeShadow(shadow);
    shadow_trans = new ssgTransform();
    graph->addKid(shadow_trans);
    shadow_trans->addKid(shadow);
    
    // add animations ("real" model only, without shadow)
    initAnimations(xml, model, &Global::inputs, animations);
  }
  else
  {
    std::string msg = "Unable to open airplane model file \"";
    msg += s;
    msg += "\"\nspecified in \"";
    msg += xml->getSourceDescr();
    msg += "\"";

    throw std::runtime_error(msg);
  }

}
예제 #4
0
/** \brief Create a "shadow" instance of a model
 *
 *  This function operates on a clone of a model and sets all associated
 *  states to a "shadowy" look. If it is called for an entity that has the
 *  "-shadow" attribute set, return true to signal the caller that he has to
 *  remove this entity from the graph.
 *  
 *  \todo If the video context supports stencil buffering, the shadow
 *        should be rendered using the stencil buffer to get a translucent look.
 *
 *  \param ent  A clone of the "real" model
 *  \retval true The current entity has to be removed from the graph
 *  \retval false No action required
 */
bool makeShadow(ssgEntity *ent)
{
  bool boRemoveCurrentEntity = false;
  
  if (ent->isAKindOf(ssgTypeLeaf()))
  {
    ssgLeaf *leaf = (ssgLeaf*)ent;

    SSGUtil::NodeAttributes attr = SSGUtil::getNodeAttributes(leaf);
    if (!attr.castsShadow)
    {
      // no shadow --> remove this entity from all parents
      boRemoveCurrentEntity = true;
    }
    else if (leaf->hasState())
    {
      ssgSimpleState *state = (ssgSimpleState*)leaf->getState();
      state->disable(GL_COLOR_MATERIAL);
      state->disable(GL_TEXTURE_2D);
      state->enable(GL_LIGHTING);
      state->enable(GL_BLEND);
      state->setShadeModel(GL_SMOOTH);
      state->setShininess(0.0f);
      state->setMaterial(GL_EMISSION, 0.0, 0.0, 0.0, 0.0);
      
      #ifdef EXPERIMENTAL_STENCIL_SHADOW
      if (vidbits.stencil)
      {
        state->setMaterial(GL_AMBIENT, 0.0, 0.0, 0.0, 0.1);
        state->setMaterial(GL_DIFFUSE, 0.0, 0.0, 0.0, 0.1);
        state->setMaterial(GL_SPECULAR, 0.0, 0.0, 0.0, 0.1);
        state->setStateCallback(SSG_CALLBACK_PREDRAW, shadowPredrawCallback);
        state->setStateCallback(SSG_CALLBACK_POSTDRAW, shadowPostdrawCallback);
      }
      else
      #endif
      {
        state->setMaterial(GL_AMBIENT, 0.0, 0.0, 0.0, 1.0);
        state->setMaterial(GL_DIFFUSE, 0.0, 0.0, 0.0, 1.0);
        state->setMaterial(GL_SPECULAR, 0.0, 0.0, 0.0, 1.0);
        state->setStateCallback(SSG_CALLBACK_PREDRAW, NULL);
        state->setStateCallback(SSG_CALLBACK_POSTDRAW, NULL);
      }
    }
  }
  else if (ent->isAKindOf(ssgTypeBranch()))
  {
    ssgBranch *branch = (ssgBranch*)ent;

    // continue down the hierarchy
    std::list<ssgLeaf*> ToBeRemoved;
    std::list<ssgLeaf*>::iterator it;
    int kids = branch->getNumKids();
    for (int i = 0; i < kids; i++)
    {
      ssgEntity* currKid = branch->getKid(i);
      if (makeShadow(currKid))
      {
        ToBeRemoved.push_back(static_cast<ssgLeaf*>(currKid));
      }
    }
    for (it = ToBeRemoved.begin(); it != ToBeRemoved.end(); it++)
    {
      SSGUtil::removeLeafFromGraph(*it);
    }
    

  }
  return boRemoveCurrentEntity;
}
예제 #5
0
void QShadowDataModel::recreate()
{
  qMirrorModel::recreate();
  makeShadow();
}