Skip to content

Instantly share code, notes, and snippets.

@chunkyguy
Created August 22, 2012 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chunkyguy/3424970 to your computer and use it in GitHub Desktop.
Save chunkyguy/3424970 to your computer and use it in GitHub Desktop.
How to generate electricity
/*
Electricity:
resolution_ = 0; means straight line
pointA_, pointB_; are vec4s
*/
void ElectricCurrent::createVertexData(){
int tfloats = (2+resolution_) * 4; //num_points * num_floats_per_point
GLfloat data[tfloats];
int atIndx = 0;
atIndx = copyData(pointA_, data, atIndx);
for(int p = 0; p < resolution_; p++){
GLfloat point = 1.0/GLfloat(resolution_+1)*(p+1.0);
glm::vec4 pt = glm::mix(pointA_, pointB_, glm::vec4(point+GLfloat(rand())/GLfloat(RAND_MAX)*0.1,point+GLfloat(rand())/GLfloat(RAND_MAX)*0.1, 0.0, 1.0));
atIndx = copyData(pt, data, atIndx);
}
atIndx = copyData(pointB_, data, atIndx);
glBindBuffer(GL_ARRAY_BUFFER, buffer_);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * tfloats, data, GL_DYNAMIC_DRAW);
}
int ElectricCurrent::copyData(glm::vec4 pt, GLfloat *data, int atIndex){
data[atIndex++] = pt.x;
data[atIndex++] = pt.y;
data[atIndex++] = pt.z;
data[atIndex++] = pt.w;
return atIndex;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment