uifw/ganes/inc/HgVgHelper.h
changeset 47 2f0c06423c72
parent 46 0e1e0022bd03
child 53 3c67ea82fafc
equal deleted inserted replaced
46:0e1e0022bd03 47:2f0c06423c72
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:     
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef HGVHELPER_H_
       
    19 #define HGVHELPER_H_
       
    20 
       
    21 // INCLUDES
       
    22 #include <e32base.h>
       
    23 #include <e32std.h>
       
    24 #include <gdi.h>
       
    25 #include <VG/openvg.h>
       
    26 
       
    27 // FORWARD DECLARATIONS
       
    28 class CFbsBitmap;
       
    29 class CHgVgEGL;
       
    30 class CGulIcon;
       
    31 
       
    32 #define RGBA(r, g, b, a) ((VGuint) (((r) << 24) | ((g) << 16) | ((b) << 8) | (a)))
       
    33 
       
    34 
       
    35 /**
       
    36  * Helper classes and methods for CHgVg* classes.
       
    37  */
       
    38 namespace HgVgHelper
       
    39 {
       
    40     /**--------------------------------------------------------------
       
    41      * Vertex and Matrix manipulations helper classes
       
    42      --------------------------------------------------------------*/
       
    43 
       
    44      // Forward declarations
       
    45     class TMatrix;
       
    46     class TVertex;
       
    47 
       
    48      /**
       
    49      * 3D Vertex class
       
    50      */
       
    51     class TVertex
       
    52        {
       
    53        public:
       
    54            // model coordinates
       
    55            VGfloat iX, iY, iZ;
       
    56 
       
    57            // transformed mode-view-coordinates
       
    58            VGfloat iTx, iTy, iTz;
       
    59 
       
    60            // projected screen coordinates
       
    61            VGfloat iScreenX;
       
    62            VGfloat iScreenY;
       
    63 
       
    64            /**
       
    65             * Projects model-view-coordinates to screen space coordinates.
       
    66             * 
       
    67             * @param aScreenWidth width of the rendering window
       
    68             * @param aScreenHeight height of the rendering window
       
    69             * @param aFov field of view to use
       
    70             */
       
    71            void ProjectPoint(VGfloat aScreenWidth, VGfloat aScreenHeight, VGfloat aFov);
       
    72            
       
    73            /**
       
    74             * Transform model coordinates by matrix given and sets
       
    75             * result to tranformed model-view-coordinates.
       
    76             * 
       
    77             * @param aMatrix model-view-transformation matrix.
       
    78             */
       
    79            void TransformPoint(const TMatrix& aMatrix);
       
    80        };
       
    81 
       
    82      /**
       
    83       * 4x4 Matrix class
       
    84       */
       
    85      class TMatrix
       
    86        {
       
    87        public:
       
    88            // matrix data
       
    89            VGfloat iM[4][4];
       
    90 
       
    91            // Construction and destruction.
       
    92            TMatrix();
       
    93            TMatrix(const TMatrix& rhs);
       
    94            ~TMatrix();
       
    95 
       
    96            // Operators
       
    97            TMatrix& operator=(const TMatrix& rhs);
       
    98 
       
    99            /**
       
   100             * Makes this matrix identity matrix.
       
   101             */
       
   102            void Identity();
       
   103            
       
   104            /**
       
   105             * Multiplies this matrix by rhs matrix.
       
   106             * 
       
   107             * @param rhs Right hand side matrix.
       
   108             */
       
   109            void Multiply(const TMatrix& rhs);
       
   110           
       
   111            /**
       
   112             * Sets this matrix to rotation matrix around X-axis.
       
   113             * 
       
   114             * @param aAngle angle in radians.
       
   115             */
       
   116            void RotationX(VGfloat aAngle);
       
   117            
       
   118            /**
       
   119             * Sets this matrix to rotation matrix around Y-axis.
       
   120             * 
       
   121             * @param aAngle angle in radians.
       
   122             */
       
   123            void RotationY(VGfloat aAngle);
       
   124            
       
   125            /**
       
   126             * Sets this matrix to rotation matrix around Z-axis.
       
   127             * 
       
   128             * @param aAngle angle in radians.
       
   129             */
       
   130            void RotationZ(VGfloat aAngle);
       
   131            
       
   132            /**
       
   133             * Sets this matrix to scale matrix.
       
   134             * 
       
   135             * @param aSx scaling on X-axis
       
   136             * @param aSy scaling on Y-axis
       
   137             * @param aSz scaling on Z-axis
       
   138             */
       
   139            void Scale(VGfloat aSx, VGfloat aSy, VGfloat aSz);
       
   140            
       
   141            /**
       
   142             * Sets this matrix to translation matrix.
       
   143             * 
       
   144             * @param aTx translation on X-axis.
       
   145             * @param aTy translation on Y-axis.
       
   146             * @param aTz translation on Z-axis. 
       
   147             */
       
   148            void Translation(VGfloat aTx, VGfloat aTy, VGfloat aTz);
       
   149        };
       
   150 
       
   151      /**--------------------------------------------------------------
       
   152       * IMAGE HANDLING ROUTINES
       
   153      --------------------------------------------------------------*/
       
   154      
       
   155     /**
       
   156      * Creates VGImage from CGuiIcon.
       
   157      * May leave for example if runs out of video memory.
       
   158      * 
       
   159      * @param aIcon valid CGuiIcon-object.
       
   160      * @return VGImage-object.
       
   161      */
       
   162     VGImage CreateVgImageFromIconL( const CGulIcon& aIcon );
       
   163     
       
   164         
       
   165     /**--------------------------------------------------------------
       
   166      * Misc. Helpers.
       
   167      --------------------------------------------------------------*/
       
   168 
       
   169     /**
       
   170      * Clamps value between lower and upper limits.
       
   171      * 
       
   172      * @param aValue value.
       
   173      * @param aUpper upper limit.
       
   174      * @param aLower lower limit.
       
   175      * @return clamped value.
       
   176      */
       
   177     VGfloat Clamp(VGfloat aValue, VGfloat aUpper, VGfloat aLower);
       
   178     
       
   179     /**
       
   180      * Linearly interpolates value between start and end.
       
   181      * 
       
   182      * @param aStart starting value.
       
   183      * @param aEnd ending value.
       
   184      * @param aT t value between 0.0f - 1.0f.
       
   185      */
       
   186     VGfloat Lerp(VGfloat aStart, VGfloat aEnd, VGfloat aT);
       
   187 
       
   188     /**
       
   189      * Gets values absolute.
       
   190      * 
       
   191      * @param aValue value.
       
   192      * @return absolute of the value.
       
   193      */
       
   194     VGfloat Abs(VGfloat aValue);    
       
   195         
       
   196     
       
   197     /**
       
   198      * Calculates bounding rect from points.
       
   199      * 
       
   200      * @param aRect destination rect-object, rectangle in symbian screen coordinates.
       
   201      * @param aPoints source points in vg coordinates (x, y, x, y...). 
       
   202      * @param aNumPoints number of points in aPoints.
       
   203      */
       
   204     void CalculateBoundingRect(TRect& aRect, VGfloat* aPoints, TInt aNumPoints, 
       
   205             const TRect& aWindowRect);    
       
   206     
       
   207         
       
   208     /**
       
   209      * Draws vg image to current vg surface.
       
   210      * NOTE: Assumes that the image is in vg coordinates.
       
   211      * 
       
   212      * @param aImage image to draw.
       
   213      * @param aPos position where to draw (in symbian screen coordinates).
       
   214      * @param aWindowRect drawing windows rectangle.
       
   215      */
       
   216     void DrawImage(VGImage aImage, const TPoint& aPos, const TRect& aWindowRect, TBool aCentered = EFalse);
       
   217     
       
   218     /**
       
   219      * Draws vg image to current vg surface multiplying its colors by a color.
       
   220      * NOTE: Assumes that the image is in vg coordinates.
       
   221      * 
       
   222      * @param aImage image to draw.
       
   223      * @param aColor color which is multiplied with image colors.
       
   224      * @param aPos position where the image is drawn (in sumbian screen coordinates)
       
   225      * @param aWindowRect drawing windows renctangle.
       
   226      */
       
   227     void DrawImageColorized(VGImage aImage, const TRgb& aColor, 
       
   228             const TPoint& aPos, const TRect& aWindowRect, TBool aCentered = EFalse);
       
   229     
       
   230     
       
   231     /**
       
   232      * Wrapper for creating paths.
       
   233      * 
       
   234      * @param aNumSegment
       
   235      * @param aSegments
       
   236      * @param aPoints
       
   237      */
       
   238     VGPath CreatePath(VGuint aNumSegments, const VGubyte* aSegments, const VGfloat* aPoints);
       
   239         
       
   240     /**
       
   241      * Wrapper for creating single color paints.
       
   242      * 
       
   243      * @param aColor
       
   244      */
       
   245     VGPaint CreateColorPaint(const TRgb& aColor);
       
   246     
       
   247     /**
       
   248      * Wrapper for creating single color paints.
       
   249      * 
       
   250      * @param aColor
       
   251      */
       
   252     VGPaint CreateColorPaint(const VGfloat* aColor);
       
   253        
       
   254     }
       
   255 
       
   256 #endif /* HGVGHELPER */