Beispiel #1
0
void ComponentDrawCamera::draw (CameraObject* camera)
{
    CameraObject *placeable = checkedCast<CameraObject*>(getOwner());
    if (!placeable)
        return;
        
    _line_material.setBlendEnable(false);
    _line_material.setDepthEnable(true);
    _line_material.setCullMode(DT3GL_CULL_NONE);
    _line_material.setColor(_color);
	_line_material.setShader(ShaderResource::getShader(FilePath("{editorline.shdr}")));


    DrawBatcher b;
    b.batchBegin(&_line_material, placeable->getTransform(), DrawBatcher::BATCH_LINES, DrawBatcher::FMT_V);

    // Can
    for (DTuint i = 0; i < ARRAY_SIZE(can); ++i) {        
        b.vertex( Vector3(THICKNESS, can[i].x, can[i].y) );
        b.vertex( Vector3(-THICKNESS, can[i].x, can[i].y) );
    }

    for (DTuint i = 0; i < ARRAY_SIZE(can)-1; ++i) {        
        b.vertex( Vector3(THICKNESS, can[i].x, can[i].y) );
        b.vertex( Vector3(THICKNESS, can[i+1].x, can[i+1].y) );
        
        b.vertex( Vector3(-THICKNESS, can[i].x, can[i].y) );
        b.vertex( Vector3(-THICKNESS, can[i+1].x, can[i+1].y) );
    }
    
    // Box
    for (DTuint i = 0; i < ARRAY_SIZE(box); ++i) {        
        b.vertex( Vector3(THICKNESS, box[i].x, box[i].y) );
        b.vertex( Vector3(-THICKNESS, box[i].x, box[i].y) );
    }

    for (DTuint i = 0; i < ARRAY_SIZE(box)-1; ++i) {        
        b.vertex( Vector3(THICKNESS, box[i].x, box[i].y) );
        b.vertex( Vector3(THICKNESS, box[i+1].x, box[i+1].y) );
        
        b.vertex( Vector3(-THICKNESS, box[i].x, box[i].y) );
        b.vertex( Vector3(-THICKNESS, box[i+1].x, box[i+1].y) );
    }

    // Side
    for (DTuint i = 0; i < ARRAY_SIZE(side); ++i) {        
        b.vertex( Vector3(THICKNESS, side[i].x, side[i].y) );
        b.vertex( Vector3(SIDE_THICKNESS+THICKNESS, side[i].x, side[i].y) );
    }

    for (DTuint i = 0; i < ARRAY_SIZE(side)-1; ++i) {        
        b.vertex( Vector3(THICKNESS, side[i].x, side[i].y) );
        b.vertex( Vector3(THICKNESS, side[i+1].x, side[i+1].y) );
        
        b.vertex( Vector3(SIDE_THICKNESS+THICKNESS, side[i].x, side[i].y) );
        b.vertex( Vector3(SIDE_THICKNESS+THICKNESS, side[i+1].x, side[i+1].y) );
    }
    
    // Lens
    for (DTuint i = 0; i < ARRAY_SIZE(lens); ++i) {        
        b.vertex( Vector3(LENS_THICKNESS, lens[i].x, lens[i].y) );
        b.vertex( Vector3(-LENS_THICKNESS, lens[i].x, lens[i].y) );
    }

    for (DTuint i = 0; i < ARRAY_SIZE(lens)-1; ++i) {        
        b.vertex( Vector3(LENS_THICKNESS, lens[i].x, lens[i].y) );
        b.vertex( Vector3(LENS_THICKNESS, lens[i+1].x, lens[i+1].y) );
        
        b.vertex( Vector3(-LENS_THICKNESS, lens[i].x, lens[i].y) );
        b.vertex( Vector3(-LENS_THICKNESS, lens[i+1].x, lens[i+1].y) );
    }
    
    b.batchEnd();
	b.flush();

    // Frustum
    
	placeable->calculateFrustum();
	Matrix4 projection_inv = placeable->getProjection().inversed();
	
	Vector3 near_p0, near_p1, near_p2, near_p3;
	Vector3 far_p0, far_p1, far_p2, far_p3;
	
	MATTransform4H(projection_inv, Vector3(-1.0F,-1.0F,-1.0F), near_p0);
	MATTransform4H(projection_inv, Vector3(1.0F,-1.0F,-1.0F), near_p1);
	MATTransform4H(projection_inv, Vector3(1.0F,1.0F,-1.0F), near_p2);
	MATTransform4H(projection_inv, Vector3(-1.0F,1.0F,-1.0F), near_p3);
	
	MATTransform4H(projection_inv, Vector3(-1.0F,-1.0F,1.0F), far_p0);
	MATTransform4H(projection_inv, Vector3(1.0F,-1.0F,1.0F), far_p1);
	MATTransform4H(projection_inv, Vector3(1.0F,1.0F,1.0F), far_p2);
	MATTransform4H(projection_inv, Vector3(-1.0F,1.0F,1.0F), far_p3);

	b.batchBegin (&_line_material, placeable->getTransform(), DrawBatcher::BATCH_LINE_LOOP, DrawBatcher::FMT_V);
	b.vertex ( near_p0);
	b.vertex ( near_p1);
	b.vertex ( near_p2);
	b.vertex ( near_p3);
	b.batchEnd();
	b.flush();
	
	b.batchBegin (&_line_material, placeable->getTransform(), DrawBatcher::BATCH_LINE_LOOP, DrawBatcher::FMT_V);
	b.vertex ( far_p0);
	b.vertex ( far_p1);
	b.vertex ( far_p2);
	b.vertex ( far_p3);
	b.batchEnd();
	b.flush();
	
	b.batchBegin (&_line_material, placeable->getTransform(), DrawBatcher::BATCH_LINE_LOOP, DrawBatcher::FMT_V);
	b.vertex ( near_p0);
	b.vertex ( near_p1);
	b.vertex ( far_p1);
	b.vertex ( far_p0);
	b.batchEnd();
	b.flush();
	
	b.batchBegin (&_line_material, placeable->getTransform(), DrawBatcher::BATCH_LINE_LOOP, DrawBatcher::FMT_V);
	b.vertex ( near_p2);
	b.vertex ( near_p3);
	b.vertex ( far_p3);
	b.vertex ( far_p2);
	b.batchEnd();	
	b.flush();

    

}