Skilled Illusionist
- Joined
- Jun 22, 2017
- Messages
- 363
- Reaction score
- 561
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;
}
};
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();
}
interesting, for all client versions?
RotateImage(int ID, float PosX, float PosY, float Width, float Height, float Angle, float StartX, float StartY, float ScaleX, float ScaleY, float Alpha)
How to use?
Code:RotateImage(int ID, float PosX, float PosY, float Width, float Height, float Angle, float StartX, float StartY, float ScaleX, float ScaleY, float Alpha)
I assume ID would be the texture's ID, then.. what's the difference between PosX/PosY and StartX/StartY? Same for Width/Height and ScaleX/ScaleY.. what's the difference?
BindTexture(ID), can you share this?
bool CTexture::BindTexture(const unsigned int ID)
{
if (this->m_TextureID.find(ID) != this->m_TextureID.end())
{
glBindTexture(GL_TEXTURE_2D, this->m_TextureID[ID]);
return true;
}
return false;
}
typedef struct
{
/* +0*/ unsigned char identsize; // size of ID field that follows 18 byte header (0 usually)
/* +1*/ unsigned char colourmaptype; // type of colour map 0=none, 1=has palette
/* +2*/ unsigned char imagetype; // type of image 0=none,1=indexed,2=rgb,3=grey,+8=rle packed
/* +3*/ short colourmapstart; // first colour map entry in palette
/* +5*/ short colourmaplength; // number of colours in palette
/* +7*/ unsigned char colourmapbits; // number of bits per palette entry 15,16,24,32
/* +8*/ short xstart; // image x origin
/* +10*/ short ystart; // image y origin
/* +12*/ short width; // image width in pixels
/* +14*/ short height; // image height in pixels
/* +16*/ unsigned char bits; // image bits per pixel 8,16,24,32
/* +17*/ unsigned char descriptor; // image descriptor bits (vh flip bits)
/* +18*/ unsigned char *data;
} TGA_HEADER;
Hope this helps!
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(); }