//======================================================================================== // geCamera_FillDriverInfo // HACK!!!! //======================================================================================== void geCamera_FillDriverInfo(geCamera *Camera) { // this is for the software driver to cache out some stuff #pragma message ("Camera.c : remove _FillDriverInfo, and thereby GlobalInfo!" ) extern GInfo GlobalInfo; assert(Camera); GlobalInfo.XScale =-Camera->Scale; GlobalInfo.YScale =-Camera->Scale; GlobalInfo.XScaleInv =1.0f / GlobalInfo.XScale; GlobalInfo.YScaleInv =1.0f / GlobalInfo.YScale; GlobalInfo.XCenter =Camera->XCenter; GlobalInfo.YCenter =Camera->YCenter; // Temp hack GlobalInfo.CXForm =Camera->XForm; GlobalInfo.Pov =Camera->Pov; GlobalInfo.ZScale =Camera->ZScale; geXForm3d_Rotate(&Camera->XForm, &GlobalInfo.Pov, &GlobalInfo.CPov); }
//======================================================================================== // geCamera_ConvertWorldSpaceToCameraSpace // Converts a worldspace Xform to a cameraspace xform //======================================================================================== GENESISAPI geBoolean GENESISCC geCamera_ConvertWorldSpaceToCameraSpace(const geXForm3d *WXForm, geXForm3d *CXForm) { // The rotation portion is just the transpose of the model xform CXForm->AX = WXForm->AX; CXForm->AY = WXForm->BX; CXForm->AZ = WXForm->CX; CXForm->BX = WXForm->AY; CXForm->BY = WXForm->BY; CXForm->BZ = WXForm->CY; CXForm->CX = WXForm->AZ; CXForm->CY = WXForm->BZ; CXForm->CZ = WXForm->CZ; CXForm->Translation = WXForm->Translation; geVec3d_Inverse(&CXForm->Translation); // Rotate the translation in the new camera matrix geXForm3d_Rotate(CXForm, &CXForm->Translation, &CXForm->Translation); return GE_TRUE; }
Brush *BrushTemplate_CreateCylinder (const BrushTemplate_Cylinder *pTemplate) { double CurrentXDiameter, CurrentZDiameter; double DeltaXDiameter, DeltaZDiameter; double CurrentXOffset, CurrentZOffset; double DeltaXOffset, DeltaZOffset, sqrcheck; double EllipseZ; int NumVerticalBands, HBand, VBand; int VertexCount=0; geVec3d *Verts, *TopPoints; geVec3d Current, Final, Delta; geXForm3d YRotation; FaceList *fl; Face *f; Brush *b; NumVerticalBands = (int)(pTemplate->VerticalStripes); if (NumVerticalBands < 3) { return NULL; } Verts =(geVec3d *)geRam_Allocate(sizeof(geVec3d)*NumVerticalBands * 2); TopPoints =(geVec3d *)geRam_Allocate(sizeof(geVec3d)*NumVerticalBands); fl =FaceList_Create(NumVerticalBands + 2); if(!Verts || !TopPoints ||!fl) { return NULL; } geXForm3d_SetIdentity(&YRotation); geXForm3d_SetYRotation(&YRotation, (M_PI * 2.0f)/(geFloat)NumVerticalBands); // Start with the top of cylinder CurrentXDiameter =pTemplate->TopXSize; CurrentZDiameter =pTemplate->TopZSize; DeltaXDiameter =(pTemplate->BotXSize - pTemplate->TopXSize); DeltaZDiameter =(pTemplate->BotZSize - pTemplate->TopZSize); // Get the offset amounts CurrentXOffset =pTemplate->TopXOffset; CurrentZOffset =pTemplate->TopZOffset; DeltaXOffset =(pTemplate->BotXOffset - pTemplate->TopXOffset); DeltaZOffset =(pTemplate->BotZOffset - pTemplate->TopZOffset); // Get the band positions and deltas geVec3d_Set(&Current, (float)(pTemplate->TopXSize / 2), (float)(pTemplate->YSize / 2), 0.0); geVec3d_Set(&Delta, (float)((pTemplate->BotXSize / 2) - Current.X), (float)(-(pTemplate->YSize/2) - Current.Y), 0.0); for(HBand = 0;HBand <= 1;HBand++) { Final = Current; for(VBand = 0;VBand < NumVerticalBands;VBand++) { // Get the elliptical Z value // (x^2/a^2) + (z^2/b^2) = 1 // z = sqrt(b^2(1 - x^2/a^2)) sqrcheck=( ((CurrentZDiameter/2)*(CurrentZDiameter/2)) * (1.0 - (Final.X*Final.X) / ( (CurrentXDiameter/2)*(CurrentXDiameter/2) )) ); if(sqrcheck <0.0) sqrcheck=0.0; EllipseZ = sqrt(sqrcheck); // Check if we need to negate this thing if(VBand > (NumVerticalBands/2)) EllipseZ = -EllipseZ; geVec3d_Set ( &Verts[VertexCount], (float)(Final.X + CurrentXOffset), Final.Y, (float)(EllipseZ + CurrentZOffset) ); VertexCount++; // Rotate the point around the Y to get the next vertical band geXForm3d_Rotate(&YRotation, &Final, &Final); } CurrentXDiameter +=DeltaXDiameter; CurrentZDiameter +=DeltaZDiameter; CurrentXOffset +=DeltaXOffset; CurrentZOffset +=DeltaZOffset; geVec3d_Add(&Current, &Delta, &Current); } for(VBand=0;VBand < NumVerticalBands;VBand++) { TopPoints[VBand] =Verts[VBand]; } f =Face_Create(NumVerticalBands, TopPoints, 0); if(f) { if(pTemplate->Solid > 1) { Face_SetFixedHull(f, GE_TRUE); } FaceList_AddFace(fl, f); } for(VBand=NumVerticalBands-1, HBand=0;VBand >=0;VBand--, HBand++) { TopPoints[HBand] =Verts[VBand + NumVerticalBands]; } f =Face_Create(NumVerticalBands, TopPoints, 0); if(f) { if(pTemplate->Solid > 1) { Face_SetFixedHull(f, GE_TRUE); } FaceList_AddFace(fl, f); } // Generate the polygons for(HBand = 0;HBand < 1;HBand++) { for(VBand = 0;VBand < NumVerticalBands;VBand++) { TopPoints[3] =Verts[(HBand * NumVerticalBands) + VBand]; TopPoints[2] =Verts[(HBand * NumVerticalBands) + ((VBand + 1) % NumVerticalBands)]; TopPoints[1] =Verts[((HBand + 1) * NumVerticalBands) + ((VBand + 1) % NumVerticalBands)]; TopPoints[0] =Verts[((HBand + 1) * NumVerticalBands) + VBand]; f =Face_Create(4, TopPoints, 0); if(f) { FaceList_AddFace(fl, f); } } } geRam_Free(Verts); geRam_Free(TopPoints); if(!pTemplate->Solid) { b =Brush_Create(BRUSH_LEAF, fl, NULL); if(b) { Brush_SetSubtract(b, pTemplate->TCut); } return b; } else { BrushList *bl =BrushList_Create(); Brush *bh, *bm; b =Brush_Create(BRUSH_LEAF, fl, NULL); if(b) { Brush_SetHollow(b, GE_TRUE); Brush_SetHullSize(b, (float)pTemplate->Thickness); bh =Brush_CreateHollowFromBrush(b); if(bh) { Brush_SetHollowCut(bh, GE_TRUE); BrushList_Append(bl, b); BrushList_Append(bl, bh); bm =Brush_Create(BRUSH_MULTI, NULL, bl); if(bm) { Brush_SetHollow(bm, GE_TRUE); Brush_SetSubtract(bm, pTemplate->TCut); Brush_SetHullSize(bm, (float)pTemplate->Thickness); return bm; } } else { Brush_Destroy(&b); BrushList_Destroy(&bl); } } else { BrushList_Destroy(&bl); } } return NULL; }