⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m3gmorphingmesh.c

📁 java 1.1 gemini 08_16
💻 C
字号:
/*******************************************************************************
 *  Modification Notice:
 *  --------------------------
 *  This software is modified by MediaTek Inc. and the information contained
 *  herein is confidential. The software may not be copied and the information
 *  contained herein may not be used or disclosed except with the written
 *  permission of MediaTek Inc. (C) 2001
 *
 *******************************************************************************/

/*****************************************************************************
 *
 * Filename:
 * ---------
 *  MorphingMesh.c
 *
 * Project:
 * --------
 *   Maui_Software
 *
 * Description:
 * ------------
 *   
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/

/****************************************************************************
 Include Header Files
****************************************************************************/
#include "m3g.h"

#ifdef SUPPORT_JSR_184
/****************************************************************************
 Function Definition
****************************************************************************/
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_m3g_MorphingMesh_createMultiSubmesh()
{
	st_m3g_vertexbuffer* vb = (st_m3g_vertexbuffer*)KNI_GetParameterAsInt(1);
	st_m3g_morphingmesh* handle = NULL;
	int submesh_count, i;

	KNI_StartHandles(3);
	KNI_DeclareHandle(target_handle);
	KNI_DeclareHandle(ib_handle);
	KNI_DeclareHandle(ap_handle);
	KNI_GetParameterAsObject(2, target_handle);
	KNI_GetParameterAsObject(3, ib_handle);
	KNI_GetParameterAsObject(4, ap_handle);

#if FAST_KNI && defined(CLDCHI)
	if(vb==NULL || *target_handle==NULL || *ib_handle==NULL) {
		KNI_ThrowNew("java/lang/NullPointerException", "null handle");
	} else {
		jint_array* targets = (jint_array*)*target_handle;
		jint_array* ibs = (jint_array*)*ib_handle;
		jint_array* aps = (jint_array*)*ap_handle;

		submesh_count = ibs->length;
		if((aps && aps->length<submesh_count) || submesh_count==0 || targets->length==0) {
			KNI_ThrowNew("java/lang/IllegalArgumentException", "Invalid submeshs");
		} else {
			for(i=0; i<submesh_count; i++) {
				if(ibs->elements[i] == 0) {
					KNI_ThrowNew("java/lang/NullPointerException", "Invalid submeshs");
					goto _return;
				}
			}

			for(i=0; i<targets->length; i++) {
				if(targets->elements[i] == 0) {
					KNI_ThrowNew("java/lang/NullPointerException", "Invalid submeshs");
					goto _return;
				}
			}

			ENTER_M3D_CS;
			if(aps == NULL) {
				handle = M3G_MorphingMesh_new(vb, targets->length, (st_m3g_vertexbuffer**)targets->elements, 
											  submesh_count, (st_m3g_trianglestriparray**)ibs->elements, 
											  (st_m3g_appearance**)NULL);
			} else {
				handle = M3G_MorphingMesh_new(vb, targets->length, (st_m3g_vertexbuffer**)targets->elements, 
											  submesh_count, (st_m3g_trianglestriparray**)ibs->elements, 
											  (st_m3g_appearance**)aps->elements);
			}
			LEAVE_M3D_CS;
		}
	}
#else
	ASSERT(0);
#endif /* FAST_KNI */

_return:
	KNI_EndHandles();
	KNI_ReturnInt((jint)handle);
}

KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_m3g_MorphingMesh_createSingleSubmesh()
{
	st_m3g_vertexbuffer* vb = (st_m3g_vertexbuffer*)KNI_GetParameterAsInt(1);
	st_m3g_indexbuffer* ib = (st_m3g_indexbuffer*)KNI_GetParameterAsInt(3);
	st_m3g_appearance* ap = (st_m3g_appearance*)KNI_GetParameterAsInt(4);
	st_m3g_morphingmesh* handle = NULL;
	int i;

	KNI_StartHandles(1);
	KNI_DeclareHandle(target_handle);
	KNI_GetParameterAsObject(2, target_handle);

#if FAST_KNI && defined(CLDCHI)
	if(vb==NULL || *target_handle==NULL) {
		KNI_ThrowNew("java/lang/NullPointerException", "null handle");
	} else {
		jint_array* targets = (jint_array*)*target_handle;

		if(targets->length==0) {
			KNI_ThrowNew("java/lang/IllegalArgumentException", "Invalid submeshs");
		} else {
			for(i=0; i<targets->length; i++) {
				if(targets->elements[i] == 0) {
					KNI_ThrowNew("java/lang/NullPointerException", "Invalid submeshs");
					goto _return;
				}
			}

			ENTER_M3D_CS;
			handle = M3G_MorphingMesh_new(vb, targets->length, (st_m3g_vertexbuffer**)targets->elements, 1, 
										  (st_m3g_trianglestriparray**)&ib, (st_m3g_appearance**)&ap);
			LEAVE_M3D_CS;
		}
	}
#else
	ASSERT(0);
#endif /* FAST_KNI */

_return:
	KNI_EndHandles();
	KNI_ReturnInt((jint)handle);

}

KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_m3g_MorphingMesh_getMorphTargetCountImpl()
{
	st_m3g_morphingmesh* handle = (st_m3g_morphingmesh*)KNI_GetParameterAsInt(1);

	if(handle == NULL) {
		KNI_ThrowNew("java/lang/NullPointerException", "null handle");
		KNI_ReturnInt(0);
	} else {
		//KNI_ReturnInt((jint)handle->morphtarget_count);
		KNI_ReturnInt((jint)M3G_MorphingMesh_getMorphTargetCount(handle));
	}
}

KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_m3g_MorphingMesh_getMorphTargetImpl()
{
	st_m3g_morphingmesh* handle = (st_m3g_morphingmesh*)KNI_GetParameterAsInt(1);
	jint index = KNI_GetParameterAsInt(2);

	if(handle == NULL) {
		KNI_ThrowNew("java/lang/NullPointerException", "null handle");
		KNI_ReturnInt(0);
	} else if (index<0 || index>=handle->morphtarget_count) {
		KNI_ThrowNew("java/lang/IndexOutOfBoundsException", "invalid target");
		KNI_ReturnInt(0);
	} else {
		//KNI_ReturnInt((jint)handle->morph_target[index]);
		KNI_ReturnInt((jint)M3G_MorphingMesh_getMorphTarget(handle,index));
	}
}

KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_m3g_MorphingMesh_getWeightsImpl()
{
	st_m3g_morphingmesh* handle = (st_m3g_morphingmesh*)KNI_GetParameterAsInt(1);

	KNI_StartHandles(1);
	KNI_DeclareHandle(array_handle);
	KNI_GetParameterAsObject(2, array_handle);

#if FAST_KNI && defined(CLDCHI)
	if(*array_handle==NULL) {
		KNI_ThrowNew("java/lang/NullPointerException", "null handle");
	} else {
		jint_array* array = (jint_array*)*array_handle;

		if(array->length < handle->morphtarget_count) {
			KNI_ThrowNew("java/lang/IllegalArgumentException", "invalid weight");
		} else {
		    
			//memcpy(array->elements, handle->initial_weight, 
			//	handle->morphtarget_count*sizeof(float));
			M3G_MorphingMesh_getWeights(handle,(float*)array->elements);
		}
	}
#else
	ASSERT(0);
#endif /* FAST_KNI */

	KNI_EndHandles();

	KNI_ReturnVoid();
}

KNIEXPORT KNI_RETURNTYPE_VOID
Java_javax_microedition_m3g_MorphingMesh_setWeightsImpl()
{
	st_m3g_morphingmesh* handle = (st_m3g_morphingmesh*)KNI_GetParameterAsInt(1);

	KNI_StartHandles(1);
	KNI_DeclareHandle(array_handle);
	KNI_GetParameterAsObject(2, array_handle);

#if FAST_KNI && defined(CLDCHI)
	if(*array_handle==NULL) {
		KNI_ThrowNew("java/lang/NullPointerException", "null handle");
	} else {
		jint_array* array = (jint_array*)*array_handle;

		if(array->length < handle->morphtarget_count) {
			KNI_ThrowNew("java/lang/IllegalArgumentException", "invalid weight");
		} else {
			memcpy(handle->initial_weight, array->elements, handle->morphtarget_count*sizeof(float));
			M3G_MorphingMesh_setWeights(handle, handle->initial_weight);
		}
	}
#else
	ASSERT(0);
#endif /* FAST_KNI */

	KNI_EndHandles();

	KNI_ReturnVoid();
}
#endif /* #ifdef SUPPORT_JSR_184 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -