javauis/amms_akn/mmacontrol/src/cammsorientationcontrol.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Manipulates the virtual orientation of an object.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32math.h>
       
    22 #include <jdebug.h>
       
    23 #include "cammsorientationcontrol.h"
       
    24 
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ===============================
       
    27 
       
    28 // Destructor
       
    29 CAMMSOrientationControl::~CAMMSOrientationControl()
       
    30 {
       
    31     DEBUG("AMMS::CAMMSOrientationControl::~CAMMSOrientationControl");
       
    32 }
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CAMMSOrientationControl::SetOrientationL
       
    36 // Turns the object to the new orientation.
       
    37 // -----------------------------------------------------------------------------
       
    38 void CAMMSOrientationControl::SetOrientationL(
       
    39     TInt aHeading,
       
    40     TInt aPitch,
       
    41     TInt aRoll)
       
    42 {
       
    43     // Sets the Heading, Pitch, Roll values for the source/listener orientation.
       
    44     // Parameters are given in thousandths of radians.
       
    45     // SourceOrientationBase/ListenerLocationBase :
       
    46     //
       
    47     // NOTE: Effect API uses thousandths of radians for all three parameters,
       
    48     // but JSR234 uses degrees.
       
    49     //
       
    50     // From e32Math.h: The multiplying factor to convert degrees to radians.
       
    51 
       
    52     DEBUG_INT3("AMMS::CAMMSOrientationControl::SetOrientationL: %d, %d, %d",
       
    53                aHeading, aPitch, aRoll);
       
    54 
       
    55     TInt32 convertedHeading = (TInt32)(aHeading * KDegToRad *
       
    56                                        1000);   // CSI: 47 Effect API uses thousands of radians #
       
    57 
       
    58     TInt32 convertedPitch = (TInt32)(aPitch * KDegToRad *
       
    59                                      1000);   // CSI: 47 Effect API uses thousands of radians #
       
    60 
       
    61     TInt32 convertedRoll = (TInt32)(aRoll * KDegToRad *
       
    62                                     1000);   // CSI: 47 Effect API uses thousands of radians #
       
    63 
       
    64     DEBUG_INT3("AMMS::CAMMSOrientationControl::SetOrientationL: %d, %d, %d",
       
    65                convertedHeading, convertedPitch, convertedRoll);
       
    66 
       
    67     iOrientationEffect->SetOrientationL(
       
    68         convertedHeading, convertedPitch, convertedRoll);
       
    69 
       
    70     // Apply updated settings to Effect API.
       
    71     iOrientationEffect->ApplyL();
       
    72 }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CAMMSOrientationControl::SetOrientationL
       
    76 // Turns the object to the new orientation.
       
    77 // -----------------------------------------------------------------------------
       
    78 void CAMMSOrientationControl::SetOrientationL(
       
    79     TInt aFrontX, TInt aFrontY, TInt aFrontZ,
       
    80     TInt aAboveX, TInt aAboveY, TInt aAboveZ)
       
    81 {
       
    82     // Check in debug build that parameters are not zero vectors.
       
    83     __ASSERT_DEBUG(((aFrontX != 0) ||
       
    84                     (aFrontY != 0) ||
       
    85                     (aFrontZ != 0)) &&
       
    86                    ((aAboveX != 0) ||
       
    87                     (aAboveY != 0) ||
       
    88                     (aAboveZ != 0)),
       
    89                    User::Invariant());
       
    90 
       
    91     // Check in debug build that vectors are not parallel.
       
    92     // Two vectors are parallel if their cross product is zero vector.
       
    93     // Cross product of vectors a1*i + a2*j + a3*k and b1*i + b2*j + b3*k :
       
    94     // (a2*b3 - a3*b2)i + (a3*b1 - a1*b3)j + (a1*b2 - a2*b1)k
       
    95     __ASSERT_DEBUG(
       
    96         ((aFrontY * aAboveZ) - (aFrontZ * aAboveY) != 0) ||
       
    97         ((aFrontZ * aAboveX) - (aFrontX * aAboveZ) != 0) ||
       
    98         ((aFrontX * aAboveY) - (aFrontY * aAboveX) != 0),
       
    99         User::Invariant());
       
   100 
       
   101     // Sets the Front and Above vectors for the orientation of the source/listener.
       
   102 
       
   103     DEBUG_INT3("AMMS::CAMMSOrientationControl::SetOrientationL: Front %d, %d, %d",
       
   104                aFrontX, aFrontY, aFrontZ);
       
   105 
       
   106     DEBUG_INT3("AMMS::CAMMSOrientationControl::SetOrientationL: Above %d, %d, %d",
       
   107                aAboveX, aAboveY, aAboveZ);
       
   108 
       
   109     iOrientationEffect->SetOrientationVectorsL(
       
   110         (TInt32)aFrontX, (TInt32)aFrontY, (TInt32)aFrontZ,
       
   111         (TInt32)aAboveX, (TInt32)aAboveY, (TInt32)aAboveZ);
       
   112 
       
   113     // Apply updated settings to Effect API.
       
   114     iOrientationEffect->ApplyL();
       
   115 }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CAMMSOrientationControl::OrientationVectors
       
   119 // Gets the orientation of the object using two vectors.
       
   120 // -----------------------------------------------------------------------------
       
   121 void CAMMSOrientationControl::OrientationVectors(
       
   122     TInt& aFrontX, TInt& aFrontY, TInt& aFrontZ,
       
   123     TInt& aAboveX, TInt& aAboveY, TInt& aAboveZ)
       
   124 {
       
   125     // Gets the orientation of the source.
       
   126 
       
   127     iOrientationEffect->OrientationVectors(
       
   128         (TInt32&)aFrontX, (TInt32&)aFrontY, (TInt32&)aFrontZ,
       
   129         (TInt32&)aAboveX, (TInt32&)aAboveY, (TInt32&)aAboveZ);
       
   130 }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CAMMSOrientationControl::CAMMSOrientationControl
       
   134 // C++ constructor can NOT contain any code, that
       
   135 // might leave.
       
   136 // -----------------------------------------------------------------------------
       
   137 CAMMSOrientationControl::CAMMSOrientationControl(CMMAPlayer* aPlayer)
       
   138         : CAMMSControl(aPlayer)
       
   139 {
       
   140 }
       
   141 
       
   142 //  End of File