forked from Mirrors/openclonk
Add the "MeshTransformation" property (#197)
parent
855f31f64c
commit
d2deb1096b
|
@ -689,12 +689,14 @@ void C4Def::Draw(C4Facet &cgo, bool fSelected, DWORD iColor, C4Object *pObj, int
|
|||
|
||||
C4Value value;
|
||||
GetProperty(Strings.P[P_PictureTransformation], value);
|
||||
StdMeshMatrix matrix = StdMeshMatrix::Identity();
|
||||
C4ValueToMatrix(value, &matrix);
|
||||
StdMeshMatrix matrix;
|
||||
if(C4ValueToMatrix(value, &matrix))
|
||||
lpDDraw->SetMeshTransform(&matrix);
|
||||
|
||||
lpDDraw->SetPerspective(&matrix);
|
||||
lpDDraw->SetPerspective(true);
|
||||
lpDDraw->RenderMesh(*instance, cgo.Surface, cgo.X,cgo.Y, cgo.Wdt, cgo.Hgt, pObj ? pObj->Color : iColor, NULL);
|
||||
lpDDraw->UnsetPerspective();
|
||||
lpDDraw->SetPerspective(false);
|
||||
lpDDraw->SetMeshTransform(NULL);
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1080,11 +1080,6 @@ void C4GraphicsOverlay::Draw(C4TargetFacet &cgo, C4Object *pForObj, int32_t iByP
|
|||
{
|
||||
C4Def *pDef = pSourceGfx->pDef;
|
||||
|
||||
C4Value value;
|
||||
pDef->GetProperty(Strings.P[P_PictureTransformation], value);
|
||||
StdMeshMatrix matrix = StdMeshMatrix::Identity();
|
||||
C4ValueToMatrix(value, &matrix);
|
||||
|
||||
float twdt, thgt;
|
||||
if(fZoomToShape)
|
||||
{
|
||||
|
@ -1097,9 +1092,16 @@ void C4GraphicsOverlay::Draw(C4TargetFacet &cgo, C4Object *pForObj, int32_t iByP
|
|||
thgt = pDef->Shape.Hgt;
|
||||
}
|
||||
|
||||
lpDDraw->SetPerspective(&matrix);
|
||||
C4Value value;
|
||||
pDef->GetProperty(Strings.P[P_PictureTransformation], value);
|
||||
StdMeshMatrix matrix;
|
||||
if(C4ValueToMatrix(value, &matrix))
|
||||
lpDDraw->SetMeshTransform(&matrix);
|
||||
|
||||
lpDDraw->SetPerspective(true);
|
||||
lpDDraw->RenderMesh(*pMeshInstance, cgo.Surface, iTx - twdt/2, iTy - thgt/2, twdt, thgt, pForObj->Color, &Transform);
|
||||
lpDDraw->UnsetPerspective();
|
||||
lpDDraw->SetPerspective(false);
|
||||
lpDDraw->SetMeshTransform(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1168,12 +1170,14 @@ void C4GraphicsOverlay::DrawPicture(C4Facet &cgo, C4Object *pForObj)
|
|||
|
||||
C4Value value;
|
||||
pDef->GetProperty(Strings.P[P_PictureTransformation], value);
|
||||
StdMeshMatrix matrix = StdMeshMatrix::Identity();
|
||||
C4ValueToMatrix(value, &matrix);
|
||||
StdMeshMatrix matrix;
|
||||
if(C4ValueToMatrix(value, &matrix))
|
||||
lpDDraw->SetMeshTransform(&matrix);
|
||||
|
||||
lpDDraw->SetPerspective(&matrix);
|
||||
lpDDraw->SetPerspective(true);
|
||||
lpDDraw->RenderMesh(*pMeshInstance, cgo.Surface, cgo.X, cgo.Y, pForObj->Shape.Wdt, pForObj->Shape.Hgt, pForObj->Color, &C4DrawTransform(Transform, cgo.X+float(pForObj->Shape.Wdt)/2, cgo.Y+float(pForObj->Shape.Hgt)/2));
|
||||
lpDDraw->UnsetPerspective();
|
||||
lpDDraw->SetPerspective(false);
|
||||
lpDDraw->SetMeshTransform(NULL);
|
||||
}
|
||||
// cleanup
|
||||
if (dwBlitMode == C4GFXBLIT_PARENT)
|
||||
|
|
|
@ -489,7 +489,14 @@ void C4Object::DrawFaceImpl(C4TargetFacet &cgo, bool action, float fx, float fy,
|
|||
true, transform);
|
||||
break;
|
||||
case C4DefGraphics::TYPE_Mesh:
|
||||
C4Value value;
|
||||
GetProperty(Strings.P[P_MeshTransformation], value);
|
||||
StdMeshMatrix matrix;
|
||||
if(C4ValueToMatrix(value, &matrix))
|
||||
lpDDraw->SetMeshTransform(&matrix);
|
||||
|
||||
lpDDraw->RenderMesh(*pMeshInstance, cgo.Surface, tx, ty, twdt, thgt, Color, transform);
|
||||
lpDDraw->SetMeshTransform(NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -407,7 +407,7 @@ void CStdDDraw::Default()
|
|||
// pClrModMap = NULL; - invalid if !fUseClrModMap anyway
|
||||
fUseClrModMap = false;
|
||||
ZoomX = 0; ZoomY = 0; Zoom = 1;
|
||||
//PerspectiveMatrix = NULL; invalid if !fUsePerspective anyway
|
||||
MeshTransform = NULL;
|
||||
fUsePerspective = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -235,7 +235,7 @@ class CStdDDraw
|
|||
bool fUseClrModMap; // if set, pClrModMap will be checked for color modulations
|
||||
unsigned char Saturation; // if < 255, an extra filter is used to reduce the saturation
|
||||
int ZoomX; int ZoomY;
|
||||
StdMeshMatrix* PerspectiveMatrix; // Transformation to apply to mesh when rendering perspectively (not owned)
|
||||
const StdMeshMatrix* MeshTransform; // Transformation to apply to mesh before rendering
|
||||
bool fUsePerspective;
|
||||
public:
|
||||
float Zoom;
|
||||
|
@ -343,8 +343,8 @@ class CStdDDraw
|
|||
void GetZoom(ZoomData *r) { r->Zoom=Zoom; r->X=ZoomX; r->Y=ZoomY; }
|
||||
void ApplyZoom(float & X, float & Y);
|
||||
void RemoveZoom(float & X, float & Y);
|
||||
void SetPerspective(StdMeshMatrix* Matrix) { fUsePerspective = true; PerspectiveMatrix = Matrix; } // if non-NULL make sure to keep matrix valid until call to UnsetPerspective
|
||||
void UnsetPerspective() { fUsePerspective = false; }
|
||||
void SetMeshTransform(const StdMeshMatrix* Transform) { MeshTransform = Transform; } // if non-NULL make sure to keep matrix valid
|
||||
void SetPerspective(bool fSet) { fUsePerspective = fSet; }
|
||||
virtual void SetTexture() = 0;
|
||||
virtual void ResetTexture() = 0;
|
||||
|
||||
|
|
|
@ -743,7 +743,7 @@ namespace
|
|||
{
|
||||
const unsigned int Phase = instance.GetTexturePhase(i, j);
|
||||
have_texture = texunit.GetTexture(Phase).texName;
|
||||
glBindTexture(GL_TEXTURE_2D, texunit.GetTexture(Phase).texName); // TODO: Adapt for texture animation
|
||||
glBindTexture(GL_TEXTURE_2D, texunit.GetTexture(Phase).texName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -986,6 +986,9 @@ void CStdGL::PerformMesh(StdMeshInstance &instance, float tx, float ty, float tw
|
|||
v1 = OgreToClonk * v1; // TODO: Include translation
|
||||
v2 = OgreToClonk * v2; // TODO: Include translation
|
||||
|
||||
// Vector from origin of mesh to center of mesh
|
||||
const StdMeshVector MeshCenter = (v1 + v2)/2.0f;
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_LIGHTING);
|
||||
|
@ -1086,16 +1089,10 @@ void CStdGL::PerformMesh(StdMeshInstance &instance, float tx, float ty, float tw
|
|||
const GLfloat light_position[] = { 0.0f, 0.0f, v2.z + 15.0f, 1.0f };
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
// Convert from Ogre to Clonk coordinate system
|
||||
glMultMatrixf(OgreToClonkGL);
|
||||
}
|
||||
else
|
||||
{
|
||||
const float MeshX = (v1.x + v2.x)/2.0f;
|
||||
const float MeshY = (v1.y + v2.y)/2.0f;
|
||||
const float MeshZ = (v1.z + v2.z)/2.0f;
|
||||
|
||||
// Mesh extents
|
||||
const float b = fabs(v2.x - v1.x)/2.0f;
|
||||
const float h = fabs(v2.y - v1.y)/2.0f;
|
||||
const float l = fabs(v2.z - v1.z)/2.0f;
|
||||
|
@ -1108,9 +1105,9 @@ void CStdGL::PerformMesh(StdMeshInstance &instance, float tx, float ty, float tw
|
|||
else
|
||||
EyeR = l + std::max(b/TAN_FOV * thgt/twdt, h/TAN_FOV);
|
||||
|
||||
const float EyeX = MeshX;
|
||||
const float EyeY = MeshY;
|
||||
const float EyeZ = MeshZ + EyeR;
|
||||
const float EyeX = MeshCenter.x;
|
||||
const float EyeY = MeshCenter.y;
|
||||
const float EyeZ = MeshCenter.z + EyeR;
|
||||
|
||||
// Up vector is unit vector in theta direction
|
||||
const float UpX = 0;//-sinEyePhi * sinEyeTheta;
|
||||
|
@ -1125,39 +1122,40 @@ void CStdGL::PerformMesh(StdMeshInstance &instance, float tx, float ty, float tw
|
|||
// Fix X axis (???)
|
||||
glScalef(-1.0f, 1.0f, 1.0f);
|
||||
// center on mesh's bounding box, so that the mesh is really in the center of the viewport
|
||||
gluLookAt(EyeX, EyeY, EyeZ, MeshX, MeshY, MeshZ, UpX, UpY, UpZ);
|
||||
|
||||
// Apply perspective matrix
|
||||
if(PerspectiveMatrix)
|
||||
{
|
||||
// Convert to column-major order
|
||||
const float Matrix[16] =
|
||||
{
|
||||
(*PerspectiveMatrix)(0,0), (*PerspectiveMatrix)(1,0), (*PerspectiveMatrix)(2,0), 0,
|
||||
(*PerspectiveMatrix)(0,1), (*PerspectiveMatrix)(1,1), (*PerspectiveMatrix)(2,1), 0,
|
||||
(*PerspectiveMatrix)(0,2), (*PerspectiveMatrix)(1,2), (*PerspectiveMatrix)(2,2), 0,
|
||||
(*PerspectiveMatrix)(0,3), (*PerspectiveMatrix)(1,3), (*PerspectiveMatrix)(2,3), 1
|
||||
};
|
||||
|
||||
const float det = PerspectiveMatrix->Determinant();
|
||||
if(det < 0) parity = !parity;
|
||||
|
||||
// Renormalize if transformation resizes the mesh
|
||||
// for lighting to be correct
|
||||
if(det != 1 && det != -1)
|
||||
glEnable(GL_NORMALIZE);
|
||||
|
||||
// Apply Matrix in the coordinate system in which the mesh
|
||||
// is centered, not in the mesh's coordinate system.
|
||||
glTranslatef(MeshX, MeshY, MeshZ);
|
||||
glMultMatrixf(Matrix);
|
||||
glTranslatef(-MeshX, -MeshY, -MeshZ);
|
||||
}
|
||||
|
||||
// Convert from Ogre to Clonk coordinate system
|
||||
glMultMatrixf(OgreToClonkGL);
|
||||
gluLookAt(EyeX, EyeY, EyeZ, MeshCenter.x, MeshCenter.y, MeshCenter.z, UpX, UpY, UpZ);
|
||||
}
|
||||
|
||||
|
||||
// Apply mesh transformation matrix
|
||||
if(MeshTransform)
|
||||
{
|
||||
// Convert to column-major order
|
||||
const float Matrix[16] =
|
||||
{
|
||||
(*MeshTransform)(0,0), (*MeshTransform)(1,0), (*MeshTransform)(2,0), 0,
|
||||
(*MeshTransform)(0,1), (*MeshTransform)(1,1), (*MeshTransform)(2,1), 0,
|
||||
(*MeshTransform)(0,2), (*MeshTransform)(1,2), (*MeshTransform)(2,2), 0,
|
||||
(*MeshTransform)(0,3), (*MeshTransform)(1,3), (*MeshTransform)(2,3), 1
|
||||
};
|
||||
|
||||
const float det = MeshTransform->Determinant();
|
||||
if(det < 0) parity = !parity;
|
||||
|
||||
// Renormalize if transformation resizes the mesh
|
||||
// for lighting to be correct
|
||||
if(det != 1 && det != -1)
|
||||
glEnable(GL_NORMALIZE);
|
||||
|
||||
// Apply Matrix in the coordinate system in which the mesh
|
||||
// is centered, not in the mesh's coordinate system.
|
||||
glTranslatef(MeshCenter.x, MeshCenter.y, MeshCenter.z);
|
||||
glMultMatrixf(Matrix);
|
||||
glTranslatef(-MeshCenter.x, -MeshCenter.y, -MeshCenter.z);
|
||||
}
|
||||
|
||||
// Convert from Ogre to Clonk coordinate system
|
||||
glMultMatrixf(OgreToClonkGL);
|
||||
|
||||
DWORD dwModClr = BlitModulated ? BlitModulateClr : 0xffffffff;
|
||||
|
||||
#if 0
|
||||
|
|
|
@ -119,6 +119,7 @@ C4StringTable::C4StringTable()
|
|||
P[P_LineAttach] = RegString("LineAttach");
|
||||
P[P_MouseDragImage] = RegString("MouseDragImage");
|
||||
P[P_PictureTransformation] = RegString("PictureTransformation");
|
||||
P[P_MeshTransformation] = RegString("MeshTransformation");
|
||||
for (unsigned int i = 0; i < P_LAST; ++i) P[i]->IncRef();
|
||||
}
|
||||
|
||||
|
|
|
@ -175,6 +175,7 @@ P_Parallaxity,
|
|||
P_LineColors,
|
||||
P_LineAttach,
|
||||
P_PictureTransformation,
|
||||
P_MeshTransformation,
|
||||
P_Procedure,
|
||||
P_Directions,
|
||||
P_FlipDir,
|
||||
|
|
Loading…
Reference in New Issue