/* ======================================================================================= Name : LgtLoad.c Description : fonction to load light (in script file) ======================================================================================= */ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ #include "acp_base.h" #include "MTH.h" #include "SCR.h" #include "POS.h" #include "GEO.h" #include "util.h" #include "color.h" #include "gld.h" #include "GLI_defn.h" #include "light.h" #include "LgtLoad.h" #include "DPT.h" /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /*these lines are to be removed*/ typedef struct GLI_tdstLight_* LGT_tdxHandleToLight; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ /* ======================================================================================= Function to access light link table ======================================================================================= */ SCR_tdst_Link_Table gs_stLightLinkTable; SCR_tdst_Link_Table *LGT_fn_p_stGetLightLinkTable() { return &gs_stLightLinkTable; } /* ======================================================================================= Init/End the light loading ======================================================================================= */ SCR_tde_Anl_ReturnValue LGT_fn_xLoadLight(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType); BOOL LGT_fn_bInitLGTLoading() { SCR_fn_v_RdL0_RegisterCallback("Light",LGT_fn_xLoadLight, SCR_CRC_c_RdL0_ForSection); SCR_fn_v_Link_InitTable(LGT_fn_p_stGetLightLinkTable()); return TRUE; } BOOL LGT_fn_bStopLGTLoading() { SCR_fn_v_Link_CloseTable(LGT_fn_p_stGetLightLinkTable()); return TRUE; } /* ======================================================================================= script callback function to load a ligth (analyse a ligth script section) ======================================================================================= */ SCR_tde_Anl_ReturnValue LGT_fn_xLoadLight(SCR_tdst_File_Description *p_fFile, char *szAction, char *szParams[], SCR_tde_Anl_Action cType) { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ LGT_tdxHandleToLight hLight,hNewLight; POS_tdstCompletePosition *p_stMatrix; long lOnOff; GEO_tdstColor stColor; long lTypeOfLight; char a255_cLongName[255]; MTH3D_tdstVector myGetVector; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ switch (cType) { case SCR_EA_Anl_BeginSection: if(strcmp(szParams[0],"Parallel")==0) lTypeOfLight = GLI_C_lParallelLight; else if(strcmp(szParams[0],"Spherical")==0) lTypeOfLight = GLI_C_lSphericalLight; else if(strcmp(szParams[0],"HotSpot")==0) lTypeOfLight = GLI_C_lHotSpotLight; else if(strcmp(szParams[0],"Ambient")==0) lTypeOfLight = GLI_C_lAmbientLight; else if(strcmp(szParams[0],"ParallelBox")==0) lTypeOfLight = GLI_C_lParallelLight_With_Limit; else if(strcmp(szParams[0],"Fog")==0) lTypeOfLight = GLI_C_lFogLight; GLI_xCreateLight(&hNewLight, lTypeOfLight); /* add new light in link table*/ SCR_M_RdL0_ComputeOpenSectionNameR(0,a255_cLongName); SCR_M_v_Link_SetAdditionalLong(SCR_fnp_st_Link_SetValue(LGT_fn_p_stGetLightLinkTable(), a255_cLongName, (unsigned long)hNewLight), 1, strlen(a255_cLongName)-strlen(SCR_M_RdL0_GetCompleteSectionNameR(0))); /* store new created ligth in section and context */ SCR_M_RdL0_SetSectionLong(0,0,hNewLight); SCR_M_RdL0_SetContextLong(0,0,hNewLight); break; case SCR_EA_Anl_Entry: /* retrieve created ligth in context*/ SCR_M_RdL0_GetContextLong(0,0,LGT_tdxHandleToLight,hLight); if (strcmp(szAction,"SetState")==0) { lOnOff=atoi(szParams[0]); GLI_xSetLightState(hLight, lOnOff); } else if (strcmp(szAction,"SetColor")==0) { stColor.xR=(GEO_tdxColorValue)atof(szParams[0]); stColor.xG=(GEO_tdxColorValue)atof(szParams[1]); stColor.xB=(GEO_tdxColorValue)atof(szParams[2]); stColor.xA=(GEO_tdxColorValue)atof(szParams[3]); GLI_xSetLightColor(hLight,&stColor); } else if (strcmp(szAction,"SetNearFar")==0) { GLI_vSetLightNearFar( hLight, MTH_M_xFloatToReal((float)atof(szParams[0])), MTH_M_xFloatToReal((float)atof(szParams[1]))); } else if (strcmp(szAction,"SetAlphas")==0) { GLI_vSetLightAlphas( hLight, MTH_M_xFloatToReal((float)atof(szParams[0])), MTH_M_xFloatToReal((float)atof(szParams[1]))); } else if (strcmp(szAction,"SetMatrix")==0) { SCR_tdst_Cxt_Values *p_stVal; p_stVal = SCR_fnp_st_RdL0_AnalyseSection(szParams[0], SCR_CDF_uw_Anl_Normal); p_stMatrix = (POS_tdstCompletePosition *)SCR_M_ul_RdL0_ExtractLongValue(p_stVal,0); GLI_xSetLightMatrix(hLight,p_stMatrix); /* ATTENTION : dans light il y a une matrix et non un pointeur sur matrix*/ /* La matrice est donc (sauvagement) recopiée.*/ /* En toute rigueur je devrais libérer p_stMatrix, mais, à terme,*/ /* je pense que light contiendra un pointeur (sigh...)*/ } else if (strcmp(szAction,"ObjectLighted")==0) { GLI_vSetObjectLighted(hLight,(unsigned char)atoi(szParams[0])); } else if (strcmp(szAction,"PaintLight")==0) { GLI_vSetPaintLight(hLight); } else if (strcmp(szAction,"NoAlphaLight")==0) { GLI_vSetAlphaLightFlag (hLight, 2); } else if (strcmp(szAction,"AlphaLight")==0) { GLI_vSetAlphaLight(hLight); } else if (strcmp(szAction, "SetInterMinPos")==0) { myGetVector.xX = MTH_M_xFloatToReal((float)atof(szParams[0])); myGetVector.xY = MTH_M_xFloatToReal((float)atof(szParams[1])); myGetVector.xZ = MTH_M_xFloatToReal((float)atof(szParams[2])); GLI_vSetLight_Inter_Min_Pos( hLight,myGetVector ); } else if (strcmp(szAction, "SetInterMaxPos")==0) { myGetVector.xX = MTH_M_xFloatToReal((float)atof(szParams[0])); myGetVector.xY = MTH_M_xFloatToReal((float)atof(szParams[1])); myGetVector.xZ = MTH_M_xFloatToReal((float)atof(szParams[2])); GLI_vSetLight_Inter_Max_Pos( hLight,myGetVector ); } else if (strcmp(szAction, "SetExterMinPos")==0) { myGetVector.xX = MTH_M_xFloatToReal((float)atof(szParams[0])); myGetVector.xY = MTH_M_xFloatToReal((float)atof(szParams[1])); myGetVector.xZ = MTH_M_xFloatToReal((float)atof(szParams[2])); GLI_vSetLight_Exter_Min_Pos( hLight,myGetVector ); } else if (strcmp(szAction, "SetExterMaxPos")==0) { myGetVector.xX = MTH_M_xFloatToReal((float)atof(szParams[0])); myGetVector.xY = MTH_M_xFloatToReal((float)atof(szParams[1])); myGetVector.xZ = MTH_M_xFloatToReal((float)atof(szParams[2])); GLI_vSetLight_Exter_Max_Pos( hLight,myGetVector ); } else if (strcmp(szAction, "SetIntensityMinMax")==0) { GLI_vSetLight_Intensity_Min_Max( hLight, MTH_M_xFloatToReal((float)atof(szParams[0])), MTH_M_xFloatToReal((float)atof(szParams[1]))); } else if (strcmp(szAction,"BackgroundColor")==0) { stColor.xR=(GEO_tdxColorValue)atof(szParams[0]); stColor.xG=(GEO_tdxColorValue)atof(szParams[1]); stColor.xB=(GEO_tdxColorValue)atof(szParams[2]); stColor.xA=(GEO_tdxColorValue)atof(szParams[3]); GLI_xSetLightBackgroundColor(hLight,&stColor); } break; case C_SCRIPT_EndSection: break; } return R_SCRIPT_NormalReturn; }