Editar

Compartilhar via


SK3dView Class

Definition

A utility class that can be used to create 3D transformations.

public class SK3dView : SkiaSharp.SKObject
Inheritance

Examples

var info = new SKImageInfo(256, 256);
using (var surface = SKSurface.Create(info)) {
    SKCanvas canvas = surface.Canvas;

    canvas.Clear(SKColors.White);

    // center the entire drawing
    canvas.Translate(128, 128);

    // the "3D camera"
    var view = new SK3dView();

    // rotate to a nice 3D view
    view.RotateXDegrees(-25);
    view.RotateYDegrees(45);

    // move the origin of the 3D view
    view.Translate(-50, 50, 50);

    // define the cube face
    var face = SKRect.Create(0, 0, 100, 100);

    // draw the left face
    using (new SKAutoCanvasRestore(canvas, true)) {
        // get the face in the correct location
        view.Save();
        view.RotateYDegrees(-90);
        view.ApplyToCanvas(canvas);
        view.Restore();

        // draw the face
        var leftFace = new SKPaint {
            Color = SKColors.LightGray,
            IsAntialias = true
        };
        canvas.DrawRect(face, leftFace);
    }

    // draw the right face
    using (new SKAutoCanvasRestore(canvas, true)) {
        // get the face in the correct location
        view.Save();
        view.TranslateZ(-100);
        view.ApplyToCanvas(canvas);
        view.Restore();

        // draw the face
        var rightFace = new SKPaint {
            Color = SKColors.Gray,
            IsAntialias = true
        };
        canvas.DrawRect(face, rightFace);
    }

    // draw the top face
    using (new SKAutoCanvasRestore(canvas, true)) {
        // get the face in the correct location
        view.Save();
        view.RotateXDegrees(90);
        view.ApplyToCanvas(canvas);
        view.Restore();

        // draw the face
        var topFace = new SKPaint {
            Color = SKColors.DarkGray,
            IsAntialias = true
        };
        canvas.DrawRect(face, topFace);
    }
}

The example above produces the following:

3D View

Constructors

SK3dView()

Creates a new instance of SK3dView.

Properties

Handle

Gets or sets the handle to the underlying native object.

(Inherited from SKObject)
IgnorePublicDispose

Gets or sets a value indicating whether the call the public Dispose() should be no-op.

(Inherited from SKNativeObject)
IsDisposed

Gets or sets a value indicating whether the object has already been disposed.

(Inherited from SKNativeObject)
Matrix

Gets the current transformation as a matrix.

OwnsHandle

Gets a value indicating whether this object should destroy the underlying native object.

(Inherited from SKObject)

Methods

ApplyToCanvas(SKCanvas)

Applies the current transformation to the specified canvas.

Dispose()

Releases all resources used by this SKNativeObject.

(Inherited from SKNativeObject)
Dispose(Boolean)

Releases the unmanaged resources used by the SK3dView and optionally releases the managed resources.

DisposeInternal()

Triggers a dispose, ignoring the value of IgnorePublicDispose.

(Inherited from SKNativeObject)
DisposeManaged()

Implemented by derived SKObject types to destroy any managed objects.

(Inherited from SKObject)
DisposeNative()

Implemented by derived SKObject types to destroy any native objects.

DisposeNative()

Implemented by derived SKObject types to destroy any native objects.

(Inherited from SKObject)
DisposeUnownedManaged() (Inherited from SKObject)
DotWithNormal(Single, Single, Single)

Returns the dot product of the current transformation and the specified normal.

GetMatrix(SKMatrix)

Stores the current transformation in the specified matrix.

Restore()

Restores the transformation to the last saved with Save().

RotateXDegrees(Single)

Rotates the transformation along the x-axis by the specified degrees.

RotateXRadians(Single)

Rotates the transformation along the x-axis by the specified radians.

RotateYDegrees(Single)

Rotates the transformation along the y-axis by the specified degrees.

RotateYRadians(Single)

Rotates the transformation along the y-axis by the specified radians.

RotateZDegrees(Single)

Rotates the transformation along the z-axis by the specified degrees.

RotateZRadians(Single)

Rotates the transformation along the z-axis by the specified radians.

Save()

Saves the current transformation so that it can be restored later using Restore().

Translate(Single, Single, Single)

Translates the transformation.

TranslateX(Single)

Translates the transformation along the x-axis.

TranslateY(Single)

Translates the transformation along the y-axis.

TranslateZ(Single)

Translates the transformation along the z-axis.

Applies to