Rotating and Scaling without gl

Hi everyone, I’m kinda new to gl coding, I’m taking computer graphics in university for this topic. My homework is rotating and scaling a pyramid without using gl. Where I can start and how can I accomplish the task. Need help please.

Didn’t your professor teach you how to do that?

Basic algebra can dictate a transformation matrix.

X 0 0 0
Y 3 3 3
Z 0 0 0

matrix addition applied to each vertex can represent a simple transform.
Acquire a book on linear algebra, or google matrix manipulation.

@Alfonse, he did mention about that on paper, but not about coding.

@Daniel, I understand the matrix multiplication for rotating and scaling but, then how am I going to create the pyramid and what these matrices represent compared to the pyramid? The part representing a pyramid with a matrix I really don’t understand.

A pyramid consists of a number of vectors. You can find some good basics about vector maths at

When you have read that, look at for information about matrices and transformations.

Finally, if you want to do a program of your own for doing matrix operations, I would recommend to use the glm package. This package supports the same operations as OpenGL.

So correct me if I’m wrong, I’m going to create a 4X3 matrix, which will hold the vertices of the pyramid and a function to draw the lines between them. Then when I need to rotate or scale, I multiply or do the needed calculation to this matrix and redraw the pyramid in every time?

You don’t seem to understand matrices, try reading this

Now, I had some other assignments but finally find time to work on this. I read all your replies and tried to make something, gonna post it here so you can have a look and leave a comment.

First I defined the values that will keep the rotation information like this:
static float yaxis[33][3]= {{2,0,0},{1.75,0,-0.9682},{1.50,0,-1.323},{1.25,0,-1.561},
{1,0,1.732},{1.25,0,1.561},{1.50,0,1.323},{1.75,0,0.9682},{2,0,0} };

And defined this to select between the y values
static float yselect[3];
int count = 0;

In the initiation function, I initiate alpha to 0, scale to 1.8 and select y values

yselect[0] = yaxis[0][0];
yselect[1] = yaxis[0][1];
yselect[2] = yaxis[0][2];

while in the idle function I keep an integer for the 1/4 of the rotation, whenever that variable is 25, the scale is incremented and the variable is reset

if (fre == 25)
	fre = 0;

And in every frame the y values changes according to the values I defined on top

yselect[0] = yaxis[count %33][0];
yselect[1] = yaxis[count %33][1];
yselect[2] = yaxis[count %33][2];

now in the reshape function, I used gl’s lighting function, I dont know whether it is doing something or not but

void reshape (int width, int height)
float black[] = { 0, 0, 0, 0 };

glViewport(0, 0, width, height);
gluPerspective(60, (float)width/height, 0.1, 1000);

gluLookAt(0, 1, 6, 0, 1, 0, 0, 1, 0);




and initiate all in main
void main (int argc, char** argv)
glutInit(&argc, argv);





When I execute, the rotation and scaling of the pyramid works fine. However it is a bit fast but that is not important. I dont know how I can code my own lighting function, and use it. So what do you say, how can I make a lighting point source and work on it?

For lighting to work you need to have a normal at each vertex and look at the lighting functions


In the assignment it says dont use gl functions for lighting. These count as gl functions right?

Yes they are. Are you supposed to use shaders? If not, I assume you have to calculate the modified colour at each vertex. You will need to look at the maths for Blinn or Lambert lighting. Just to a quick google there is lots out there.