Ejemplo n.º 1
0
void ComponentDrawFlare::draw (CameraObject* camera)
{
    PlaceableObject *placeable = checkedCast<PlaceableObject*>(getOwner());
    if (!placeable)
        return;
        
	for (DTuint i = 0; i < NUM_FLARES; ++i) {
		if (_mat[i].isNull())
			continue;
	
		Color c = _mat[i]->getColor();
		c.setAFloat(_alpha);
		_mat[i]->setColor(c);
    }
    
	Vector3 projected_point = camera->projectPoint (placeable->getTranslation());
    if (projected_point.z > 1.0F)
        return;
        
	Vector3 flare_vec = (Vector3(0.0F, 0.0F, 0.0F) - projected_point) * 2.0F;
    
	DTfloat aspect = System::getRenderer()->getViewportAspect();
    
	DrawBatcherQuads b;
	
	for (DTuint i = 0; i < NUM_FLARES; ++i) {
		if (_mat[i].isNull())
			continue;
		
		DTfloat size = _size[i];
		
		Matrix4 transform = Matrix4::identity();
        transform.setTranslation(projected_point + flare_vec * _pos[i]);	// TODO: Why is this backwards?

		b.batchBegin (_mat[i].get(), Matrix4::identity(), DrawBatcherQuads::FMT_V | DrawBatcherQuads::FMT_T1 | DrawBatcherQuads::FMT_C);
		b.vertex ( transform * Vector3(-size,-size*aspect,0.0F), Texcoord2(0.0F,0.0F), Color(_alpha,_alpha,_alpha,_alpha) );
		b.vertex ( transform * Vector3(size,-size*aspect,0.0F), Texcoord2(1.0F,0.0F), Color(_alpha,_alpha,_alpha,_alpha) );
		b.vertex ( transform * Vector3(size,size*aspect,0.0F), Texcoord2(1.0F,1.0F), Color(_alpha,_alpha,_alpha,_alpha) );
		b.vertex ( transform * Vector3(-size,size*aspect,0.0F), Texcoord2(0.0F,1.0F), Color(_alpha,_alpha,_alpha,_alpha) );
		b.batchEnd();
	}
	
	b.flush();
    
}
Ejemplo n.º 2
0
void EdManipGUIObject::drawCube (MaterialResource *mat, Matrix4 transform)
{
    DrawBatcherQuads b;
    b.batchBegin(mat, transform, DrawBatcher::FMT_V);
    
    b.vertex( Vector3(-1.0F,1.0F,-1.0F) );
    b.vertex( Vector3(1.0F,1.0F,-1.0F) );
    b.vertex( Vector3(1.0F,1.0F,1.0F) );
    b.vertex( Vector3(-1.0F,1.0F,1.0F) );

    b.vertex( Vector3(-1.0F,-1.0F,-1.0F) );
    b.vertex( Vector3(1.0F,-1.0F,-1.0F) );
    b.vertex( Vector3(1.0F,-1.0F,1.0F) );
    b.vertex( Vector3(-1.0F,-1.0F,1.0F) );
    
    b.vertex( Vector3(-1.0F,1.0F,-1.0F) );
    b.vertex( Vector3(-1.0F,-1.0F,-1.0F) );
    b.vertex( Vector3(-1.0F,-1.0F,1.0F) );
    b.vertex( Vector3(-1.0F,1.0F,1.0F) );
    
    b.vertex( Vector3(1.0F,1.0F,-1.0F) );
    b.vertex( Vector3(1.0F,-1.0F,-1.0F) );
    b.vertex( Vector3(1.0F,-1.0F,1.0F) );
    b.vertex( Vector3(1.0F,1.0F,1.0F) );
    
    b.vertex( Vector3(-1.0F,1.0F,1.0F) );
    b.vertex( Vector3(-1.0F,-1.0F,1.0F) );
    b.vertex( Vector3(1.0F,-1.0F,1.0F) );
    b.vertex( Vector3(1.0F,1.0F,1.0F) );

    b.vertex( Vector3(-1.0F,1.0F,-1.0F) );
    b.vertex( Vector3(-1.0F,-1.0F,-1.0F) );
    b.vertex( Vector3(1.0F,-1.0F,-1.0F) );
    b.vertex( Vector3(1.0F,1.0F,-1.0F) );
    
    b.batchEnd();
}
Ejemplo n.º 3
0
void ComponentGUIVideoPlayer::draw (CameraObject* camera, const Color &parent_color)
{
    GUIObject *gui = checkedCast<GUIObject*>(getOwner());
    if (!gui)
        return;
    
    if (gui->getColor().getA() * parent_color.getA() <= 0.0F)
        return;
       
    Rectangle local_rect = gui->getRectangle();
    Matrix4 transform = gui->getDrawTransform();
    Color c = gui->getColor() * parent_color;
    
    
    // Video
    if ( _video_material->isValid() ) {
        DrawBatcherQuads b;
        
        b.batchBegin(_video_material->get(), transform, DrawBatcherQuads::FMT_V | DrawBatcherQuads::FMT_T1 | DrawBatcherQuads::FMT_C);
        
        b.vertex(Vector3(local_rect.getMinusX(), local_rect.getMinusY(), 0.0F), Texcoord2(0.0F,0.0F), c);
        b.vertex(Vector3(local_rect.getPlusX(), local_rect.getMinusY(), 0.0F), Texcoord2(1.0F,0.0F), c);
        b.vertex(Vector3(local_rect.getPlusX(), local_rect.getPlusY(), 0.0F), Texcoord2(1.0F,1.0F), c);
        b.vertex(Vector3(local_rect.getMinusX(), local_rect.getPlusY(), 0.0F), Texcoord2(0.0F,1.0F), c);
        
        b.batchEnd();
    }

    // Background
    if ( _background->isValid() ) {
        DrawBatcherQuads b;
        Rectangle r = calcBackgroundRect(local_rect);
        
        b.batchBegin(_background->get(), transform, DrawBatcherQuads::FMT_V | DrawBatcherQuads::FMT_T1 | DrawBatcherQuads::FMT_C);
        
        b.vertex(Vector3(r.getMinusX(), r.getMinusY(), 0.0F), Texcoord2(0.0F,0.0F), c);
        b.vertex(Vector3(r.getPlusX(), r.getMinusY(), 0.0F), Texcoord2(1.0F,0.0F), c);
        b.vertex(Vector3(r.getPlusX(), r.getPlusY(), 0.0F), Texcoord2(1.0F,1.0F), c);
        b.vertex(Vector3(r.getMinusX(), r.getPlusY(), 0.0F), Texcoord2(0.0F,1.0F), c);
        
        b.batchEnd();
    }

    // Play/Pause
    if ( _play_material->isValid() && _pause_material->isValid()) {
        DrawBatcherQuads b;
        Rectangle r = calcPlayPauseRect(local_rect);
        
        if (Video::getState(_hw) == Video::STATE_PLAYING)
            b.batchBegin(_pause_material->get(), transform, DrawBatcherQuads::FMT_V | DrawBatcherQuads::FMT_T1 | DrawBatcherQuads::FMT_C);
        else
            b.batchBegin(_play_material->get(), transform, DrawBatcherQuads::FMT_V | DrawBatcherQuads::FMT_T1 | DrawBatcherQuads::FMT_C);
        
        b.vertex(Vector3(r.getMinusX(), r.getMinusY(), 0.0F), Texcoord2(0.0F,0.0F), c);
        b.vertex(Vector3(r.getPlusX(), r.getMinusY(), 0.0F), Texcoord2(1.0F,0.0F), c);
        b.vertex(Vector3(r.getPlusX(), r.getPlusY(), 0.0F), Texcoord2(1.0F,1.0F), c);
        b.vertex(Vector3(r.getMinusX(), r.getPlusY(), 0.0F), Texcoord2(0.0F,1.0F), c);
        
        b.batchEnd();
    }

    // Track
    if ( _track_unloaded->isValid() ) {
        DrawBatcherQuads b;
        Rectangle r = calcTrackRect(local_rect);
        
        b.batchBegin(_track_unloaded->get(), transform, DrawBatcherQuads::FMT_V | DrawBatcherQuads::FMT_T1 | DrawBatcherQuads::FMT_C);
        
        b.vertex(Vector3(r.getMinusX(), r.getMinusY(), 0.0F), Texcoord2(0.0F,0.0F), c);
        b.vertex(Vector3(r.getPlusX(), r.getMinusY(), 0.0F), Texcoord2(1.0F,0.0F), c);
        b.vertex(Vector3(r.getPlusX(), r.getPlusY(), 0.0F), Texcoord2(1.0F,1.0F), c);
        b.vertex(Vector3(r.getMinusX(), r.getPlusY(), 0.0F), Texcoord2(0.0F,1.0F), c);
        
        b.batchEnd();
    }

    // Thumb
    if ( _thumb_material->isValid() ) {
        DrawBatcherQuads b;
        Rectangle r = calcThumbRect(local_rect, _current_time, _length);
        
        b.batchBegin(_thumb_material->get(), transform, DrawBatcherQuads::FMT_V | DrawBatcherQuads::FMT_T1 | DrawBatcherQuads::FMT_C);
        
        b.vertex(Vector3(r.getMinusX(), r.getMinusY(), 0.0F), Texcoord2(0.0F,0.0F), c);
        b.vertex(Vector3(r.getPlusX(), r.getMinusY(), 0.0F), Texcoord2(1.0F,0.0F), c);
        b.vertex(Vector3(r.getPlusX(), r.getPlusY(), 0.0F), Texcoord2(1.0F,1.0F), c);
        b.vertex(Vector3(r.getMinusX(), r.getPlusY(), 0.0F), Texcoord2(0.0F,1.0F), c);
        
        b.batchEnd();
    }
    
    
    
}
Ejemplo n.º 4
0
void ComponentGUIScroller::draw (CameraObject* camera, const Color &parent_color)
{
    GUIObject *gui = checkedCast<GUIObject*>(getOwner());
    if (!gui)
        return;

    MaterialResource *material = _material->get();
       
    if (gui->getColor().getA() * parent_color.getA() <= 0.0F)
        return;
            
    //
    // Scroll bars
    //

    Color c = gui->getColor() * parent_color;

    if (_material->isValid()) {
        const DTfloat H_SIZE = 4.0F/1024.0F;
        const DTfloat V_SIZE = H_SIZE / System::getRenderer()->getScreenAspect();
                    
        // Limit scroll bounds
        Rectangle rect = gui->getRectangle();
            
        if (_scroll_vert && (_contents.getPlusY() > rect.getPlusY() || _contents.getMinusY() < rect.getMinusY())) {
            
            DTfloat top_gap = 1.0F - ( _contents.getPlusY() - rect.getPlusY() ) / _contents.getHeight();
            DTfloat bottom_gap = ( rect.getMinusY() - _contents.getMinusY() ) / _contents.getHeight();
            
            if (top_gap > 1.0F)     top_gap = 1.0F;
            if (bottom_gap < 0.0F)  bottom_gap = 0.0F;
                    
            DrawBatcherQuads b;
            b.batchBegin(material, gui->getDrawTransform(), DrawBatcherQuads::FMT_V | DrawBatcherQuads::FMT_T1 | DrawBatcherQuads::FMT_C);
            
            b.vertex(Vector3(rect.getPlusX() - H_SIZE,  rect.getMinusY() + rect.getHeight() * bottom_gap,0.0F), Texcoord2(0.0F,0.0F), c);
            b.vertex(Vector3(rect.getPlusX(),           rect.getMinusY() + rect.getHeight() * bottom_gap,0.0F), Texcoord2(1.0F,0.0F), c);
            b.vertex(Vector3(rect.getPlusX(),           rect.getMinusY() + rect.getHeight() * bottom_gap + V_SIZE,0.0F), Texcoord2(1.0F,0.5F), c);
            b.vertex(Vector3(rect.getPlusX() - H_SIZE,  rect.getMinusY() + rect.getHeight() * bottom_gap + V_SIZE,0.0F), Texcoord2(0.0F,0.5F), c);

            b.vertex(Vector3(rect.getPlusX() - H_SIZE,  rect.getMinusY() + rect.getHeight() * bottom_gap + V_SIZE,0.0F), Texcoord2(0.0F,0.5F), c);
            b.vertex(Vector3(rect.getPlusX(),           rect.getMinusY() + rect.getHeight() * bottom_gap + V_SIZE,0.0F), Texcoord2(1.0F,0.5F), c);
            b.vertex(Vector3(rect.getPlusX(),           rect.getMinusY() + rect.getHeight() * top_gap - V_SIZE,0.0F), Texcoord2(1.0F,0.5F), c);
            b.vertex(Vector3(rect.getPlusX() - H_SIZE,  rect.getMinusY() + rect.getHeight() * top_gap - V_SIZE,0.0F), Texcoord2(0.0F,0.5F), c);

            b.vertex(Vector3(rect.getPlusX() - H_SIZE,  rect.getMinusY() + rect.getHeight() * top_gap - V_SIZE,0.0F), Texcoord2(0.0F,0.5F), c);
            b.vertex(Vector3(rect.getPlusX(),           rect.getMinusY() + rect.getHeight() * top_gap - V_SIZE,0.0F), Texcoord2(1.0F,0.5F), c);
            b.vertex(Vector3(rect.getPlusX(),           rect.getMinusY() + rect.getHeight() * top_gap,0.0F), Texcoord2(1.0F,1.0F), c);
            b.vertex(Vector3(rect.getPlusX() - H_SIZE,  rect.getMinusY() + rect.getHeight() * top_gap,0.0F), Texcoord2(0.0F,1.0F), c);
            
            b.batchEnd();
        }

        if (_scroll_horz && (_contents.getPlusX() > rect.getPlusX() || _contents.getMinusX() < rect.getMinusX())) {
            
            DTfloat right_gap = 1.0F - ( _contents.getPlusX() - rect.getPlusX() ) / _contents.getWidth();
            DTfloat left_gap = ( rect.getMinusX() - _contents.getMinusX() ) / _contents.getWidth();
            
            if (right_gap > 1.0F)   right_gap = 1.0F;
            if (left_gap < 0.0F)    left_gap = 0.0F;
            
            
            DrawBatcherQuads b;
            b.batchBegin(material, gui->getDrawTransform(), DrawBatcherQuads::FMT_V | DrawBatcherQuads::FMT_T1 | DrawBatcherQuads::FMT_C);
            
            b.vertex(Vector3(rect.getMinusX() + rect.getWidth() * left_gap,            rect.getMinusY() - V_SIZE,   0.0F), Texcoord2(0.0F,0.0F), c);
            b.vertex(Vector3(rect.getMinusX() + rect.getWidth() * left_gap + H_SIZE,   rect.getMinusY() - V_SIZE,   0.0F), Texcoord2(0.5F,0.0F), c);
            b.vertex(Vector3(rect.getMinusX() + rect.getWidth() * left_gap + H_SIZE,   rect.getMinusY(),            0.0F), Texcoord2(0.5F,1.0F), c);
            b.vertex(Vector3(rect.getMinusX() + rect.getWidth() * left_gap,            rect.getMinusY(),            0.0F), Texcoord2(0.0F,1.0F), c);

            b.vertex(Vector3(rect.getMinusX() + rect.getWidth() * left_gap + H_SIZE,   rect.getMinusY() - V_SIZE,   0.0F), Texcoord2(0.5F,0.0F), c);
            b.vertex(Vector3(rect.getMinusX() + rect.getWidth() * right_gap - H_SIZE,  rect.getMinusY() - V_SIZE,   0.0F), Texcoord2(0.5F,0.0F), c);
            b.vertex(Vector3(rect.getMinusX() + rect.getWidth() * right_gap - H_SIZE,  rect.getMinusY(),            0.0F), Texcoord2(0.5F,1.0F), c);
            b.vertex(Vector3(rect.getMinusX() + rect.getWidth() * left_gap + H_SIZE,   rect.getMinusY(),            0.0F), Texcoord2(0.5F,1.0F), c);

            b.vertex(Vector3(rect.getMinusX() + rect.getWidth() * right_gap - H_SIZE,  rect.getMinusY() - V_SIZE,   0.0F), Texcoord2(0.5F,0.0F), c);
            b.vertex(Vector3(rect.getMinusX() + rect.getWidth() * right_gap,           rect.getMinusY() - V_SIZE,   0.0F), Texcoord2(1.0F,0.0F), c);
            b.vertex(Vector3(rect.getMinusX() + rect.getWidth() * right_gap,           rect.getMinusY(),            0.0F), Texcoord2(1.0F,1.0F), c);
            b.vertex(Vector3(rect.getMinusX() + rect.getWidth() * right_gap - H_SIZE,  rect.getMinusY(),            0.0F), Texcoord2(0.5F,1.0F), c);
            
            b.batchEnd();
        }
    }
        
    //
    // Delete boxes
    //
    
    if (_delete_material->isValid() && _can_remove_items && _mode != MODE_NORMAL) {
        std::list<PlaceableObject*> children = gui->getChildren();
        
        for (auto i : children) {
            GUIObject *icon = checkedCast<GUIObject*>(i);
            if (!icon)
                continue;
                
            Rectangle rect = calcDeleteButtonRectangle(icon);
            
            DrawBatcherQuads b;
            b.batchBegin(_delete_material->get(), gui->getTransform(), DrawBatcherQuads::FMT_V | DrawBatcherQuads::FMT_T1 | DrawBatcherQuads::FMT_C);
            
            b.vertex(Vector3(rect.getMinusX(), rect.getMinusY(), 0.0F), Texcoord2(0.0F,0.0F), c);
            b.vertex(Vector3(rect.getPlusX(), rect.getMinusY(), 0.0F), Texcoord2(1.0F,0.0F), c);
            b.vertex(Vector3(rect.getPlusX(), rect.getPlusY(), 0.0F), Texcoord2(1.0F,1.0F), c);
            b.vertex(Vector3(rect.getMinusX(), rect.getPlusY(), 0.0F), Texcoord2(0.0F,1.0F), c);
            
            b.batchEnd();
        }  
    }
}