// (c) Ubi Studios 1996 // See Vincent Greco for any comment or question #include "stdafx.h" #ifdef ACTIVE_EDITOR #include "acp_base.h" #include "geo.h" #include "gli.h" #include "col.h" #define HieFriend #include "spo.h" #include "lst.hpp" #include "incgam.h" #undef HieFriend #include "x:\cpa\tempgrp\gliGLOU\MULTIDRV\inc\visus_st.h" #include "itf/CPASObjB.hpp" //temporary 3DOS header file include //#include "x:appli\3dos\inc\3dos\physicol.h" #include "pcs.h" #include "po.h" #include "ipo.h" #include "isi.h" DeclareTemplateStatic(HIE_tdxHandleToSuperObject); ACP_tdxHandleOfMaterial g_hMaterial; BOOL g_bMaterialInitialised = FALSE; extern ACP_tdxBool g_bShowCollisionMap; GLI_tdstColor TabColor[]= { {(float) 0.00, (float) 0.00, (float) 0.00, (float) 0.0},//E_lc_NoColor {(float) 0.8f, (float) 0.0f, (float) 0.0f, (float) 1.f},//E_lc_Red {(float) 0.00, (float) 0.99, (float) 0.00, (float) 0.0},//E_lc_Green {(float) 0.00, (float) 0.00, (float) 0.99, (float) 0.0},//E_lc_Blue {(float) 0.45, (float) 0.45, (float) 0.00, (float) 0.0},//E_lc_Yellow {(float) 0.45, (float) 0.00, (float) 0.99, (float) 0.0},//E_lc_Violet {(float) 0.00, (float) 0.45, (float) 0.99, (float) 0.0},//E_lc_LightBlue }; #define C_lLocalColorMask ( GLI_C_lAllIsEnable \ - GLI_C_lIsNotForceDefaultMaterial \ - GLI_C_lIsNotGrided \ - GLI_C_lIsUseStaticLights \ - GLI_C_lIsUseRLI) //######################################################################################## //######################################################################################## //######################################################################################## CPA_SuperObjectBase::CPA_SuperObjectBase (void) : CPA_EdNode() { m_eDrawingFlag = E_df_Normal; m_eColor = E_lc_NoColor; m_bMustDraw = TRUE; m_bDrawBV = FALSE; } //######################################################################################## //######################################################################################## //######################################################################################## CPA_SuperObjectBase::CPA_SuperObjectBase(HIE_tdxHandleToSuperObject hEngineSO) { SetStruct(hEngineSO); m_eDrawingFlag = E_df_Normal; m_eColor = E_lc_NoColor; m_bMustDraw = TRUE; m_bDrawBV = FALSE; } //ANNECY TQ 26/02/98{ //######################################################################################## //######################################################################################## //######################################################################################## //-------------------------------------------------------------------------------------- // Name : CreateParallelBoxGeometricObject // Author : Thierry QUERE // Date : 27/02/98 // Description : Creates an engine-geometric object to store the parallel box (bounding volume) // and to send it to the viewport //-------------------------------------------------------------------------------------- void CPA_SuperObjectBase::CreateParallelBoxGeometricObject() { ACP_tdxHandleOfElement hAlignedBoxes; GEO_vCreateGeometricObject(&s_hBoxGeomObj, 2 /* 2 points */, 1 /* 1 element */); GEO_vCreateElementAlignedBoxes(s_hBoxGeomObj, &hAlignedBoxes, 1); } void CPA_SuperObjectBase::DestroyParallelBoxGeometricObject() { GEO_vDeleteGeometricObject(&s_hBoxGeomObj); } //-------------------------------------------------------------------------------------- // Name : CreateBoundingSphereGeometricObject // Author : Thierry QUERE // Date : 03/06/98 // Description : Creates an engine-geometric object to store the BoundingSphere (bounding volume) // and to send it to the viewport //-------------------------------------------------------------------------------------- void CPA_SuperObjectBase::CreateBoundingSphereGeometricObject() { ACP_tdxHandleOfElement hSphere; GEO_vCreateGeometricObject(&s_hSphereGeomObj, 1 /* 1 point */, 1 /* 1 element */); GEO_vCreateElementSpheres(s_hSphereGeomObj, &hSphere, 1); } void CPA_SuperObjectBase::DestroyBoundingSphereGeometricObject() { GEO_vDeleteGeometricObject(&s_hSphereGeomObj); } //ENDANNECY TQ} //######################################################################################## //######################################################################################## //######################################################################################## void CPA_SuperObjectBase::Display(GLD_tdxHandleToViewportAttributes hVpt,long lDrawMask, tdstSaveLight a_tdxhArrayOfLights[], long lNbLights, HIE_tdxHandleToSuperObject pWorld, BOOL bUseLocalFlag) { HIE_tdxHandleToSuperObject pStruct; ACP_tdxHandleToRadiosity hRad; GEO_tdxHandleToBoundingSphere hBoundingSphere = NULL; GEO_tdxHandleToParallelBox hParallelBox = NULL; ACP_tdxHandleOfObject hBoundingVolume = NULL; HIE_tdxHandleToVoid hObject; CPA_SuperObjectBase * pChild; MTH3D_tdstVector stCenter; tdeLocalColor eCol; POSITION pos; long lLocalMask; unsigned long ulType; long lMask; long lIndex; MTH3D_tdstVector stMaxBoxPoint; MTH3D_tdstVector stMinBoxPoint; POS_tdstCompletePosition * p_stGlobalMatrix; POS_tdstCompletePosition stIdentityMatrix; float fGlobalAlphaTemp ; float fTransp, fTransparency = -1.0; ACP_tdxBool bDummy; // draw only valid objects if (!m_bMustDraw) return; if (!g_bMaterialInitialised) { GLI_xCreateMaterial(&g_hMaterial); GLI_xSetMaterialType(g_hMaterial, C_lGouraudElement); g_bMaterialInitialised = TRUE; } // init parameters pStruct = (HIE_tdxHandleToSuperObject) GetSuperObjectStruct(); eCol = GetLocalColor(); // init matrix HIE_fn_vPushMatrix (pStruct); HIE_fn_vPushOnCameraMatrixStack (pStruct); // selection drawing : no light ! if (eCol != E_lc_NoColor) { for (lIndex = 0; lIndex < lNbLights; lIndex++) GLI_xSetLightState(a_tdxhArrayOfLights[lIndex].hLight, 0); } // local mask lLocalMask = (eCol == E_lc_NoColor) ? lDrawMask : lDrawMask & C_lLocalColorMask ; //ANNECY VL PRT 08/04/98{ // avoid sinus effect while in editor mode lLocalMask |= GLI_C_lHasNotSinusEffect; //ENDANNECY VL} // default material GLI_xSetMaterialAmbientCoef (g_hMaterial, TabColor+eCol); GLI_vSetDefaultMaterial(hVpt, g_hMaterial); // local drawing flag if (bUseLocalFlag) { switch (m_eDrawingFlag) { case E_df_BoundingV: lLocalMask &= ~GLI_C_lIsNotDrawingSuperObjectBoundingVolume; break; case E_df_Grided: lLocalMask &= ~GLI_C_lIsNotGrided; break; case E_df_Wired: lLocalMask &= ~GLI_C_lIsNotWired; break; } } if (m_bDrawBV) lLocalMask &= ~GLI_C_lIsNotDrawingSuperObjectBoundingVolume; fTransp = HIE_fn_fGetSuperObjectTransparenceLevel(pStruct); if (( eCol != E_lc_NoColor) || ((fTransp < 30.0) && (fTransp > 0.0)) || ( bUseLocalFlag && (m_eDrawingFlag == E_df_Grided)) || !(HIE_fn_lGetSuperObjectDrawMask(pWorld) & GLI_C_lIsNotGrided)) { fTransparency = fTransp; // minimal transparency if (fTransparency < 30.0 && fTransparency > 0.0) HIE_fn_vSetSuperObjectTransparenceLevel(pStruct, 30.0); if (eCol == E_lc_NoColor) { if (fTransparency > 200.0) HIE_fn_vSetSuperObjectTransparenceLevel(pStruct, (float) (fTransparency - 100.0)); else if (fTransparency > 100.0) HIE_fn_vSetSuperObjectTransparenceLevel(pStruct, 100.0); } else HIE_fn_vSetSuperObjectTransparenceLevel(pStruct, 128.0); } // parameters ulType = HIE_fn_ulGetSuperObjectType(pStruct); lMask = HIE_fn_lGetSuperObjectDrawMask(pStruct); // avoid sinus effect while in editor mode lMask |= GLI_C_lHasNotSinusEffect; hObject = HIE_fn_hGetSuperObjectObject(pStruct); // bounding volume hParallelBox = (GEO_tdxHandleToParallelBox)HIE_fn_hGetSuperObjectBoundingVolume(pStruct); if (hParallelBox && HIE_fn_SO_bHasABoxBoundingVolume (pStruct)) { p_stGlobalMatrix = HIE_fn_hGetSuperObjectGlobalMatrix(pStruct); MTH3D_M_vAddVector(&stMaxBoxPoint, &p_stGlobalMatrix->stTranslationVector, GEO_fn_pGetMaxPointOfParallelBox(hParallelBox)); MTH3D_M_vAddVector(&stMinBoxPoint, &p_stGlobalMatrix->stTranslationVector, GEO_fn_pGetMinPointOfParallelBox(hParallelBox)); GEO_vSetPointOfObject (s_hBoxGeomObj, &stMaxBoxPoint, 1); GEO_vSetPointOfObject (s_hBoxGeomObj, &stMinBoxPoint, 0); GEO_vSetMinMaxPointOfIndexedAlignedBox( s_hBoxGeomObj, 0, /* First element */ 0, /* First Aligned box of the element */ 0, /* First point = Max */ 1);/* Second point = Min */ hBoundingVolume = s_hBoxGeomObj; } else { hBoundingSphere = (GEO_tdxHandleToBoundingSphere)HIE_fn_hGetSuperObjectBoundingVolume(pStruct); if ((hBoundingSphere) && (!HIE_fn_SO_bHasABoxBoundingVolume(pStruct))) { MTH3D_M_vCopyVector(&stCenter, GEO_fn_pGetCenterPointOfBoundingSphere(hBoundingSphere)); GEO_vSetPointOfObject( s_hSphereGeomObj, GEO_fn_pGetCenterPointOfBoundingSphere(hBoundingSphere), 0); GEO_vSetCenterPointOfIndexedSphere ( s_hSphereGeomObj, 0, /* First Element */ 0, /* First Sphere of the element */ 0); /* First Point */ GEO_vSetRadiusOfIndexedSphere ( s_hSphereGeomObj, 0, /* First Element */ 0, /* First Sphere of the element */ GEO_fn_xGetRadiusOfBoundingSphere(hBoundingSphere) ); hBoundingVolume = s_hSphereGeomObj; } } // draw geometric object if (ulType & (HIE_C_ulEDT_Geometric | HIE_C_ulSpecialEffect)) { POS_tdstCompletePosition *p_stCurrentMatrix; if((MTH_M_bEqual(GEO_xGetElementType((ACP_tdxHandleOfObject)hObject, 0), GEO_C_xElementAlignedBoxes)) && (fn_bHasALinkedZDM() == TRUE)) { /* The points have not the translation of the object ... */ MTH3D_M_vAddVector(&((ACP_tdxHandleOfObject)hObject)->d_stListOfPoints[0], &pStruct->hGlobalMatrix->stTranslationVector, &((ACP_tdxHandleOfObject)hObject)->d_stListOfPoints[0]); MTH3D_M_vAddVector(&((ACP_tdxHandleOfObject)hObject)->d_stListOfPoints[1], &pStruct->hGlobalMatrix->stTranslationVector, &((ACP_tdxHandleOfObject)hObject)->d_stListOfPoints[1]); POS_fn_vSetIdentityMatrix(&stIdentityMatrix); HIE_fn_bLoadMatrix (&stIdentityMatrix); // update camera matrix p_stCurrentMatrix = HIE_fn_pGetCurrentInCamCoordsMatrix(); HIE_fn_vSetCurrentInCamCoordsMatrix(&((( GLI_tdstSpecificAttributesFor3D *)hVpt->p_vSpecificToXD)->p_stCam)->stMatrix); } fGlobalAlphaTemp = GLI_vGetGlobalAlpha(); GLI_vSetGlobalAlpha( HIE_fn_fGetSuperObjectTransparenceLevel(pStruct) ); GLI_xSendObjectToViewportWithLights(hVpt, (ACP_tdxHandleOfObject)hObject, lMask&lLocalMask); if (eCol != E_lc_NoColor) GLI_xSendObjectToViewportWithLights(hVpt, (ACP_tdxHandleOfObject)hObject, (lMask&lLocalMask) - GLI_C_lIsNotWired); GLI_vSetGlobalAlpha (fGlobalAlphaTemp) ; // Please, do not alter the following line without contacting Thierry QUERE // Annecy if((MTH_M_bEqual(GEO_xGetElementType((ACP_tdxHandleOfObject)hObject, 0), GEO_C_xElementAlignedBoxes)) && (fn_bHasALinkedZDM() == TRUE)) { HIE_fn_vPopMatrix (); // update camera matrix HIE_fn_vSetCurrentInCamCoordsMatrix(p_stCurrentMatrix); //HIE_fn_vPopOnCameraMatrixStack (); MTH3D_M_vSubVector(&((ACP_tdxHandleOfObject)hObject)->d_stListOfPoints[0], &((ACP_tdxHandleOfObject)hObject)->d_stListOfPoints[0], &pStruct->hGlobalMatrix->stTranslationVector); MTH3D_M_vSubVector(&((ACP_tdxHandleOfObject)hObject)->d_stListOfPoints[1], &((ACP_tdxHandleOfObject)hObject)->d_stListOfPoints[1], &pStruct->hGlobalMatrix->stTranslationVector); } } // draw physical object if ((ulType == HIE_C_ulPO) || (ulType == HIE_C_ulPO_Mirror)) { PO_tdxHandleToPhysicalObject hPO = (PO_tdxHandleToPhysicalObject) hObject; // get bounding volume and center if (!HIE_fn_SO_bHasABoxBoundingVolume (pStruct)) hBoundingSphere = PO_fn_hGetBoundingVolume(hPO); if ((hBoundingSphere) && (!HIE_fn_SO_bHasABoxBoundingVolume(pStruct))) { MTH3D_M_vCopyVector(&stCenter, GEO_fn_pGetCenterPointOfBoundingSphere(hBoundingSphere)); GEO_vSetPointOfObject( s_hSphereGeomObj, GEO_fn_pGetCenterPointOfBoundingSphere(hBoundingSphere), 0); GEO_vSetCenterPointOfIndexedSphere ( s_hSphereGeomObj, 0, /* First Element */ 0, /* First Sphere of the element */ 0); /* First Point */ GEO_vSetRadiusOfIndexedSphere ( s_hSphereGeomObj, 0, /* First Element */ 0, /* First Sphere of the element */ GEO_fn_xGetRadiusOfBoundingSphere(hBoundingSphere) ); hBoundingVolume = s_hSphereGeomObj; } else if ((!hBoundingSphere) && (!HIE_fn_SO_bHasABoxBoundingVolume(pStruct))) MTH3D_M_vNullVector(&stCenter); fGlobalAlphaTemp = GLI_vGetGlobalAlpha(); GLI_vSetGlobalAlpha( HIE_fn_fGetSuperObjectTransparenceLevel(pStruct) ); //--- Display collision map --- if(g_bShowCollisionMap) { if(PO_fn_hGetCollideSet(hPO)) { if(PCS_fn_hGetZdrGeoObjOfPhysicalCollSet(PO_fn_hGetCollideSet(hPO))) GLI_xSendObjectToViewportWithLights(hVpt, PCS_fn_hGetZdrGeoObjOfPhysicalCollSet(PO_fn_hGetCollideSet(hPO)), lMask&lLocalMask); } } else //--- Display graphical map --- { GLI_lSendVisualSetToViewport2(hVpt, PO_fn_hGetVisualSet(hPO), &stCenter, lMask&lLocalMask); if (eCol != E_lc_NoColor) GLI_lSendVisualSetToViewport2(hVpt, PO_fn_hGetVisualSet(hPO), &stCenter, (lMask&lLocalMask) - GLI_C_lIsNotWired); GLI_vSetGlobalAlpha (fGlobalAlphaTemp) ; } } // draw instanciated physical object if (ulType & (HIE_C_ulIPO | HIE_C_ulIPO_Mirror)) { IPO_tdxHandleToInstanciatedPhysicalObject hIPO = (IPO_tdxHandleToInstanciatedPhysicalObject) hObject; PO_tdxHandleToPhysicalObject hPO = IPO_fn_hGetPhysicalObject(hIPO); // get bounding volume and center if (!HIE_fn_SO_bHasABoxBoundingVolume (pStruct)) hBoundingSphere = PO_fn_hGetBoundingVolume(hPO); //ANNECY TQ 27/02/98{ if ((hBoundingSphere) && (!HIE_fn_SO_bHasABoxBoundingVolume(pStruct))) { MTH3D_M_vCopyVector(&stCenter, GEO_fn_pGetCenterPointOfBoundingSphere(hBoundingSphere)); GEO_vSetPointOfObject( s_hSphereGeomObj, GEO_fn_pGetCenterPointOfBoundingSphere(hBoundingSphere), 0); GEO_vSetCenterPointOfIndexedSphere ( s_hSphereGeomObj, 0, /* First Element */ 0, /* First Sphere of the element */ 0); /* First Point */ GEO_vSetRadiusOfIndexedSphere ( s_hSphereGeomObj, 0, /* First Element */ 0, /* First Sphere of the element */ GEO_fn_xGetRadiusOfBoundingSphere(hBoundingSphere) ); hBoundingVolume = s_hSphereGeomObj; } else if (HIE_fn_SO_bHasABoxBoundingVolume(pStruct)) { MTH3D_tdstVector * p_stMinPoint = GEO_fn_pGetMinPointOfParallelBox ((GEO_tdstParallelBox *) HIE_fn_hGetSuperObjectBoundingVolume (pStruct)); MTH3D_tdstVector * p_stMaxPoint = GEO_fn_pGetMaxPointOfParallelBox ((GEO_tdstParallelBox *) HIE_fn_hGetSuperObjectBoundingVolume (pStruct)); MTH3D_M_vMiddleVector (&stCenter , p_stMinPoint , p_stMaxPoint); } //ENDANNECY TQ} fGlobalAlphaTemp = GLI_vGetGlobalAlpha(); GLI_vSetGlobalAlpha( HIE_fn_fGetSuperObjectTransparenceLevel(pStruct) ); // get RLI parameters hRad = IPO_fn_hGetRadiosity(hIPO); //--- Display Collision Map --- if(g_bShowCollisionMap) { if(PO_fn_hGetCollideSet(hPO)) { if(PCS_fn_hGetZdrGeoObjOfPhysicalCollSet(PO_fn_hGetCollideSet(hPO))) GLI_xSendObjectToViewportWithLights(hVpt, PCS_fn_hGetZdrGeoObjOfPhysicalCollSet(PO_fn_hGetCollideSet(hPO)), lMask&lLocalMask); } } else //--- Display Graphical Map --- { GLI_lSendVisualSetToViewportWithRLI2(hVpt, PO_fn_hGetVisualSet(hPO), &stCenter, lMask&lLocalMask, hRad/*dColor*/); if (eCol != E_lc_NoColor) GLI_lSendVisualSetToViewportWithRLI2(hVpt, PO_fn_hGetVisualSet(hPO), &stCenter, (lMask&lLocalMask) - GLI_C_lIsNotWired, hRad /*dColor*/); } } GLI_vSetGlobalAlpha (fGlobalAlphaTemp) ; /* The matrix that is on the top of the pile is currently the global matrix of the object */ /* This matrix is used by the viewport to know in what axis system the coordinates he receives are */ /* When the bounding volume is a sphere, the matrix on the top MUST be the gobal matrix because the center and the radius are computed in the local axis system of the object, */ /* but, unfortunatly, for the parallel boxes where everything is computed in the global axis system, the matrix on the top must be the identity matrix */ // draw bounding volume if (hBoundingVolume && (HIE_fn_SO_bHasABoxBoundingVolume(pStruct)) && !(lLocalMask & GLI_C_lIsNotDrawingSuperObjectBoundingVolume)) { POS_tdstCompletePosition *p_stCurrentMatrix; POS_fn_vSetIdentityMatrix(&stIdentityMatrix); HIE_fn_bLoadMatrix (&stIdentityMatrix); // update camera matrix p_stCurrentMatrix = HIE_fn_pGetCurrentInCamCoordsMatrix(); HIE_fn_vSetCurrentInCamCoordsMatrix(&((( GLI_tdstSpecificAttributesFor3D *)hVpt->p_vSpecificToXD)->p_stCam)->stMatrix); GLI_xSendObjectToViewportWithLights(hVpt, hBoundingVolume, lMask & lDrawMask &~GLI_C_lIsNotWired &~GLI_C_lIsNotDrawCollideInformation); HIE_fn_vPopMatrix (); // update camera matrix HIE_fn_vSetCurrentInCamCoordsMatrix(p_stCurrentMatrix); //HIE_fn_vPopOnCameraMatrixStack(); } else if(hBoundingVolume&&!(lLocalMask &GLI_C_lIsNotDrawingSuperObjectBoundingVolume)) GLI_xSendObjectToViewportWithLights(hVpt, hBoundingVolume, lMask & lDrawMask &~GLI_C_lIsNotWired &~GLI_C_lIsNotDrawCollideInformation); // reset lights if (eCol != E_lc_NoColor) { for (lIndex = 0; lIndex < lNbLights; lIndex++) GLI_xSetLightState(a_tdxhArrayOfLights[lIndex].hLight, a_tdxhArrayOfLights[lIndex].lInitialState); } if (fTransparency >= 0.0) { HIE_fn_vSetSuperObjectTransparenceLevel(pStruct, fTransparency); } // recursive function if (HIE_fn_ulGetSuperObjectType(pStruct)==HIE_C_ulActor) { GLI_tdxHandleToLight hLight=HIE_fn_hGetSuperObjectLight(pStruct); if(hLight) { if (HIE_fn_bGetSuperObjectExcluLight(pStruct)) GLI_xSetViewportLightsOnOff(0); GLI_vAddLightToViewport(hVpt,hLight); } bDummy = g_bShowCollisionMap; g_bShowCollisionMap = FALSE; M_ForAllTheElementsInList(pChild, this, pos) pChild->Display(hVpt, HIE_fn_lGetSuperObjectDrawMask(pStruct), a_tdxhArrayOfLights, lNbLights, pWorld, bUseLocalFlag); g_bShowCollisionMap = bDummy; if(hLight) { GLI_vPopLightsInViewport(hVpt , 1); if (HIE_fn_bGetSuperObjectExcluLight(pStruct)) GLI_xSetViewportLightsOnOff(1); } } else M_ForAllTheElementsInList(pChild, this, pos) pChild->Display(hVpt, HIE_fn_lGetSuperObjectDrawMask(pStruct)&lDrawMask, a_tdxhArrayOfLights, lNbLights, pWorld, bUseLocalFlag); HIE_fn_vPopMatrix (); HIE_fn_vPopOnCameraMatrixStack (); } //######################################################################################## //######################################################################################## //######################################################################################## void CPA_SuperObjectBase::DisplayWorld(GLD_tdxHandleToViewportAttributes hVpt, tdstSaveLight a_tdxhArrayOfLights[], long lNbLights, BOOL bUseLocalMask) { GEO_tdstColor stColor; // default material GLI_xCreateMaterial(&g_hMaterial); stColor.xR = (float) 0.99; stColor.xG = (float) 0.99; stColor.xB = (float) 0.99; GLI_xSetMaterialAmbientCoef (g_hMaterial, &stColor); GLI_xSetMaterialType(g_hMaterial, C_lGouraudElement); GLI_vSetDefaultMaterial(hVpt, g_hMaterial); // reinit matrix HIE_fn_vInitMatrixStack(); if( HIE_fn_bInitCameraMatrixStack(hVpt) == OK) { // display world (recursive function) Display(hVpt, GLI_C_lAllIsEnable&(GLI_C_lIsNotDrawCollideInformation^0xffffffff), a_tdxhArrayOfLights, lNbLights, (HIE_tdxHandleToSuperObject) GetSuperObjectStruct(), bUseLocalMask); } } // FBF 01 04 98 { void CPA_SuperObjectBase::SetLocalColor (tdeLocalColor eNewColor) { m_eColor = eNewColor; } // FBF 01 04 98} #endif // ACTIVE_EDITOR