Example #1
0
void HwMesh::readSub()
{
    DWORD tmp;
    char s[255];
    //name
    f->read((char *)&tmp, sizeof(DWORD));
    f->read((char *)s, tmp);
    f->seekg(1, ios::cur);
    s[tmp] = '\0';

    DWORD vCount, iCount;

    f->read((char *)&vCount, sizeof(DWORD)); //vertex Count
    f->read((char *)&iCount, sizeof(DWORD)); //index Count

    HwSurface *sub = newSurface(s);
    sub->aType = HWAT_NONE;
    sub->setSize(vCount, iCount);

    for (int i = 0; i < vCount; i++)
    {
        f->read((char *)&sub->vertices[i].pos, sizeof(D3DXVECTOR3));
        f->read((char *)&sub->vertices[i].normal, sizeof(D3DXVECTOR3));
        f->read((char *)&sub->vertices[i].tex, sizeof(D3DXVECTOR2));
    }

    for (int i = 0; i < iCount; i++)
        f->read((char *)&sub->indices[i], sizeof(DWORD));
}
Example #2
0
void ImageNode::setBitmap(BitmapPtr pBmp)
{
    if (m_pGPUImage->getSource() == GPUImage::SCENE && getState() == Node::NS_CANRENDER) {
        m_pGPUImage->getCanvas()->removeDependentCanvas(getCanvas());
    }
    m_pGPUImage->setBitmap(pBmp, m_Compression);
    if (getState() == Node::NS_CANRENDER) {
        newSurface();
    }
    m_href = "";
    setViewport(-32767, -32767, -32767, -32767);
}
Example #3
0
void ImageNode::checkReload()
{
    if (isCanvasURL(m_href)) {
        if (m_Compression != TEXCOMPRESSION_NONE) {
            throw Exception(AVG_ERR_UNSUPPORTED, 
                    "Texture compression can't be used with canvas hrefs.");
        }
        OffscreenCanvasPtr pCanvas = Player::get()->getCanvasFromURL(m_href);
        checkCanvasValid(pCanvas);
        m_pGPUImage->setCanvas(pCanvas);
        if (getState() == NS_CANRENDER) {
            pCanvas->addDependentCanvas(getCanvas());
        }
        newSurface();
    } else {
        bool bNewImage = Node::checkReload(m_href, m_pGPUImage, m_Compression);
        if (bNewImage) {
            newSurface();
        }
    }
    setViewport(-32767, -32767, -32767, -32767);
    RasterNode::checkReload();
}
Example #4
0
void RasterNode::connectDisplay()
{
    AreaNode::connectDisplay();

    if (m_MaxTileSize != IntPoint(-1, -1)) {
        m_TileSize = m_MaxTileSize;
    }
    newSurface();
    setBlendModeStr(m_sBlendMode);
    if (m_pMaskBmp) {
        downloadMask();
        setMaskCoords();
    }
    m_pSurface->setColorParams(m_Gamma, m_Intensity, m_Contrast);
    setupFX();
}
Example #5
0
void HwMesh::readAnimSub()
{
    DWORD tmp;
    char s[255];
    //name
    f->read((char *)&tmp, sizeof(DWORD));
    f->read((char *)s, tmp);
    f->seekg(1, ios::cur);
    s[tmp] = '\0';

    DWORD vCount, iCount;

    f->read((char *)&vCount, sizeof(DWORD)); //vertex Count
    f->read((char *)&iCount, sizeof(DWORD)); //index Count

    HwSurface *sub = newSurface(s);
    sub->aType = HWAT_SKELET;
    sub->setSize(vCount, iCount);

    for (int i = 0; i < vCount; i++)
    {
        f->read((char *)&sub->vertices[i].pos, sizeof(D3DXVECTOR3));
        f->read((char *)&sub->vertices[i].normal, sizeof(D3DXVECTOR3));
        f->read((char *)&sub->vertices[i].tex, sizeof(D3DXVECTOR2));

        f->read((char *)&tmp, sizeof(DWORD));
        sub->setBoneSize(i, tmp);
        for (int j = 0; j < tmp; j++)
        {
            DWORD tmp2;
            f->read((char *)&tmp2, sizeof(DWORD));
            sub->vertices[i].bones[j] = tmp2;
            float w;
            f->read((char *)&w, sizeof(float));
            sub->vertices[i].weights[j] = w;
        }
    }

    for (int i = 0; i < iCount; i++)
        f->read((char *)&sub->indices[i], sizeof(DWORD));

}
Example #6
0
SDL_Surface * CSDL_Ext::scaleSurfaceFast(SDL_Surface *surf, int width, int height)
{
	if (!surf || !width || !height)
		return nullptr;

	//Same size? return copy - this should more be faster
	if (width == surf->w && height == surf->h)
		return copySurface(surf);

	SDL_Surface *ret = newSurface(width, height, surf);

	switch(surf->format->BytesPerPixel)
	{
		case 1: scaleSurfaceFastInternal<1>(surf, ret); break;
		case 2: scaleSurfaceFastInternal<2>(surf, ret); break;
		case 3: scaleSurfaceFastInternal<3>(surf, ret); break;
		case 4: scaleSurfaceFastInternal<4>(surf, ret); break;
	}
	return ret;
}
Example #7
0
void Wing::compile()
{
    // Have we already been compiled?
    if(! _surfs.empty()) return;

    // Assemble the start/end coordinates of all control surfaces
    // and the wing itself into an array, sort them,
    // and remove duplicates.  This gives us the boundaries of our
    // segments.
    float bounds[10];
    bounds[0] = _flap0Start;   bounds[1] = _flap0End;
    bounds[2] = _flap1Start;   bounds[3] = _flap1End;
    bounds[4] = _spoilerStart; bounds[5] = _spoilerEnd;
    bounds[6] = _slatStart;    bounds[7] = _slatEnd;
    //and don't forget the root and the tip of the wing itself
    bounds[8] = 0;             bounds[9] = 1;

    // Sort in increasing order
    int i;
    for(i=0; i<10; i++) {
        int minIdx = i;
	float minVal = bounds[i];
        int j;
        for(j=i+1; j<10; j++) {
            if(bounds[j] < minVal) {
                minIdx = j;
		minVal = bounds[j];
	    }
	}
        float tmp = bounds[i];
        bounds[i] = minVal; bounds[minIdx] = tmp;
    }

    // Uniqify
    float last = bounds[0];
    int nbounds = 1;
    for(i=1; i<10; i++) {
        if(bounds[i] != last)
            bounds[nbounds++] = bounds[i];
        last = bounds[i];
    }

    // Calculate a "nominal" segment length equal to an average chord,
    // normalized to lie within 0-1 over the length of the wing.
    float segLen = _chord * (0.5f*(_taper+1)) / _length;

    // Generating a unit vector pointing out the left wing.
    float left[3];
    left[0] = -Math::tan(_sweep);
    left[1] = Math::cos(_dihedral);
    left[2] = Math::sin(_dihedral);
    Math::unit3(left, left);

    // Calculate coordinates for the root and tip of the wing
    float root[3], tip[3];
    Math::set3(_base, root);
    Math::set3(left, tip);
    Math::mul3(_length, tip, tip);
    Math::add3(root, tip, tip);

    // The wing's Y axis will be the "left" vector.  The Z axis will
    // be perpendicular to this and the local (!) X axis, because we
    // want motion along the local X axis to be zero AoA (i.e. in the
    // wing's XY plane) by definition.  Then the local X coordinate is
    // just Y cross Z.
    float orient[9], rightOrient[9];
    float *x = orient, *y = orient+3, *z = orient+6;
    x[0] = 1; x[1] = 0; x[2] = 0;
    Math::set3(left, y);
    Math::cross3(x, y, z);
    Math::unit3(z, z);
    Math::cross3(y, z, x);

    if(_mirror) {
	// Derive the right side orientation matrix from this one.
        int i;
        for(i=0; i<9; i++)  rightOrient[i] = orient[i];

	// Negate all Y coordinates, this gets us a valid basis, but
	// it's left handed!  So...
        for(i=1; i<9; i+=3) rightOrient[i] = -rightOrient[i];

	// Change the direction of the Y axis to get back to a
	// right-handed system.
	for(i=3; i<6; i++)  rightOrient[i] = -rightOrient[i];
    }

    // Now go through each boundary and make segments
    for(i=0; i<(nbounds-1); i++) {
        float start = bounds[i];
        float end = bounds[i+1];
        float mid = (start+end)/2;

        bool flap0=0, flap1=0, slat=0, spoiler=0;
        if(_flap0Start   < mid && mid < _flap0End)   flap0 = 1;
        if(_flap1Start   < mid && mid < _flap1End)   flap1 = 1;
        if(_slatStart    < mid && mid < _slatEnd)    slat = 1;
        if(_spoilerStart < mid && mid < _spoilerEnd) spoiler = 1;

        // FIXME: Should probably detect an error here if both flap0
        // and flap1 are set.  Right now flap1 overrides.

        int nSegs = (int)Math::ceil((end-start)/segLen);
        if (_twist != 0 && nSegs < 8) // more segments if twisted
            nSegs = 8;
        float segWid = _length * (end - start)/nSegs;

        int j;
        for(j=0; j<nSegs; j++) {
            float frac = start + (j+0.5f) * (end-start)/nSegs;
            float pos[3];
            interp(root, tip, frac, pos);

            float chord = _chord * (1 - (1-_taper)*frac);

            Surface *s = newSurface(pos, orient, chord,
                                    flap0, flap1, slat, spoiler);

            SurfRec *sr = new SurfRec();
            sr->surface = s;
            sr->weight = chord * segWid;
            s->setTotalDrag(sr->weight);
            s->setTwist(_twist * frac);
            _surfs.add(sr);

            if(_mirror) {
		pos[1] = -pos[1];
                s = newSurface(pos, rightOrient, chord,
                               flap0, flap1, slat, spoiler);
                sr = new SurfRec();
                sr->surface = s;
                sr->weight = chord * segWid;
                s->setTotalDrag(sr->weight);
                s->setTwist(_twist * frac);
                _surfs.add(sr);
            }
        }
    }

    // Last of all, re-set the incidence in case setIncidence() was
    // called before we were compiled.
    setIncidence(_incidence);
}
boost::optional<IdfObject> ForwardTranslator::translateDaylightingDeviceShelf( model::DaylightingDeviceShelf & modelObject )
{
  SubSurface window = modelObject.subSurface();
  boost::optional<Space> space = window.space();
  boost::optional<InteriorPartitionSurface> insideShelf = modelObject.insideShelf();
  boost::optional<ShadingSurface> outsideShelf = modelObject.outsideShelf();

  if (!space){
    return boost::none;
  }

  if (!(insideShelf || outsideShelf)){
    return boost::none;
  }

  IdfObject idfObject = createRegisterAndNameIdfObject(openstudio::IddObjectType::DaylightingDevice_Shelf, 
                                                       modelObject);

  idfObject.setString(DaylightingDevice_ShelfFields::WindowName, window.name().get());


  // inside shelf is converted to a surface
  if (insideShelf){

    openstudio::Transformation transformation;
    boost::optional<InteriorPartitionSurfaceGroup> group = insideShelf->interiorPartitionSurfaceGroup();
    if (group){
      transformation = group->transformation();
    }

    Point3dVector vertices = transformation*insideShelf->vertices();
    Surface newSurface(vertices, modelObject.model());
    newSurface.setName(modelObject.name().get());
    newSurface.setSpace(*space);
    newSurface.setAdjacentSurface(newSurface);

    boost::optional<ConstructionBase> construction = insideShelf->construction();
    if (!construction){
      Model t_model = modelObject.model();
      construction = interiorPartitionSurfaceConstruction(t_model);
    }
    OS_ASSERT(construction);
    newSurface.setConstruction(*construction);
    
    boost::optional<IdfObject> newSurfaceObject = translateAndMapModelObject(newSurface);
    if (newSurfaceObject){
      idfObject.setString(DaylightingDevice_ShelfFields::InsideShelfName, newSurfaceObject->name().get());
    }
  }

  if (outsideShelf){

    idfObject.setString(DaylightingDevice_ShelfFields::OutsideShelfName, outsideShelf->name().get());
    
    boost::optional<ConstructionBase> construction = outsideShelf->construction();
    if (!construction){
      Model t_model = modelObject.model();
      construction = exteriorSurfaceConstruction(t_model);
    }
    OS_ASSERT(construction);
    idfObject.setString(DaylightingDevice_ShelfFields::OutsideShelfConstructionName, construction->name().get());

    OptionalDouble d = modelObject.viewFactortoOutsideShelf();
    if (d){
      idfObject.setDouble(DaylightingDevice_ShelfFields::ViewFactortoOutsideShelf, *d);
    }
  }

  return idfObject;
}