本文整理汇总了C++中Mat3::TransformPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat3::TransformPoint方法的具体用法?C++ Mat3::TransformPoint怎么用?C++ Mat3::TransformPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat3
的用法示例。
在下文中一共展示了Mat3::TransformPoint方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawAgent
void SpriteBatch::DrawAgent(Agent* a_agent)
{
Vec2 pos = a_agent->m_pos;
float width = (float)m_agentWidth;
float height = (float)m_agentHeight;
int xOff = (int)width / 2;
int yOff = (int)height / 2;
Vec2 tl = Vec2(-xOff, -yOff);
Vec2 tr = Vec2(xOff , -yOff);
Vec2 br = Vec2(-xOff, yOff);
Vec2 bl = Vec2(xOff , yOff);
float rot = Vec2(0,1).GetAngleBetween(a_agent->m_heading);
//create matrix for start point
Mat3 rotMat;
rotMat.Rotate(rot + 3.141592654);
rotMat.SetTranslation(pos);
//set the 4 vert points to correct rotation
tl = rotMat.TransformPoint(tl);
tr = rotMat.TransformPoint(tr);
br = rotMat.TransformPoint(br);
bl = rotMat.TransformPoint(bl);
processSprite(&tl, &tr, &bl, &br, m_agentIBO, m_agentVBO, m_texID_agent, SPRITE_COLOUR_WHITE);
}
示例2: DrawLine
//Draw Line
void SpriteBatch::DrawLine(Vec2 a_start, Vec2 a_end, SPRITE_COLOUR a_col, float a_width)
{
//width used to offsetting
float width;
if(a_width > 0)
width = a_width;
else
width = (float)m_line_width / 2;
//width override for debugging
//width = 50;
float size = (a_start - a_end).Length();
Vec2 origin = Vec2(-width / 2, 0);
//set the line around the zero point with the pivot
//at the top center (0,0)
//oriented for rotation zero along the x axis
Vec2 tl = Vec2(0, 0) + origin;
Vec2 tr = Vec2(width, 0) + origin;
Vec2 br = Vec2(0, size) + origin;
Vec2 bl = Vec2(width, size) + origin;
//get difference normalised
// Vec2 diff = Vec2(a_end.x - a_start.x, a_end.y - a_start.y).GetNormalised();
Vec2 diff = (a_start - a_end).GetNormalised();
float rot = Vec2(0,1).GetAngleBetween(diff);
//create matrix for start point
Mat3 rotMat;
rotMat.Rotate(rot + 3.141592654);
rotMat.SetTranslation(a_start);
//transform line start point
tl = rotMat.TransformPoint(tl);
tr = rotMat.TransformPoint(tr);
//transform line end point
br = rotMat.TransformPoint(br);
bl = rotMat.TransformPoint(bl);
processSprite(&tl, &tr, &bl, &br, m_lineIBO, m_lineVBO, m_texID_line, a_col);
}
示例3: DrawSprite
void SpriteBatch::DrawSprite(unsigned int VBO, unsigned int IBO, unsigned int programID, unsigned int textureID , unsigned int projectionLoc, float *projectionMat, Mat3 &matrix, float a_width, float a_height, int rotatePoint, Vec2 a_pivot)
{
//make sure we are drawing the current width of the object multiplied against the scale
//otherwise changing the scale of the Mat3 isn't taken into account when drawing.
float width = a_width * matrix.GetRightScale();
float height = a_height * matrix.GetUpScale();
Vec2 tl = Vec2(0, 0) + a_pivot;
Vec2 tr = Vec2(width, 0) + a_pivot;
Vec2 br = Vec2(0, height) + a_pivot;
Vec2 bl = Vec2(width, height) + a_pivot;
//set the 4 vert points to correct rotation
tl = matrix.TransformPoint(tl);
tr = matrix.TransformPoint(tr);
br = matrix.TransformPoint(br);
bl = matrix.TransformPoint(bl);
Vertex vertexData[4] =
{
Vertex(tl.x, tl.y, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f),
Vertex(tr.x, tr.y, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f),
Vertex(bl.x, bl.y, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f),
Vertex(br.x, br.y, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f)
};
GLubyte indices[6] =
{
0, 1, 2, // first triangle
0, 2, 3 // second triangle
};
glUseProgram(programID);
//std::cout << glGetError() << std::endl;
// bind our texture to active texture 0...
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, textureID);
int textureLocation = glGetUniformLocation(programID, "myTextureSampler");
glUniform1i(textureLocation , 1 );
//send our orthographic projection info to the shader
glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, projectionMat);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IBO);
//allocate space for vertices on the graphics card
glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex)*4, vertexData, GL_STREAM_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLubyte)*6, indices, GL_STREAM_DRAW);
//enable the vertex array state, since we're sending in an array of vertices
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)16);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)32);
//glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(sizeof(float)*8));
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, NULL);
// glDrawArrays(GL_QUADS, 0, 4);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glUseProgram(0);
//debug collision circles by displaying them
//note that collision code should match this method for positions collision circles to be correct
//create a posiiton around the world 0 point for the centre of the object to transform from
// Vec2 drawPos = Vec2((width / 2) + a_pivot.x, (height / 2) + a_pivot.y);
//
// //transform the circle point to where it needs to go
// drawPos = matrix.TransformPoint(drawPos);
//
// float radius = getRadius(width, height, matrix.GetRightScale());
// //draw the circle
// DrawCircle(drawPos.x, drawPos.y, radius, 12, projectionLoc, projectionMat);
//
}