uiaccelerator_plat/alf_core_toolkit_api/inc/uiacceltk/huim3gmesh.h
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:   Definition of CHuiM3GMesh, an interface enabling usage of M3G
       
    15 * 				 scene graphs within Hitchcock UI Toolkit user interfaces.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20  
       
    21 #ifndef __HUIM3GMESH_H__
       
    22 #define __HUIM3GMESH_H__
       
    23 
       
    24 #include <uiacceltk/HuiMesh.h>
       
    25 #include <uiacceltk/HuiRealRect.h>
       
    26 
       
    27 // Force softfp linkage until included header has its own definitions
       
    28 #if defined(__ARMCC_VERSION)
       
    29 #pragma push
       
    30 #pragma softfp_linkage
       
    31 #endif
       
    32 #include <M3G/m3g_core.h>
       
    33 #if defined(__ARMCC_VERSION)
       
    34 #pragma pop
       
    35 #endif
       
    36 
       
    37 /* Constants */
       
    38 
       
    39 // ID for Animating all controllers
       
    40 const TInt KHuiM3GAnimateAllControllers = 100000;  
       
    41 
       
    42 /* Forward declarations. */
       
    43 
       
    44 /* Structs */
       
    45 
       
    46 // Hitchcock M3G animation controller
       
    47 struct THuiM3GMeshAnimationController
       
    48 	{
       
    49 	M3GAnimationController iController;  // M3G controller
       
    50 	THuiTimedValue iPosition;            // position in timeline
       
    51 	TBool iAnimating;                    // is controller animating
       
    52 	TInt iTimeOffset;
       
    53 	TInt iPreviousTime;
       
    54 	};
       
    55 
       
    56 
       
    57 /**
       
    58  * CHuiM3GMesh is a 3D mesh that can be used in Hitchcock UI Toolkit to incorporate
       
    59  * M3G (Mobile 3D Graphics) objects into the user interface.
       
    60  */
       
    61 class CHuiM3GMesh : public CHuiMesh
       
    62     {
       
    63 public: // New
       
    64     
       
    65     /** @beginAPI */
       
    66     
       
    67     /**
       
    68      * Loads an M3G scene graph from an M3G file. The M3G mesh scene graph is loaded 
       
    69      * from the file given as a parameter. If the filename string is malformed and does not adhere to
       
    70      * file path syntax this method leaves with KErrBadName error code. If the file
       
    71      * path is not found this method leaves with KErrPathNotFound error code.
       
    72      * If the specified file is not found this method leaves with KErrNotFound error code.
       
    73      * If the M3G file does not contain any M3G objects or is corrupted this method
       
    74      * leaves with KErrCorrupt error code. If this method leaves the whole scene graph content
       
    75      * is released. This means that no partial scene graph content can be accessed through this object.
       
    76      *
       
    77      * @param aFileName Path to the M3G file from which the M3G scene graph is loaded
       
    78      *                  into this M3G mesh. The texture image path is prepended to this
       
    79      *                  resource file name. @see CHuiTextureManager::ImagePath().
       
    80      */	
       
    81 	IMPORT_C virtual void LoadSceneL(const TDesC &aFileName);
       
    82 
       
    83 	/** @endAPI */
       
    84 
       
    85     /**
       
    86      * Default constructor.
       
    87      */
       
    88 	IMPORT_C CHuiM3GMesh();
       
    89 
       
    90     /**
       
    91      * Destructor.
       
    92      */
       
    93 	IMPORT_C virtual ~CHuiM3GMesh();
       
    94 
       
    95 	/**
       
    96 	 * Set viewport of the m3g mesh.
       
    97 	 */
       
    98     IMPORT_C virtual void SetViewportRect( const THuiRealRect& aRect );
       
    99 
       
   100 	/**
       
   101 	 * Rotate world around Y axis.
       
   102 	 */
       
   103 	IMPORT_C virtual void RotateYaw(TReal32 aAngle) __SOFTFP;
       
   104 
       
   105 	/**
       
   106 	 * Rotate world around X axis.
       
   107 	 */
       
   108 	IMPORT_C virtual void RotatePitch(TReal32 aAngle) __SOFTFP;
       
   109 
       
   110 	/**
       
   111 	 * Store camera transformations of the M3G world so those can be restored later on and this way animations
       
   112 	 * doesn't mess with camera manipulations.
       
   113 	 */
       
   114 	IMPORT_C virtual void StoreCamera();
       
   115 	
       
   116 	/**
       
   117 	 * Restore camera transformations of the M3G world.
       
   118 	 */
       
   119 	IMPORT_C virtual void RestoreCamera();
       
   120 	
       
   121 	/**
       
   122 	 * Goes through animation controllers and does animations.
       
   123 	 */
       
   124 	IMPORT_C virtual void AnimateControllers();
       
   125 	
       
   126 public: // From CHuiMesh
       
   127      /**
       
   128      * Draws the loaded M3G scene.
       
   129      */     
       
   130     IMPORT_C virtual void Draw(CHuiGc& aGc, const THuiImage* aImage = 0, 
       
   131                       const THuiImage* aSecondaryImage = 0,
       
   132                       TReal32 aSecondaryAlpha = 0.0) const __SOFTFP;
       
   133 
       
   134 
       
   135 	/**
       
   136 	 * Returns number of (hitchcock) animation controllers
       
   137 	 */
       
   138     IMPORT_C virtual TInt AnimationControllerCount() const;
       
   139 
       
   140 	/**
       
   141 	 * Set position of animation in animation controller.
       
   142 	 *
       
   143 	 * @param aControllerId  ID of the controller.
       
   144 	 * @param aTarget  Target position in the timeline (seconds)
       
   145 	 * @param aTime  Time to be used in animation
       
   146 	 */
       
   147 	IMPORT_C virtual void SetAnimationPosition(TInt aControllerId, TReal32 aTarget, TInt aTime) __SOFTFP;
       
   148 
       
   149 	/**
       
   150 	 * Start animation of the controller
       
   151 	 *
       
   152 	 * @param aControllerId  ID of the animation controller.
       
   153 	 */
       
   154 	IMPORT_C virtual void StartAnimationController(TInt aControllerId);
       
   155 	
       
   156 	/**
       
   157 	 * Stop animation of the controller
       
   158 	 *
       
   159 	 * @param aControllerId  ID of the animation controller.
       
   160 	 */
       
   161     IMPORT_C virtual void StopAnimationController(TInt aControllerId);
       
   162 
       
   163 protected: // todo: to private?
       
   164 
       
   165     /**
       
   166      * 2nd phase constructor. 
       
   167      */
       
   168     IMPORT_C virtual void ConstructL();    
       
   169 
       
   170     /**
       
   171      * Will release the loaded scene.
       
   172      */
       
   173     IMPORT_C virtual void ReleaseScene();
       
   174 	
       
   175 	/**
       
   176 	 * Load scene with m3g interface parameter
       
   177 	 */
       
   178 	IMPORT_C void LoadSceneL(const TDesC& aFileName, M3GInterface aInterface);
       
   179 	
       
   180 	/**
       
   181      * Provides expandability, helps keeping the binary compatibility. Since virtual
       
   182      * table is now exported and this class is dll derivable and the implementation
       
   183      * is more difficult to change, hence this method, which can provide additional
       
   184      * extension APIs.
       
   185      * 
       
   186      * @param aExtensionUid     UID, which is being used for recognizing the extension
       
   187      * @param aExtensionParams  Return pointer to the extension API, once recognized from the extension uid
       
   188      */
       
   189     IMPORT_C virtual void M3GMeshExtension(const TUid& aExtensionUid, TAny** aExtensionParams);
       
   190 
       
   191 private:
       
   192 
       
   193 	/**
       
   194 	 * Finds the center point of the groups objects. Goes the groups
       
   195 	 * inside the group recursively.
       
   196 	 *
       
   197 	 * @param aGroup  group thats center position is needed
       
   198 	 * @param aTrans  translation values to be returned
       
   199 	 * @param aFirst  indicates if aTrans has been initiliazed
       
   200 	 */
       
   201 	void FindObjectCenter(M3GGroup aGroup, TReal32 aTrans[4], TBool aFirst = ETrue);
       
   202 
       
   203 	void RotateObjects(TReal32 aAngle, TReal32 aAxisX, TReal32 aAxisY, TReal32 aAxisZ) __SOFTFP;                      
       
   204 	
       
   205 	/**
       
   206 	 * Populates the iControllers array with animation controllers found
       
   207 	 * from below given object in the M3G object net.
       
   208 	 */
       
   209 	void PopulateAnimationControllerArrayL(const M3GObject aObject);
       
   210 	
       
   211 	/**
       
   212 	 * Execute the actual scene graph loading.
       
   213 	 */
       
   214 	void DoLoadSceneL(const TDesC& aFileName, M3GInterface aInterface);	
       
   215 	
       
   216 protected:
       
   217 
       
   218 	// Area where M3G mesh is rendered.
       
   219 	THuiRealRect iViewportRect;
       
   220 
       
   221 	// World
       
   222     M3GWorld iWorld;
       
   223 
       
   224     // Camera
       
   225     M3GCamera iCamera;
       
   226     TBool iUpdateCamera;
       
   227 
       
   228     // Objects
       
   229     TInt iNumObjects;
       
   230     M3GObject *iObjects;
       
   231 
       
   232 
       
   233 	// Stored camera transformations    
       
   234     TReal32 iCamRotation[4];
       
   235     TReal32 iCamTranslation[4];
       
   236 
       
   237     // Animation controllers
       
   238     RArray<THuiM3GMeshAnimationController> iControllers;
       
   239     
       
   240     /** Spare member to help keeping binary compatibility, since HuiM3GMesh is
       
   241         now dll derivable **/
       
   242     TInt iSpare;
       
   243 
       
   244     };  
       
   245 
       
   246 #endif  // __HUIM3GMESH_H__