53 lines
1.5 KiB
C++
53 lines
1.5 KiB
C++
/*
|
|
==============================================================================
|
|
|
|
OpenGLUtils.cpp
|
|
Created: 17 Jan 2026 11:41:12am
|
|
Author: esca
|
|
|
|
==============================================================================
|
|
*/
|
|
|
|
#include "OpenGLUtils.h"
|
|
#include <vector>
|
|
#include <math.h>
|
|
|
|
void svCol(Vertex &v, float newColour[4]){
|
|
v.colour[0] = newColour[0];
|
|
v.colour[1] = newColour[1];
|
|
v.colour[2] = newColour[2];
|
|
v.colour[3] = newColour[3];
|
|
}
|
|
|
|
void setColour(std::vector<Vertex> &verticeList, float newColour[4]){
|
|
for(Vertex v : verticeList){
|
|
svCol(v, newColour);
|
|
}
|
|
}
|
|
|
|
void vTransform(std::vector<Vertex> &verticeList, float x, float y){
|
|
for(Vertex &v : verticeList){
|
|
v.position[0] += x;
|
|
v.position[1] += y;
|
|
}
|
|
}
|
|
|
|
void vScale(std::vector<Vertex> &verticeList, float x, float y){
|
|
for(Vertex &v : verticeList){
|
|
v.position[0] = v.position[0]*x;
|
|
v.position[1] = v.position[1]*y;
|
|
}
|
|
}
|
|
|
|
std::vector<Vertex> generateSineWave(int numVertices, float angle, float startingColour[4]){
|
|
//generates one cycle of a sine wave with vertices numVertices and starting at angle angle
|
|
|
|
std::vector<Vertex> ret(numVertices, Vertex{});
|
|
for (int i = 0; i<numVertices; i++){
|
|
ret[i].position[0] = (float)i*1/numVertices;
|
|
ret[i].position[1] = sin(angle+i*(2*M_PI/numVertices));
|
|
svCol(ret[i], startingColour);
|
|
}
|
|
return ret;
|
|
}
|