I am coding a white triangle inverted above another white triangle so their tips meet to form an hourglass shape. I need help fixing my code.
your text
#include “SceneManager.h”
your text
#ifndef STB_IMAGE_IMPLEMENTATION
your text
#define STB_IMAGE_IMPLEMENTATION
your text
#include “stb_image.h”
your text
#endif
your text
#include <glm/gtx/transform.hpp>
your text
{
your text
const char* g_ModelName = “model”;
your text
const char* g_ColorValueName = “objectColor”;
your text
const char* g_TextureValueName = “objectTexture”;
your text
const char* g_UseTextureName = “bUseTexture”;
your text
const char* g_UseLightingName = “bUseLighting”;
your text
}
your text
SceneManager::SceneManager(ShaderManager *pShaderManager)
your text
{
your text
m_pShaderManager = pShaderManager;
your text
m_basicMeshes = new ShapeMeshes();
your text
}
your text
SceneManager::~SceneManager()
your text
{
your text
m_pShaderManager = NULL;
your text
delete m_basicMeshes;
your text
m_basicMeshes = NULL;
your text
}
your text
void SceneManager::SetTransformations(
your text
glm::vec3 scaleXYZ,
your text
float XrotationDegrees,
your text
float YrotationDegrees,
your text
float ZrotationDegrees,
your text
glm::vec3 positionXYZ)
your text
{
your text
// variables for this method
your text
glm::mat4 modelView;
your text
glm::mat4 scale;
your text
glm::mat4 rotationX;
your text
glm::mat4 rotationY;
your text
glm::mat4 rotationZ;
your text
glm::mat4 translation;
your text
// set the scale value in the transform buffer
your text
scale = glm::scale(scaleXYZ);
your text
// set the rotation values in the transform buffer
your text
rotationX = glm::rotate(glm::radians(XrotationDegrees), glm::vec3(1.0f, 0.0f, 0.0f));
your text
rotationY = glm::rotate(glm::radians(YrotationDegrees), glm::vec3(0.0f, 1.0f, 0.0f));
your text
rotationZ = glm::rotate(glm::radians(ZrotationDegrees), glm::vec3(0.0f, 0.0f, 1.0f));
your text
// set the translation value in the transform buffer
your text
translation = glm::translate(positionXYZ);
your text
// matrix math to calculate the final model matrix
your text
modelView = translation * rotationX * rotationY * rotationZ * scale;
your text
if (NULL != m_pShaderManager)
your text
{
your text
// pass the model matrix into the shader
your text
m_pShaderManager->setMat4Value(g_ModelName, modelView);
}
your text`}
your text
void SceneManager::SetShaderColor(
your text
float redColorValue,
your text
float greenColorValue,
your text
float blueColorValue,
your text
float alphaValue)
your text
{
your text
// variables for this method
your text
glm::vec4 currentColor;
your text
currentColor.r = redColorValue;
your text
currentColor.g = greenColorValue;
your text
currentColor.b = blueColorValue;
your text
currentColor.a = alphaValue;
your text
if (NULL != m_pShaderManager)
your text
{
your text
// set the color values into the shader
your text
m_pShaderManager->setIntValue(g_UseTextureName, false);
your text
m_pShaderManager->setVec4Value(g_ColorValueName, currentColor);
your text
}
your text
}
your text
void SceneManager::PrepareScene()
your text
{
your text
// only one instance of a particular mesh needs to be
your text
// loaded in memory no matter how many times it is drawn
your text
// in the rendered 3D scene
your text
m_basicMeshes->LoadPyramid4Mesh();
your text
}
your text
void SceneManager::RenderScene() {
your text
// Set up the first pyramid transformations
your text
glPushMatrix(); // Save the current matrix
your text
// Apply transformations to the first pyramid
your text
glTranslatef(0.0f, 1.0f, 0.0f); // Move it up so the tips meet
your text
// Code to render the first pyramid
your text
RenderPyramid();
your text
glPopMatrix(); // Restore the saved matrix
your text
// Set up the second pyramid transformations
your text
glPushMatrix(); // Save the current matrix
your text
// Apply transformations to the second pyramid
your text
glRotatef(180.0f, 1.0f, 0.0f, 0.0f); // Invert the pyramid by rotating 180 degrees on your text
the X-axis
your text
glTranslatef(0.0f, -1.0f, 0.0f); // Move it down so the tips meet
your text
// Code to render the second pyramid
your text
RenderPyramid();
your text
glPopMatrix(); // Restore the saved matrix
your text
}
Please ignore the “your text” as I had to do that in order to post my code
Sydney Porter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.