javauis/m3g_qt/src/jni/camera.inl
changeset 35 85266cc22c7f
equal deleted inserted replaced
26:dc7c549001d5 35:85266cc22c7f
       
     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 #include "javax_microedition_m3g_Camera.h"
       
    19 
       
    20 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Camera__1setPerspective
       
    21 (JNIEnv* aEnv, jclass, jint aHandle, jfloat aFovy, jfloat aAspectRatio, jfloat aNear, jfloat aFar)
       
    22 {
       
    23     M3G_DO_LOCK
       
    24     m3gSetPerspective((M3GCamera)aHandle, aFovy, aAspectRatio, aNear, aFar);
       
    25     M3G_DO_UNLOCK(aEnv)
       
    26 }
       
    27 
       
    28 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Camera__1setGeneric
       
    29 (JNIEnv* aEnv, jclass, jint aHandle, jbyteArray aTransform)
       
    30 {
       
    31     jbyte* elems = NULL;
       
    32     if (aTransform)
       
    33     {
       
    34         elems = aEnv->GetByteArrayElements(aTransform, NULL);
       
    35         if (elems == NULL)
       
    36         {
       
    37             M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
       
    38             return;
       
    39         }
       
    40     }
       
    41     M3G_DO_LOCK
       
    42     m3gSetProjectionMatrix((M3GCamera)aHandle,
       
    43                            (const M3GMatrix *)elems);
       
    44     M3G_DO_UNLOCK(aEnv)
       
    45     if (elems)
       
    46         aEnv->ReleaseByteArrayElements(aTransform, elems, 0);
       
    47 }
       
    48 
       
    49 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Camera__1getProjectionAsParams
       
    50 (JNIEnv* aEnv, jclass, jint aHandle, jfloatArray aParams)
       
    51 {
       
    52     jfloat* elems = NULL;
       
    53 
       
    54     if (aParams && aEnv->GetArrayLength(aParams) < 4)
       
    55     {
       
    56         M3G_RAISE_EXCEPTION(aEnv, "java/lang/IllegalArgumentException");
       
    57         return 0;
       
    58     }
       
    59     elems = NULL;
       
    60     if (aParams)
       
    61     {
       
    62         elems = aEnv->GetFloatArrayElements(aParams, NULL);
       
    63         if (elems == NULL)
       
    64         {
       
    65             M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
       
    66             return 0;
       
    67         }
       
    68     }
       
    69 
       
    70     M3G_DO_LOCK
       
    71     jint ret = m3gGetProjectionAsParams((M3GCamera)aHandle, (jfloat*)elems);
       
    72     M3G_DO_UNLOCK(aEnv)
       
    73 
       
    74     if (elems)
       
    75     {
       
    76         aEnv->ReleaseFloatArrayElements(aParams, elems, 0);
       
    77     }
       
    78 
       
    79     return ret;
       
    80 }
       
    81 
       
    82 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Camera__1setParallel
       
    83 (JNIEnv* aEnv, jclass, jint aHandle, jfloat aHeight, jfloat aAspectRatio, jfloat aNear, jfloat aFar)
       
    84 {
       
    85     M3G_DO_LOCK
       
    86     m3gSetParallel((M3GCamera)aHandle, aHeight, aAspectRatio, aNear, aFar);
       
    87     M3G_DO_UNLOCK(aEnv)
       
    88 }
       
    89 
       
    90 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Camera__1ctor
       
    91 (JNIEnv* aEnv, jclass, jint aM3g)
       
    92 {
       
    93     M3G_DO_LOCK
       
    94     jint handle = (jint)m3gCreateCamera((M3GInterface)aM3g);
       
    95     M3G_DO_UNLOCK(aEnv)
       
    96     return handle;
       
    97 }
       
    98 
       
    99 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Camera__1getProjectionAsTransform
       
   100 (JNIEnv* aEnv, jclass, jint aHandle, jbyteArray aTransform)
       
   101 {
       
   102     jbyte* elems = NULL;
       
   103     if (aTransform)
       
   104     {
       
   105         elems = aEnv->GetByteArrayElements(aTransform, NULL);
       
   106         if (elems == NULL)
       
   107         {
       
   108             M3G_RAISE_EXCEPTION(aEnv, "java/lang/OutOfMemoryError");
       
   109             return 0;
       
   110         }
       
   111     }
       
   112 
       
   113     M3G_DO_LOCK
       
   114     jint ret = m3gGetProjectionAsMatrix((M3GCamera)aHandle,
       
   115                                         (M3GMatrix *)elems);
       
   116     M3G_DO_UNLOCK(aEnv)
       
   117 
       
   118     if (elems)
       
   119         aEnv->ReleaseByteArrayElements(aTransform, elems, 0);
       
   120     return ret;
       
   121 }