void Entity::RenderShadow( Vector3 const &_pos, double _size )
{
    Vector3 shadowPos = _pos;
    Vector3 shadowR = Vector3(_size,0,0);
    Vector3 shadowU = Vector3(0,0,_size);
        
    Vector3 posA = shadowPos - shadowR - shadowU;
    Vector3 posB = shadowPos + shadowR - shadowU;
    Vector3 posC = shadowPos + shadowR + shadowU;
    Vector3 posD = shadowPos - shadowR + shadowU;

    posA.y = g_app->m_location->m_landscape.m_heightMap->GetValue( posA.x, posA.z ) + 0.9;
    posB.y = g_app->m_location->m_landscape.m_heightMap->GetValue( posB.x, posB.z ) + 0.9;
    posC.y = g_app->m_location->m_landscape.m_heightMap->GetValue( posC.x, posC.z ) + 0.9;
    posD.y = g_app->m_location->m_landscape.m_heightMap->GetValue( posD.x, posD.z ) + 0.9;
    
    posA.y = max( posA.y, 1.0 );
    posB.y = max( posB.y, 1.0 );
    posC.y = max( posC.y, 1.0 );
    posD.y = max( posD.y, 1.0 );

    if( posA.y > _pos.y && posB.y > _pos.y && posC.y > _pos.y && posD.y > _pos.y )
    {
        // The object casting the shadow is beneath the ground
        return;
    }

    glBegin( GL_QUADS );
        glTexCoord2f( 0.0, 0.0 );     glVertex3dv     ( posA.GetData() );
        glTexCoord2f( 1.0, 0.0 );     glVertex3dv     ( posB.GetData() );
        glTexCoord2f( 1.0, 1.0 );     glVertex3dv     ( posC.GetData() );
        glTexCoord2f( 0.0, 1.0 );     glVertex3dv     ( posD.GetData() );
    glEnd();
}
void DrawTriPlane(Vector3 &t1, Vector3 &t2, Vector3 &t3)
{
	float planeSize = 4.0f;
	Vector3 triCentre = (t1 + t2 + t3) / 3.0f;
	Vector3 dir1 = (t2 - t1).Normalise();
	Vector3 dir2 = (t3 - t2).Normalise();
	Vector3 planeNorm = dir1 ^ dir2;
	dir1 = (dir2 ^ planeNorm).Normalise();
	triCentre -= dir1 * 0.5f * planeSize;
	triCentre -= dir2 * 0.5f * planeSize;

	glDisable(GL_CULL_FACE);
	glEnable(GL_BLEND);
	glColor4ub(255,128,128, 80);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glBegin(GL_QUADS);
		glVertex3fv(triCentre.GetData());
		glVertex3fv((triCentre + dir1 * planeSize).GetData());
		glVertex3fv((triCentre + dir1 * planeSize + dir2 * planeSize).GetData());
		glVertex3fv((triCentre + dir2 * planeSize).GetData());
	glEnd();
	glDisable(GL_BLEND);
	
	glColor3ub(255,128,128);
	glLineWidth(1.0f);
	glBegin(GL_LINE_LOOP);
		glVertex3fv(t1.GetData());
		glVertex3fv(t2.GetData());
		glVertex3fv(t3.GetData());
	glEnd();
}
void DrawLine(Vector3 &start, Vector3 &end)
{
	DrawPoint(start);
	DrawPoint(end);
	glBegin(GL_LINES);
		glVertex3fv(start.GetData());
		glVertex3fv(end.GetData());
	glEnd();
}
void Bridge::RenderAlphas ( double predictionTime )
{
    //
    // Render our signal

    if( m_nextBridgeId != -1 )
    {
        Building *building = g_app->m_location->GetBuilding( m_nextBridgeId );
        if( building && building->m_type == Building::TypeBridge )
        {
            Bridge *bridge = (Bridge *) building;
            if( m_status > 0.0 && bridge->m_status > 0.0 )
            {
                Vector3 ourPos = GetStartPoint();
                Vector3 theirPos = bridge->GetStartPoint();                
            
		        if( m_id.GetTeamId() == 255 )
		        {
			        glColor4f( 0.5, 0.5, 0.5, m_status / 100.0 );
		        }
		        else
		        {
                    RGBAColour col = g_app->m_location->m_teams[ m_id.GetTeamId() ]->m_colour;
			        glColor4ub( col.r, col.g, col.b, (unsigned char)(255.0 * m_status / 100.0) );
		        }

                glLineWidth ( 3.0 );
                glEnable    ( GL_BLEND );
                glEnable    ( GL_LINE_SMOOTH );
                glBegin( GL_LINES );
                    glVertex3dv( ourPos.GetData() );
                    glVertex3dv( theirPos.GetData() );
                glEnd();
                glDisable   ( GL_LINE_SMOOTH );
                glDisable   ( GL_BLEND );
            }
        }
    }


    Teleport::RenderAlphas(predictionTime);
}
void SafeArea::Render( double predictionTime )
{
    if( g_app->m_editing )
    {
        RGBAColour colour;

        if( m_id.GetTeamId() != 255 )
        {
            colour = g_app->m_location->m_teams[ m_id.GetTeamId() ]->m_colour;    
        }
        colour.a = 255;

#ifdef DEBUG_RENDER_ENABLED
        RenderSphere( m_pos, 20.0, colour );
#endif
        int numSteps = 30;
        double angle = 0.0;

        glColor4ubv(colour.GetData() );
        glLineWidth( 2.0 );
        glBegin( GL_LINE_LOOP );
        for( int i = 0; i <= numSteps; ++i )
        {
            double xDiff = m_size * iv_sin(angle);
            double zDiff = m_size * iv_cos(angle);
            Vector3 pos = m_pos + Vector3(xDiff,5,zDiff);
	        pos.y = g_app->m_location->m_landscape.m_heightMap->GetValue(pos.x, pos.z) + 10.0;
            if( pos.y < 2 ) pos.y = 2;
            glVertex3dv( pos.GetData() );
            angle += 2.0 * M_PI / (double) numSteps;
        }
        glEnd();
    }
    else
    {
/*
        double angle = g_gameTime * 2.0;
        Vector3 dif( m_size * iv_sin(angle), 0.0, m_size * iv_cos(angle) );
        
        Vector3 pos = m_pos + dif;
        pos.y = g_app->m_location->m_landscape.m_heightMap->GetValue( pos.x, pos.z ) + 5.0;
        g_app->m_particleSystem->CreateParticle( pos, g_upVector*2 + dif/30, Particle::TypeMuzzleFlash, 100.0 );

        pos = m_pos - dif;
        pos.y = g_app->m_location->m_landscape.m_heightMap->GetValue( pos.x, pos.z ) + 5.0;
        g_app->m_particleSystem->CreateParticle( pos, g_upVector*2 - dif/30, Particle::TypeMuzzleFlash, 100.0 );
*/
    }
    

    //char *entityTypeRequired = Entity::GetTypeName( m_entityTypeRequired );
    //g_editorFont.DrawText3DCentre( m_pos + Vector3(0,m_size/2,0), 10.0, "%d / %d %ss", m_entitiesCounted, m_entitiesRequired, entityTypeRequired );
}
void DrawPoint(Vector3 &pos)
{
	Matrix34 planeMat;
	GetPlaneMatrix(Vector3(0,0,0), Vector3(1,0,0), Vector3(0,0,1), &planeMat);
	Vector3 posOnPlane;
	ProjectPointOntoPlane(pos, planeMat, &posOnPlane);

	glColor3ub(255,255,255);
	glPointSize(2.0f);
	glBegin(GL_POINTS);
		glVertex3fv(pos.GetData());
	glEnd();
	glColor3ub(128,128,128);
	glBegin(GL_POINTS);
		glVertex3fv(posOnPlane.GetData());
	glEnd();

	glColor3ub(128,128,128);
	glLineWidth(1.0f);
	glBegin(GL_LINES);
		glVertex3fv(pos.GetData());
		glVertex3fv(posOnPlane.GetData());
	glEnd();		
}
void LocationEditor::RenderUnit(InstantUnit *_iu)
{
	char *typeName = Entity::GetTypeName(_iu->m_type);
	
	float landHeight = g_app->m_location->m_landscape.m_heightMap->GetValue(_iu->m_posX, _iu->m_posZ);
	glColor4f( 1.0, 1.0, 1.0, 1.0 );
    g_editorFont.DrawText3DCentre(Vector3(_iu->m_posX, landHeight + 15.0, _iu->m_posZ),
								  15.0, "%d %s(s)", _iu->m_number, typeName);


	// Render troops
	int maxX = (int)iv_sqrt(_iu->m_number);
	int maxZ = _iu->m_number / maxX;
	float pitch = 10.0;
	float offsetX = -maxX * pitch * 0.5;
	float offsetZ = -maxZ * pitch * 0.5;
	RGBAColour colour;
    if( _iu->m_teamId >= 0 ) colour = g_app->m_location->m_teams[_iu->m_teamId]->m_colour;
	colour.a = 200;
    glColor4ubv(colour.GetData());
    
    Vector3 camUp = g_app->m_camera->GetUp() * 5.0;
    Vector3 camRight = g_app->m_camera->GetRight() * 5.0;

    glDisable   (GL_CULL_FACE );
    glEnable    (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE);
    glDepthMask (false);
	glBegin     (GL_QUADS);
    
    //
    // Render dots for the number and team of the unit

	for (int x = 0; x < maxX; ++x)
	{
		for (int z = 0; z < maxZ; ++z)
		{
			Vector3 pos(_iu->m_posX + offsetX + x * pitch, 0,
						_iu->m_posZ + offsetZ + z * pitch);
			pos.y = g_app->m_location->m_landscape.m_heightMap->GetValue(pos.x, pos.z) + 2.0;
			glVertex3dv( (pos - camUp - camRight).GetData() );
            glVertex3dv( (pos - camUp + camRight).GetData() );
            glVertex3dv( (pos + camUp + camRight).GetData() );
            glVertex3dv( (pos + camUp - camRight).GetData() );
		}
	}

    glEnd();


    //
    // Render our spread circle

    if( m_mode == ModeInstantUnit )
    {
        int numSteps = 30;
        float angle = 0.0;

        colour.a = 100;
        glColor4ubv(colour.GetData() );
        glLineWidth( 2.0 );
        glBegin( GL_LINE_LOOP );
        for( int i = 0; i <= numSteps; ++i )
        {
            float xDiff = _iu->m_spread * iv_sin(angle);
            float zDiff = _iu->m_spread * iv_cos(angle);
            Vector3 pos = Vector3(_iu->m_posX, 0.0, _iu->m_posZ) + Vector3(xDiff,5,zDiff);
	        pos.y = g_app->m_location->m_landscape.m_heightMap->GetValue(pos.x, pos.z) + 10.0;
            if( pos.y < 2 ) pos.y = 2;
            glVertex3dv( pos.GetData() );
            angle += 2.0 * M_PI / (float) numSteps;
        }
        glEnd();
    }
    

    glDisable   (GL_BLEND);
    glDepthMask (true);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable    (GL_CULL_FACE );

}
Exemplo n.º 8
0
    void Renderer::Render(const Camera& cam, IContext& c){
#if ZEUS_SAFE
        if (c.GetType() != IContext::OpenGL21) throw Exception("Context not supported by renderer: " + Utils::ToString<IContext::Type>(c.GetType()));
#endif
        Context& glContext = (Context&)c;

        // Draw scene
        ApplyCamera(cam, c);

        glEnable(GL_CULL_FACE);

        // @TODO Setup light. Lightmaps 'n shit
        glEnable(GL_COLOR_MATERIAL);
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
        Vector3 dir = Vector3(1,3,2);
        Normalize(dir);
        float hat[4]; dir.GetData(hat); hat[3] = 1.0f;
        glLightfv(GL_LIGHT0, GL_POSITION, hat);


        SceneObjectList::iterator itr = SceneObjectList::Begin();
        while (itr != SceneObjectList::End()){
            //Debug::Log("Rendering " + (*itr)->GetName());
            
            const ModelComponent* m = (*itr)->GetComponent<ModelComponent>();
            if (m){
                //Debug::Log((*itr)->GetName() + " has mesh");
                const ModelPropertiesPtr props = m->GetModelProperties();
                if (props) {
                    ModelProperties::Texture2DIterator itr = props->Texture2DBegin();
                    while (itr != props->Texture2DEnd()) {
                        const GLTexture2D* tex = glContext.AddTexture(itr->second);
                        glBindTexture(GL_TEXTURE_2D, tex->GetID());
                        glEnable(GL_TEXTURE_2D);
                        ++itr;
                    }
                } else {
                    glBindTexture(GL_TEXTURE_2D, 0);
                    glDisable(GL_TEXTURE_2D);
                }

                const MeshPtr mesh = m->GetMesh();
                if (mesh) {
                    const Transformation* t = (*itr)->GetComponent<Transformation>();
                    glPushMatrix();
                    Matrix4x4 m = t->GetAccumulatedMatrix();
                    glMultMatrixf(m.GetData());
                    
                    // @TODO Apply material

                    const GLMesh* mInfo = glContext.AddMesh(mesh);
                    RenderModel(*mInfo, glContext);
                    
                    glPopMatrix();
                }
            }
            ++itr;
        }

        glDisable(GL_COLOR_MATERIAL);
        glDisable(GL_LIGHTING);
        glDisable(GL_LIGHT0);

        glDisable(GL_CULL_FACE);
    }
void AIObjectiveMarker::RenderAlphas( double _predictionTime )
{
    bool objectiveActive = m_objectiveId == -1 || ((AIObjective *)g_app->m_location->GetBuilding( m_objectiveId ))->m_active;
    bool render = (!g_app->m_editing && g_prefsManager->GetInt( "RenderAIInfo", 0 ) != 0 && objectiveActive );
    if( g_app->m_editing || render)
    {
#ifdef LOCATION_EDITOR
        Building::RenderAlphas( _predictionTime );
        RGBAColour col;
        if( g_app->m_editing )
        {
            col.Set( 255, 0, 0 );
        }
        else if( m_id.GetTeamId() == 255 )
        {
            col.Set( 150, 150, 150 );
        }
        else
        {
            if( m_objectiveBuildingId != -1 &&
                fabs(sin(g_gameTime)) < 0.5)
            {
                col = RGBAColour(255, 255, 255, 255);
            }
            else
            {
                col = g_app->m_location->m_teams[ m_id.GetTeamId() ]->m_colour;
            }
        }
        RenderSphere( m_pos, 25.0, col );

        Building *b = g_app->m_location->GetBuilding( m_objectiveBuildingId );
        if( b )
        {
            RenderArrow( m_pos, b->m_pos, 5.0, col );
        }

        if( g_app->m_editing &&
            g_app->m_locationEditor->m_mode == LocationEditor::ModeBuilding &&
            g_app->m_locationEditor->m_selectionId == m_id.GetUniqueId() )
        {
            RenderSphere( m_pos, 30.0, RGBAColour( 255, 0, 0 ) );

            Vector3 triggerPos = m_pos;
            int numSteps = 20;
            glBegin( GL_LINE_LOOP );
            glLineWidth( 1.0 );
            glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
            for( int i = 0; i < numSteps; ++i )
            {
                float angle = 2.0f * M_PI * (float)i / (float) numSteps;
                Vector3 thisPos = triggerPos + Vector3( sinf(angle)*m_scanRange, 0.0f,
                                                        cosf(angle)*m_scanRange );
                thisPos.y = g_app->m_location->m_landscape.m_heightMap->GetValue( thisPos.x, thisPos.z );
                thisPos.y += 10.0f;
                glVertex3dv( thisPos.GetData() );
            }
            glEnd();
        }
#endif
    }
}