// draw passes the transformation and reflectivity data to the hardware
//
void SubdividedGraphic::draw(const iObject* object, int i) {

    // if SubdividedGraphic doesn't exist, set it up first
    if (!isSetup) setup(object);

    if (isSetup) {
		#if   PIPELINE == FIXED_FUNCTION
		#elif PIPELINE == PROGRAMMABLE || PIPELINE == PROGRAMMABLE_EFFECT
		Display* disp = reinterpret_cast<Display*>(display);
		Matrix worldView = object->world() * disp->viewMatrix();
		Matrix worldViewProjection = worldView * disp->projectionMatrix();
		#endif
        #if   PIPELINE == FIXED_FUNCTION
        d3dd->SetTransform(D3DTS_WORLD, (D3DXMATRIX*)(&object->world()));
        d3dd->SetMaterial(&mat[i]);
        if (!strcmp(technique, "opaque") || !strcmp(technique, "skybox"))
            d3dd->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
        else if (!strcmp(technique, "translucent"))
            d3dd->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
        getVertexList()->draw(i);
        #elif PIPELINE == PROGRAMMABLE
        LPD3DXCONSTANTTABLE vertexTable = (LPD3DXCONSTANTTABLE)uniformVS;
        LPD3DXCONSTANTTABLE fragmentTable = (LPD3DXCONSTANTTABLE)uniformFS;
        vertexTable->SetMatrix(d3dd, "world", (D3DXMATRIX*)&object->world());
        fragmentTable->SetFloatArray(d3dd, "material.ambient", (FLOAT*)&ambient[i], 4);
        fragmentTable->SetFloatArray(d3dd, "material.diffuse", (FLOAT*)&diffuse[i], 4);
        fragmentTable->SetFloatArray(d3dd, "material.specular", (FLOAT*)&specular[i], 4); 
        fragmentTable->SetFloat(d3dd, "material.power", (FLOAT)power[i]);
        if (!strcmp(technique, "opaque") || !strcmp(technique, "skybox"))
            d3dd->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
        else if (!strcmp(technique, "translucent"))
            d3dd->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
        #elif PIPELINE == PROGRAMMABLE_EFFECT
        effect->SetInt(stagesHandle,      nStages);
        effect->SetMatrix(worldHandle,    (D3DXMATRIX*)&object->world());
        effect->SetVector(ambientHandle,  (D3DXVECTOR4*)&ambient[i]);
        effect->SetVector(diffuseHandle,  (D3DXVECTOR4*)&diffuse[i]);
        effect->SetVector(specularHandle, (D3DXVECTOR4*)&specular[i]);
        effect->SetFloat(powerHandle,     power);
		effect->SetFloat(roughnessHandle, object->getRoughness());
		effect->SetFloat(refractionHandle,object->getIndexOfRefraction());
		effect->SetInt(algorithmHandle,   object->getAlgorithm());
		effect->SetMatrix(worldViewHandle, (D3DXMATRIX*)&worldView);
		effect->SetMatrix(clipMatrixHandle, (D3DXMATRIX*)&worldViewProjection);
        effect->CommitChanges();
        effect->SetTechnique(techniqueHandle);
        unsigned nPasses;
        effect->Begin(&nPasses, 0);
        for (unsigned iPass = 0; iPass < nPasses; iPass++) {
            effect->BeginPass(iPass);
            getVertexList()->draw(i);
            effect->EndPass();
        }
        effect->End();
        #endif
    }
}
	void TerrainInstance::buildAABB() {
		list<Vertex *> vertices=getVertexList();
		aabb.reset();
		for (list<Vertex *>::iterator it=vertices.begin(); it!=vertices.end(); it++) {
			aabb.addPoint((*it)->getTPosition(matrix));
		}
		aabb.expand(LIBGENS_TERRAIN_INSTANCE_AABB_EXPANSION);
	}
示例#3
0
bool SquareObstacle::isInArea(const Obstacle& obstacle) const
{
    bool in_area_flag = false;
    std::vector<Geo::Point> vertex_list = getVertexList();

    for(unsigned int i = 0; i < vertex_list.size(); i++)
        in_area_flag |= obstacle.isInArea(vertex_list.at(i));

    return in_area_flag;
}
示例#4
0
std::vector<Geo::Line> SquareObstacle::getEdgeList() const
{
    std::vector<Geo::Line> edge_list;
    std::vector<Geo::Point> vertex_list = getVertexList();

    for(unsigned int i = 0; i < vertex_list.size(); i++)
    {
        Geo::Point s = vertex_list.at(i);
        Geo::Point e = vertex_list.at((i + 1) % vertex_list.size());

        edge_list.push_back(Geo::Line(s, e));
    }

    return edge_list;
}
// setup retrieves the material reflectivity and populates the instance arrays
//
void SubdividedGraphic::setup(const iObject* object) {

    d3dd = (LPDIRECT3DDEVICE9)device;
	float a = object->ambient();

	// make a shiny material of the specified color
    for (int i = 0; i < nSubsets; i++) {
        Colour c = object->diffuse(i);
		Colour spec = object->specular(i);

        #if   PIPELINE == FIXED_FUNCTION
        ZeroMemory(&mat[i], sizeof(mat[i]));
        mat[i].Ambient  = D3DXCOLOR(c.r*0.7f, c.g*0.7f, c.b*0.7f, c.a);
        mat[i].Diffuse  = D3DXCOLOR(c.r, c.g, c.b, c.a); // reflected from lights
        mat[i].Specular = D3DXCOLOR(1, 1, 1, c.a);       // shine from lights
        mat[i].Power    = object->power(i); // 0 if it shouldn't be shiny
        #elif PIPELINE == PROGRAMMABLE
        ambient[i]  = D3DXCOLOR(c.r*0.7f, c.g*0.7f, c.b*0.7f, c.a);
        diffuse[i]  = D3DXCOLOR(c.r, c.g, c.b, c.a); // reflected from lights
        specular[i] = D3DXCOLOR(1, 1, 1, c.a);       // shine from lights
        power[i]    = object->power(i); // 0 if it shouldn't be shiny
        #elif PIPELINE == PROGRAMMABLE_EFFECT
        ambient[i]  = D3DXCOLOR(c.r*a, c.g*a, c.b*a, c.a);
        diffuse[i]  = D3DXCOLOR(c.r, c.g, c.b, c.a); // reflected from lights
		specular[i] = D3DXCOLOR(spec.r, spec.g, spec.b, c.a);       // shine from lights
        power       = object->power(); // 0 if it shouldn't be shiny
        // initialize handles to effect uniform variables
        effect				= (LPD3DXEFFECT)effect_;
        techniqueHandle		= effect->GetTechniqueByName(techniqueName());
        stagesHandle		= effect->GetParameterByName(0, "nStages");
        worldHandle			= effect->GetParameterByName(0, "world");
        ambientHandle		= effect->GetParameterByName(0, "material.ambient");
        diffuseHandle		= effect->GetParameterByName(0, "material.diffuse");
        specularHandle		= effect->GetParameterByName(0, "material.specular");
        powerHandle			= effect->GetParameterByName(0, "material.power");
		roughnessHandle		= effect->GetParameterByName(0, "roughness_value");
		refractionHandle	= effect->GetParameterByName(0, "refractionIndex");
		algorithmHandle		= effect->GetParameterByName(0, "algorithm");
		clipMatrixHandle	= effect->GetParameterByName(0, "clipMatrix");
		worldViewHandle		= effect->GetParameterByName(0, "worldView");
        #endif
    }

    getVertexList()->setup();
    isSetup = true;
}
// release suspends the graphi
//
void SubdividedGraphic::release() {

    suspend();
    getVertexList()->release();
}
// suspend initializes for setup
//
void SubdividedGraphic::suspend() {

    getVertexList()->suspend();
    isSetup = false;
}