question

AdrianLevy-6647 avatar image
0 Votes"
AdrianLevy-6647 asked RobCaplan edited

How to use SK3dView with multiple objects

Thank you in advance...

The Issue:

I am calling a grid of 100 quads (10x10) of which their PaintSurface is called and within which defines a SK3dView camera that I learned from the MS Docs. The problem is when animating the mView.TranslateZ(mTransZ); with a slider all of quads individually zoom away into the distance instead of them acting as one entity. Its as if the view is affecting and acting upon each of the quads separately. But I want them to stay together and zoom collectively.

The Request:

Please could you show/describe how I should do this properly. I am choosing this method also because the SKMatrix44's CreateTranslation upon the Z axis is lost when converting it to a 2D SKMatrix. Once again if anyone knows how to do this properly please advise. This is roughly the rendering code that runs for each of the quads:

The Code:

 public void CanvasViewOnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
 {
     SKImageInfo imgInfo = e.Info;
     SKSurface surface = e.Surface;
     mCanvas = surface.Canvas;
    
     // The camera 
     mView = new SK3dView();
    
     mCanvas.Clear();
    
     using (new SKAutoCanvasRestore(mCanvas, true))
     {
         mView.Save();
    
         /* <=== Slider controls this but each one of these quads 
          * gets zoomed individually! instead of staying together 
          * as a whole and zooming away. */
         mView.TranslateZ(mTransZ);
    
         /* 
          * CalculateMetricsHereForTheScaleRotationAndTranslation(...);
          * 
          */
    
         #region MatrixOps
    
         mMatrix = SKMatrix.CreateIdentity();
    
         // Scale X Y
         SKMatrix.PostConcat(ref mMatrix, SKMatrix.MakeScale(fScale2, fScale2));
    
         // Rotation X Y Z
         mMatrix44 = SKMatrix44.CreateIdentity();
         mMatrix44.PostConcat(SKMatrix44.CreateRotationDegrees(1, 0, 0, (float)gData.dRotX));
         mMatrix44.PostConcat(SKMatrix44.CreateRotationDegrees(0, 1, 0, (float)gData.dRotY));
         mMatrix44.PostConcat(SKMatrix44.CreateRotationDegrees(0, 0, 1, (float)gData.dRotZ));
    
         // Perspective divide by 3 (arbitrary number seems nice)
         mPerspectiveMatrix = SKMatrix44.CreateIdentity();
         mPerspectiveMatrix[3, 2] = (-1 / fDepth) / 3f;
         mMatrix44.PostConcat(mPerspectiveMatrix);
    
         // Translate X Y Z
         // (How do you use the Z component - it has no effect
         // because of the 2D Matrix conversion.
         mMatrix44.PostConcat(SKMatrix44.CreateTranslation(
             (float)mTransX, (float)mTransY, (float)mTransZ));
    
         // Concatenate with 2D matrix
         SKMatrix.PostConcat(ref mMatrix, mMatrix44.Matrix);
    
         // Set the matrix and display the text
         mCanvas.SetMatrix(mMatrix);
    
         #endregion MatrixOps
    
         mView.ApplyToCanvas(mCanvas);
         mView.Restore();
         mCanvas.DrawPicture(App.mImages.GetImage(miImageIndex).Picture);
     }
 }

My apologies for the unformatted text previously. I have tidied it up now :)


not-supported
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, welcome to Q&A, could you please format your source code using the markdown? With all these lines mixed together it would be hard to read and understand, thank you!

0 Votes 0 ·

Sorry about that. I didn't notice. Now formatted nicely :)

0 Votes 0 ·

@AdrianLevy-6647 Would you be able to post your XAML for this view as well?
If you can post the Entire View and code behind it would help me better understand exactly what you are doing here.

Thanks

0 Votes 0 ·

Could you share XAML code or a simple demo that could help us to understand your issue?

0 Votes 0 ·

0 Answers