Skilled Illusionist
- Joined
- Jun 22, 2017
- Messages
- 363
- Reaction score
- 561
Hope this helps!
code:
code:
Code:
class Pos2D
{
public:
Pos2D(float x= 0.0f, float y = 0.0f)
{
this->X = x;
this->Y = y;
}
float X;
float Y;
public:
void Set(float x, float y)
{
this->X = x;
this->Y = y;
}
};
class Vec3D
{
public:
Vec3D(float x = 0.0f, float y = 0.0f, float z = 0.0f)
{
this->X = x;
this->Y = y;
this->Z = z;
}
float X;
float Y;
float Z;
public:
void SetVertexCoord(Vec3D *Pos, Vec3D *a2)
{
this->X = a2->Y * Pos->Y + a2->Z * Pos->Z + Pos->X * a2->X;
this->Y = a2[1].Y * Pos->X + a2[1].Z * Pos->Y + a2[2].X * Pos->Z;
this->Z = a2[2].Z * Pos->X + a2[3].X * Pos->Y + a2[3].Y * Pos->Z;
}
void SetVertex(Vec3D *lpVertex)
{
float PosZ = this->Z * 0.01745329238474369f;
float v3 = sin(PosZ);
float v4 = cos(PosZ);
float PosY = this->Y * 0.01745329238474369f;
float v6 = sin(PosY);
float v7 = cos(PosY);
float PosX = this->X * 0.01745329238474369f;
float v9 = sin(PosX);
float v10 = cos(PosX);
lpVertex->X = v7 * v4;
lpVertex[1].Y = v7 * v3;
lpVertex[2].Z = -v6;
lpVertex->Y = v9 * v6 * v4 + -v3 * v10;
lpVertex[1].Z = v9 * v6 * v3 + v10 * v4;
lpVertex[3].X = v9 * v7;
lpVertex->Z = v10 * v6 * v4 + -v9 * -v3;
lpVertex[2].X = v10 * v6 * v3 + -v9 * v4;
lpVertex[3].Y = v10 * v7;
lpVertex[1].X = 0.0;
lpVertex[2].Y = 0.0;
lpVertex[3].Z = 0.0;
}
void Set(float R, float G, float B)
{
this->X = R;
this->Y = G;
this->Z = B;
}
Vec3D * Get()
{
return this;
}
};
Code:
void CTexture::RotateImage(int ID, float PosX, float PosY, float Width, float Height, float Angle, float StartX, float StartY, float ScaleX, float ScaleY, float Alpha)
{
Pos2D TextureCoord[4];
Vec3D Vertex3f1[4];
Vec3D VertexCoord[4];
Vec3D VertexSize[4];
PosX = WINDOW_WIDTH * PosX / 640.0f;
PosY = WINDOW_HEIGHT * PosY / 480.0f;
Width = WINDOW_WIDTH * Width / 640.0f;
Height = WINDOW_HEIGHT * Height / 480.0f;
float PosYHeight = WINDOW_HEIGHT - PosY;
glPushMatrix();
this->BindTexture(ID);
VertexSize[0].Set(-Width * 0.5f, Height * 0.5f, 0.0);
VertexSize[1].Set(-Width * 0.5f, -Height * 0.5f, 0.0);
VertexSize[2].Set(Width * 0.5f, -Height * 0.5f, 0.0);
VertexSize[3].Set(Width * 0.5f, Height * 0.5f, 0.0);
Vec3D VecPos3f(0.0, 0.0, Angle);
VecPos3f.SetVertex(Vertex3f1);
TextureCoord[0].Set(StartX, StartY);
TextureCoord[1].Set(StartX, (StartY + ScaleY));
TextureCoord[2].Set((StartX + ScaleX), (StartY + ScaleY));
TextureCoord[3].Set((StartX + ScaleX), StartY);
glBegin(GL_TRIANGLE_FAN);
if (Alpha > 0.0)
glColor4f(1.0f, 1.0f, 1.0f, Alpha);
for (int i = 0; i < 4; i++)
{
glTexCoord2f(TextureCoord[i].X, TextureCoord[i].Y);
VertexCoord[i].SetVertexCoord(&VertexSize[i], Vertex3f1);
glVertex2f((VertexCoord[i].X + PosX), (PosYHeight - VertexCoord[i].Y)); //PosYHeight + VertexCoord[i].Y : Used for DrawText
}
if (Alpha > 0.0)
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glEnd();
glPopMatrix();
}
Last edited: