Monday, April 6, 2009

Finished Project 2

I finally finished Project 2 to the best of my ability!...
Here are some pictures of the final product..there is a picture of the teapot and then I found a teddy bear. For some reason, .obj files were sorta hard to find. I tried searching many of times for different ones that weren't too complex but couldn't find many.




I like to give some credit to OpenGL @ Lighthouse 3D because they had some tutorials helping out with moving around in the world space via camera. I'd also like to give some credit to the helpful resources posted by Dr. Patterson on the blog.

Click this to go to OpenGL @ Lighthouse 3D's website to view some of their tutorials.

Also if your search for "sample .obj files" on Google, the first website to appear should appear to be the one I used for the teddybear.obj!

Wednesday, April 1, 2009

Working on Project 2...starting to come around

Here is a picture of what I've got so far...I've got the teapot to load...now its just searching for another one to use...as well as trying to make something in Maya to import to display...and then implementing mouse movements to be able to drag around the object created.

Thursday, March 26, 2009

Web Exercise #3 - March 20th

After a lot of reading, I've got a better understanding of the commands that control the view of the camera (view from the eye).

Here is the part in #2 running:



For the last part, I was instructed to take a look at the special keys functions we have been using to rotate the object or view. I took an example from Chapter 3 of the Programming Guide for OpenGL which is a quarter of a wire sphere. I took out the clipping plane parts and it drew a whole wire sphere. I used glLookAt() and glFrustum to change it up a little bit to mess around and see what it actually did.

Here is a picture of the sphere because I don't think I can upload an executable.



I couldn't find the code that I used, but it is the 4th of a sphere that I used...I just took out the clipping plane stuff!

Tuesday, March 17, 2009

Web Assignment #2

I started looking at this over spring break and realized that I didn't want to do work so I decided to start working on this Sunday. Here's what I came up with:

OpenGL ES - OpenGL ES is "a cross-platform API for full-function 2D and 3D graphics on embedded systems." OpenGL ES is used on cell phones, consoles, and appliances as well being used in vehicles. There are two types of OpenGL ES: 1.X and 2.X. The first type is for fixed function hardware and it offers performance, acceleration, and great image quality. 2.X on the other hand is for programmable hardware. Some advantages of OpenGL ES are: industry standard and royalty free, small footpring and low power consumption, seamless transition from software to hardware rendering, extensible and evolving, easy to use, and well-documented (in case you need guidance).

Processing and OpenGL - There is an option to use OpenGL rendering in Processing. This allows Processing to use the cross-platform graphics interface for 3D and 2D graphics and utilize the speed of an OpenGL accelerated graphics card. When using OpenGL in Processing, you have the chance to draw more to the screen and a chance to create larger windows. However, you might have issues if you don't have an OpenGL accelerated graphics card. To use OpenGL in Processing, simply import OpenGL through this statement: import processing.opengl.*; You also have to specify, in order to use OpenGL, OpenGL as a third parameter in the size() function in setup(). OpenGL in Processing is really memory hungry and has a potential to crash computers if it is trying to process a large amount of drawings to the screen.

PyOpenGL - PyOpenGL is the Pythonic OpenGL API. This is basically programming in Python using the OpenGL API. Python is an easy language to write in. It has no punctuation for endings unlike Java, or C/C++ which use a ';' to denote the end of a line. Everything is done by indentation as well which shows ownership of what is in a for loop or while loop or in a specific method/class. There are some advantages to using PyOpenGL: Calls to OpenGL automatically come with exceptions when things are wrong in the code; there is no need to compile since it is Python which means you can change code faster; PyOpenGL is open source so it's changing daily.

1. I have changed the 'lstrips' example to draw a specific bezier curve and be able to rotate it. Here is a picture of what I did:



2. Here is "Perspective Projection": I changed it up to make it look like a triangular prism. The color scheme is a tie-dye...anyways...something we haven't seen is the lighting aspect of it.

Wednesday, March 4, 2009

The First Project!!!

Wow, this was pretty fun, I'm not gonna lie. I did the Twisted World one where you had to use NodeBox to create some pictures swirling around on the screen. Basically I set up the first canvas to be the size of the picture for the central image. You can either do like Twisted World did and have no central image and just swirl around random pictures or you can have a central picture and swirl pictures around that. I did the latter. I had to download the web.zip file and the coreimage.zip files in order to be able to use the canvas stuff and be able to access pictures from Flickr. I tried to get some pictures from Google, but I couldn't ever figure out how to do that so I just stayed with Flickr. Once all of those files were imported, I created about 20 random layers and took around 50 pictures from Flickr, or however many pictures it could get within about 30 seconds or less. I added twirl, noisereduction, and starshine effects to the pictures that I grabbed. I rotated them, scaled them, and sometimes I flipped them. After this, I chose the central image and appended, or placed, all of these layers on to a second canvas and drew that to the NodeBox screen. All and all it was a lot of fun and I really enjoyed doing this project. Here are some examples of my pictures that I created:








I must give credit to the Twisted World Example found on Nodebox.net. I also must give credit to Flickr for providing the randomly grabbed pictures. And I must give credit to Google for providing me with some of the central pictures!

Tuesday, March 3, 2009

Dev C++

So I had to get some help in compiling some code to get it to work. I had to download something and install it in Dev C++ since I have a Windows computer that is so much different from everything else, it seems like...Anywho, here is the picture to show that I got this Simple.cpp to compile on Dev C++:

Tuesday, February 17, 2009

Homework #4

Once again a busy start to the week!...For this assignment we had to rotate a triangle. Then we had to rotate it to make a design. After that, the last part I spent creating a cool image using pushMatrix, popMatrix, translate, rotate, and scale. So here are some pictures of what I have created and then code is listed below them:



Code:
float[][] rotateMatrix = new float[2][2];

void setup(){
size(720,480);
background(30,144,255);
noLoop();
}

void draw(){
noFill();
stroke(16,78,139);
int x0,y0,x1,y1,x2,y2;
x0 = int(random(720));
y0 = int(random(480));
x1 = int(random(720));
y1 = int(random(480));
x2 = int(random(720));
y2 = int(random(480));

for(float a=0; a < 2; a += 1){
rotateTriangle(x0,y0,x1,y1,x2,y2,(a*PI));
stroke(255,0,0);
}
}

void rotateTriangle(int x0, int y0, int x1, int y1, int x2, int y2, float r){
setRotateMatrix(r);
//calculating origin of the triangle
int ox = (x0+x1+x2)/3;
int oy = (y0+y1+y2)/3;
//translating back to (0,0) origin to make translating easier
float[][] origin = {{x0-ox,y0-oy},{x1-ox,y1-oy},{x2-ox,y2-oy}};
origin = multiplyMatrix(origin,rotateMatrix);
//going back to origin
for(int a=0; a < origin.length; a++){
for(int b=0; b < origin[0].length; b++){
if(b==0){
origin[a][b] += ox;
}else
origin[a][b] += oy;
}
}
triangle(origin[0][0],origin[0][1],origin[1][0],origin[1][1],origin[2][0],origin[2][1]);
}

void setRotateMatrix(float r){
rotateMatrix[0][0] = cos(r);
rotateMatrix[0][1] = -sin(r);
rotateMatrix[1][0] = sin(r);
rotateMatrix[1][1] = cos(r);
}

float[][] multiplyMatrix(float[][] matrix1, float[][] matrix2){
float[][] matrix3 = new float[matrix1.length][matrix2[0].length];
for(int a=0; a for(int b=0; b for(int c=0; c matrix3[a][b] += matrix1[a][c] * matrix2[c][b];
}
}
}
return matrix3;
}
void drawTriangle(int x0, int y0, int x1, int y1, int x2, int y2){
line(x0,y0,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x0,y0);
}



Code:

float[][] rotateMatrix = new float[2][2];

void setup(){
size(720,480);
background(30,144,255);
noLoop();
}

void draw(){
noFill();
stroke(16,78,139);
int x0,y0,x1,y1,x2,y2;
x0 = int(random(720));
y0 = int(random(480));
x1 = int(random(720));
y1 = int(random(480));
x2 = int(random(720));
y2 = int(random(480));

for(float a=0; a < 2; a += .04166666){
rotateTriangle(x0,y0,x1,y1,x2,y2,(a*PI));
}
}

void rotateTriangle(int x0, int y0, int x1, int y1, int x2, int y2, float r){
setRotateMatrix(r);
//calculating origin of the triangle
int ox = (x0+x1+x2)/3;
int oy = (y0+y1+y2)/3;
//translating back to (0,0) origin to make translating easier
float[][] origin = {{x0-ox,y0-oy},{x1-ox,y1-oy},{x2-ox,y2-oy}};
origin = multiplyMatrix(origin,rotateMatrix);
//going back to origin
for(int a=0; a < origin.length; a++){
for(int b=0; b < origin[0].length; b++){
if(b==0){
origin[a][b] += ox;
}else
origin[a][b] += oy;
}
}
triangle(origin[0][0],origin[0][1],origin[1][0],origin[1][1],origin[2][0],origin[2][1]);
}

void setRotateMatrix(float r){
rotateMatrix[0][0] = cos(r);
rotateMatrix[0][1] = -sin(r);
rotateMatrix[1][0] = sin(r);
rotateMatrix[1][1] = cos(r);
}

float[][] multiplyMatrix(float[][] matrix1, float[][] matrix2){
float[][] matrix3 = new float[matrix1.length][matrix2[0].length];
for(int a=0; a for(int b=0; b for(int c=0; c matrix3[a][b] += matrix1[a][c] * matrix2[c][b];
}
}
}
return matrix3;
}
void drawTriangle(int x0, int y0, int x1, int y1, int x2, int y2){
line(x0,y0,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x0,y0);
}



Code:
float[][] rotateMatrix = new float[2][2];

void setup(){
size(950,700);
background(30,144,255);
noLoop();
}

void draw(){
fill(0);
rect(0,0,50,50);
pushMatrix();
for(int i=0; i < 9; i++){
translate(50,50);
rect(0,0,50,50);
pushMatrix();
}
for(int j=0; j < 9; j++){
translate(50,-50);
rect(0,0,50,50);
}
for(int a=0; a < 10; a++){
popMatrix();
}
fill(random(255),random(255),random(255));
translate(50,0);
rect(0,0,50,50);
pushMatrix();
for(int k=0; k < 8; k++){
translate(50,50);
rect(0,0,50,50);
pushMatrix();
}
for(int j=0; j < 8; j++){
translate(50,-50);
rect(0,0,50,50);
}
for(int a=0; a < 9; a++){
popMatrix();
}

fill(random(255),random(255),random(255));
translate(50,0);
rect(0,0,50,50);
pushMatrix();
for(int b=0; b < 7; b++){
translate(50,50);
rect(0,0,50,50);
pushMatrix();
}
for(int c=0; c < 7; c++){
translate(50,-50);
rect(0,0,50,50);
}
for(int a=0; a < 8; a++){
popMatrix();
}
fill(random(255),random(255),random(255));
translate(50,0);
rect(0,0,50,50);
pushMatrix();
for(int b=0; b < 6; b++){
translate(50,50);
rect(0,0,50,50);
pushMatrix();
}
for(int c=0; c < 6; c++){
translate(50,-50);
rect(0,0,50,50);
}
for(int a=0; a < 7; a++){
popMatrix();
}
fill(random(255),random(255),random(255));
translate(50,0);
rect(0,0,50,50);
pushMatrix();
for(int b=0; b < 5; b++){
translate(50,50);
rect(0,0,50,50);
pushMatrix();
}
for(int c=0; c < 5; c++){
translate(50,-50);
rect(0,0,50,50);
}
for(int a=0; a < 6; a++){
popMatrix();
}
fill(random(255),random(255),random(255));
translate(50,0);
rect(0,0,50,50);
pushMatrix();
for(int b=0; b < 4; b++){
translate(50,50);
rect(0,0,50,50);
pushMatrix();
}
for(int c=0; c < 4; c++){
translate(50,-50);
rect(0,0,50,50);
}
for(int a=0; a < 5; a++){
popMatrix();
}
noFill();
stroke(random(255),random(255),random(255));
int x0,y0,x1,y1,x2,y2;
x0 = 0;
y0 = 0;
x1 = 100;
y1 = 100;
x2 = 50;
y2 = 50;

translate(175,25);
for(float a=0; a < 2; a += .04166666){
rotateTriangle(x0,y0,x1,y1,x2,y2,(a*PI));
}
stroke(random(255),random(255),random(255));
translate(-250,500);
pushMatrix();
for(int i=0; i < 50; i++){
rotate(PI/12);
rect(0,0,100,50);
}
stroke(random(255),random(255),random(255));
translate(500,-275);
for(int i=0; i < 50; i++){
rotate(PI/12);
rect(0,0,100,50);
}
}

void rotateTriangle(int x0, int y0, int x1, int y1, int x2, int y2, float r){
setRotateMatrix(r);
//calculating origin of the triangle
int ox = (x0+x1+x2)/3;
int oy = (y0+y1+y2)/3;
//translating back to (0,0) origin to make translating easier
float[][] origin = {{x0-ox,y0-oy},{x1-ox,y1-oy},{x2-ox,y2-oy}};
origin = multiplyMatrix(origin,rotateMatrix);
//going back to origin
for(int a=0; a < origin.length; a++){
for(int b=0; b < origin[0].length; b++){
if(b==0){
origin[a][b] += ox;
}else
origin[a][b] += oy;
}
}
triangle(origin[0][0],origin[0][1],origin[1][0],origin[1][1],origin[2][0],origin[2][1]);
}

void setRotateMatrix(float r){
rotateMatrix[0][0] = cos(r);
rotateMatrix[0][1] = -sin(r);
rotateMatrix[1][0] = sin(r);
rotateMatrix[1][1] = cos(r);
}

float[][] multiplyMatrix(float[][] matrix1, float[][] matrix2){
float[][] matrix3 = new float[matrix1.length][matrix2[0].length];
for(int a=0; a for(int b=0; b for(int c=0; c matrix3[a][b] += matrix1[a][c] * matrix2[c][b];
}
}
}
return matrix3;
}
void drawTriangle(int x0, int y0, int x1, int y1, int x2, int y2){
line(x0,y0,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x0,y0);
}

Friday, February 6, 2009

Project Proposal

It has been a busy week so far and I had neglected to repost my proposal for the project. I have been looking around and since I know we're going to be doing some more on processing, I wanted to branch out and try something different. So I went to the resources page and found something that involves using NodeBox. NodeBox is a pretty cool program that uses Python as its language. I found a picture that looked pretty cool that is called Membrane. Here is a link to it:

http://nodebox.net/code/index.php/Membrane_%7C_Dynamics_in_Core_Image

It involves an already taken picture that is stored on your computer. That picture is stored as a layer, and then on top of that there is another layer that, at that website, is called the Membrane, which is just what looks like bubbles popping/twirling around the picture distorting the picture. I think I could possibly create a different layer that would act, of course, differently from the one that is posted on the website.

Sunday, February 1, 2009

Homework #3

For the first part of this homework, I had to draw a cubic Bezier curve by clicking the mouse to draw it. Here is the code and a picture:

int points;
int x0, y0, x1, y1, x2, y2, x3, y3;

void setup(){
size(400,400);
background(0);
}

void draw(){
noFill();
stroke(255,0,0);
}

void mousePressed(){
if(points == 0){
x0 = mouseX;
y0 = mouseY;
point(x0,y0);
println(x0 + "x0" + y0 + "y0");
points = 1;
}else if(points == 1){
x1 = mouseX;
y1 = mouseY;
points = 2;
}else if(points == 2){
x2 = mouseX;
y2 = mouseY;
points = 3;
}else if(points == 3){
x3 = mouseX;
y3 = mouseY;
stroke(255,0,0);
bezier(x0,y0,x1,y1,x2,y2,x3,y3);
points = 0;
}
}


I'm not able to get the applet to load onto here, so I just posted the picture itself of tons of bezier curves.

For the second part I had to create a function that accepts 3 points and draws a triangles of random size/ with random points. Here is the code and a picture for that as well:

int x0,y0,x1,y1,x2,y2;
void setup(){
size(720,480);
background(0,100,100);
}

void draw() {
noFill();
stroke(0,255,255);
}

void keyPressed(){
x0 = int(random(720));
y0 = int(random(480));
x1 = int(random(720));
y1 = int(random(480));
x2 = int(random(720));
y2 = int(random(480));

if(key == 't'){
drawTriangle(x0,y0,x1,y1,x2,y2);
}

}

void drawTriangle(int x0, int y0, int x1, int y1, int x2, int y2){
line(x0,y0,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x0,y0);
}



Finally for the third part, I am supposed to draw a rectangle with size 360 X 240 in the center of a 720 X 480 screen with 5 random triangles drawn and clipped down to just residing in the rectangle. I've been working on this yesterday and have gotten somewhere but it isn't exactly correct. But I will post that later on this week.

My proposal will come during the Super Bowl while I'm watching it tonight...

Thursday, January 22, 2009

Web Assignment 1 - Bezier curve: Line, Quadratic, and Cubic


Wow, this was very interesting assignment to do. I was confused at first but now it makes sense.

- I had to create another formula to draw a line without using y=mx+b formula, but using a parametric/Bezier equation to draw the line.
- Also, I had to create a formula to draw a quadratic curve using Bezier's formula.
- Finally, I used the cubic formula from Bezier to create the cubic curve.

//Brandon Hilton
//CSC 370
//Eric Patterson
//Web Assignment #1

void setup() {
size(300, 300);
}

void draw() {
stroke(255, 255, 255);
myLine(10, 40, 50, 90);

stroke(255, 0, 0);
myquad(10, 150, 30, 200, 210, 210);

stroke(0, 0, 255);
mycubic(20, 30, 90, 15, 85, 60, 20, 60);
}

void myLine(int x0, int y0, int x1, int y1) {
float x, y;
for(float t = 0.0f; t < 1; t += 0.00001){
x = x0 + t*(x1 - x0);
y = y0 + t*(y1 - y0);
point(x, y);
}
}

void myquad(int x0, int y0, int x1, int y1, int x2, int y2){
float x, y;
for(float t = 0; t < 1; t += 0.00001){
x = (1-t)*(1-t)*x0 + 2*(1-t)*t*x1 + t*t*x2;
y = (1-t)*(1-t)*y0 + 2*(1-t)*t*y1 + t*t*y2;
point(x, y);
}
}

void mycubic(int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3){
float x, y;
for(float t=0; t < 1; t += 0.00001){
x = (1-t)*(1-t)*(1-t)*x0 + 3*(1-t)*(1-t)*t*t*x1 + 3*(1-t)*t*t*x2 + t*t*t*x3;
y = (1-t)*(1-t)*(1-t)*y0 + 3*(1-t)*(1-t)*t*t*y1 + 3*(1-t)*t*t*y2 + t*t*t*y3;
point(x, y);
}
}

Monday, January 12, 2009

Homework #2 - Line, Circle, Web

For this homework assignment, I had to:
- Create a line using only point commands and without using the line command from Processing.
- Create a circle using only point commands and without using the ellipse command from Processing.
- Create a "web" using a grid of straight lines by calling the line command over and over again.








//Line
void setup() {
size(300, 300);
}
void draw() {
drawMyLine(20, 100, 20, 100);
}

void drawMyLine(int x1, int x2, int y1, int y2){
int dx = x2-x1;
int dy = y2-y1;
float error = 0;
float slope = (float)dy/dx;
int y = y1;

for(int x=x1; x <= x2; x++){
point(x,y);
error = error + slope;
if(abs(error) >= 0.5){
y = y+1;
error = error - 1.0;
}
}
}

//Circle
void setup() {
size(300, 300);
}
void draw() {
drawMyCircle(150, 150, 100);
}

void drawMyCircle(int x1, int y1, int radius){
int f = 1 - radius;
int fx = 1;
int fy = -2*radius;
int x=0;
int y=radius;
point(x1,y1+radius);
point(x1,y1-radius);
point(x1+radius,y1);
point(x1-radius,y1);

while(x <>
if(f>=0){
y--;
fy += 2;
f += fy;
}
x++;
fx += 2;
f += fx;
point(x1 + x,y1 + y);
point(x1 - x,y1 + y);
point(x1 + x,y1 - y);
point(x1 - x,y1 - y);
point(x1 + y,y1 + x);
point(x1 - y,y1 + x);
point(x1 + y,y1 - x);
point(x1 - y,y1 - x);
}
}
//Web
void setup() {
size(300, 300);
}
void draw() {
drawMyWeb(75);
}
void drawMyWeb(int n) {
for(int i=0; i < n; i++){
line(0,n-i,i,0);
}
}

Thursday, January 8, 2009

Homework #1 - Sheep



size(200, 200);
ellipse(100, 100, 100, 70);
ellipse(50, 100, 25, 70);
ellipse(45, 90, 7, 15);
ellipse(50, 131, 13, 7);
line(57, 90, 70, 110);
line(150, 100, 170, 70);
line(75, 130, 60, 160);
line(75, 130, 90, 160);
line(125, 130, 110, 160);
line(125, 130, 140, 160);