Sunday, April 08, 2007

There are days, that have very special events, that are rearly forgotten. There are other days..when it's mostly because one is very tried, full of troubles, that evetything just seems to pass by. This was happening to me, a week ago. It was actually really helpful for me to take this week off. I think I'm thinking clearer, really paying attention to what I'm doing.
Anyway, I was sitting in my living room, and sudenly something crossed my mind...What as I doing two tuesdays ago???? What was I doing in my favorite lab class???

I remember it was March 27, 10 days after my mom's birthday but bla bla bla bla bla my other l
when I was 7 or 6 , I rememebr I had to do a picture of how I'd be when I was grown up. I rmemeber I drew myself with long straight hair, (i used to have straight hair) with a pen in my hand. I wanted to be a writer , when I grew up. I loved writing, I rememebr I would mont little plays for my school friends, I'd do differnet voices and interpreat diffenet characters...

Now, those days of writing are long gone. ... I think I stopped writitng writing, because ...
I don't quiet know why. Maybe it had something to do with my parent's approval. I guess that could explain, why I'm currenlty studying computer engineering!
Don't get me wrong, I enjoy programming, and I do love math, learing new things, finding solutions...but I miss playing, I miss making up characters, interpreating them...

ANyway, returning to the matter, that day in my Graphics lab class, my dear teacher, showed us a munch of neat examples using glut. We saw an example of a fractal.
I was really intreged by it.
I made my own little fractal here, which can be view by a special little window, this window can view only the desired part of the fractal. (we also saw some things about glutSpecialFunc (SpecialKey), as well as swapBuffers, which can help the screen not seem as if it is twiching...
I'm including as always the code->

#include // Header File For The GLUT Library
#include // Header File For The OpenGL32 Library
#include // Header File For The GLu32 Library
//#include // Header File For sleeping.

#include "MyDefs.h"

// Some global vars
float CD = 0.0f;

sPoint CP, pa;
sPoint UpperLeftCorner, LowerRightCorner;
bool StartClipping = false;
bool IsDragging = false;
boolean right=false;
boolean left=false;
boolean top=false;
boolean bottom=false;

int main( int argc, char **argv)
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB );
glutInitWindowSize( 500, 500 );
glutInitWindowPosition( 0, 0 );
glutCreateWindow( "Snowflake" );
glutDisplayFunc( display );
glutMouseFunc( mouse );
glutMotionFunc( mouseDragg );

return 0;

void myInit( void ){
// Black as bk
glClearColor( 0.0, 0.0, 0.0, 1.0 );
//Draw color
glColor3f( 1.0, 0.0, 0.0 );
// Projection Matrix
glMatrixMode( GL_PROJECTION );
gluOrtho2D( -12.0, 5.0, -6.0, 10.0 );
glMatrixMode( GL_MODELVIEW );

UpperLeftCorner.x = 0.0f;
UpperLeftCorner.y = 0.0f;

LowerRightCorner.x = 0.0f;
LowerRightCorner.y = 0.0f;

// Builds the Koch curve, recursive
void Koch( float dir, float len, int n ){
if( n > 0 ){
Koch( dir, len/3, n-1 );
dir = dir + 60.0f;
Koch( dir, len/3, n-1);
dir = dir - 120.0f;
Koch( dir, len/3, n-1);
dir = dir + 60.0f;
Koch( dir, len/3, n-1);
bool isDrawn = true;
sPoint paAux;

pa.x = CP.x + (double)len*cos((double)(rads*dir));
pa.y = CP.y + (double)len*sin((double)(rads*dir));

paAux = pa;

if( StartClipping ){
/// Aqui deben colocar su rutina de recorte, en el caso del codigo que desarrolle iba asi
/// isDrawn = clippingWindow->clipLine( &CP, &pa );
/// isDrawn es un booleano que dice si la linea es visible y se usa en el if fuera de esta condicion
/// CP y pa son dos estructuras que les paso. La estructura es muy simple, solo contiene un punto
/// Por ahora dejo encendido el valor de isDrawn, para que se dibuje la region de recorte y toda la curva
/// Cuando coloquen ustedes su rutina, entonces solo sera visible la linea indicada por CP y pa

//isDrawn = true;
isDrawn = cyrusBeck(CP, pa, UpperLeftCorner, LowerRightCorner);
//std::cout << "I am alive" << cp =" paAux;" cp =" paAux;" dist =" 0.0f;" x =" CP.y" state ="=" realy =" viewport[3]" z =" 0.0" x =" wx;" y =" wy;" isdragging =" false;" window =" [(%f,">(%f, %f)]\n", UpperLeftCorner.x, UpperLeftCorner.y, LowerRightCorner.x, LowerRightCorner.y);

if( UpperLeftCorner.x > LowerRightCorner.x ){
pAux.x = UpperLeftCorner.x;
UpperLeftCorner.x = LowerRightCorner.x;
LowerRightCorner.x = pAux.x;

if( UpperLeftCorner.y < y =" UpperLeftCorner.y;" y =" LowerRightCorner.y;" y =" pAux.y;">SetClippingWindow( UpperLeftCorner, LowerRightCorner );

StartClipping = true;
if( state == GLUT_DOWN )
}//End mouse

void mouseDragg( int x, int y){
GLint viewport[4];
GLdouble mvMatrix[16], projMatrix[16];
GLint realY;
GLdouble wx, wy, wz;

glGetIntegerv( GL_VIEWPORT, viewport );
glGetDoublev( GL_MODELVIEW_MATRIX, mvMatrix );
glGetDoublev( GL_PROJECTION_MATRIX, projMatrix );

IsDragging = true;

realY = viewport[3] - (GLint)y - 1;

gluUnProject( (GLdouble)x, (GLdouble)realY, 0.0f, mvMatrix, projMatrix, viewport, &wx, &amp;amp;wy, &wz );

LowerRightCorner.x = wx; LowerRightCorner.y = wy;


bool cyrusBeck( sPoint& p0,
sPoint& p1,
sPoint UpperLeftCorner,
sPoint LowerRightCorner ){

if( p0.x == p1.x && p0.y == p1.y ){
const double ulcXdiff = p0.x - UpperLeftCorner.x;
const double ulcYdiff = p0.y - UpperLeftCorner.y;
const double lrcXdiff = LowerRightCorner.x - p0.x;
const double lrcYdiff = LowerRightCorner.y - p0.y;

* Si ulcXdiff < 0 =""> esta fuera del lado Izquierdo
* Si ulcYdiff < 0 =""> esta por arriba del clip area
* Si lrcXdiff < 0 =""> esta fuera del lado derecho
* Si lrcYdiff < 0 =""> esta por abajo del clip area

if( ( ulcXdiff < t_left =" NOINTERSEC;" t_right =" NOINTERSEC;" t_up =" NOINTERSEC;" t_bottom=" NOINTERSEC;" x =" p1.x" y =" p1.y" te =" 0," tl =" 1" temp =" 0;" den =" dotProduct(right_normal," x="UpperLeftCorner.x;" y="(LowerRightCorner.y-UpperLeftCorner.y)/2;" num =" dotProduct(left_normal," temp =" num/den;" t_left="temp;" t_left =" ("> 1)? NOINTERSEC: temp;

//if( t_left != NOINTERSEC ){
den *= -1;

if( den > 0)
tE = getmax(tE,t_left);
else tL = getmin(tL, t_left);
std::cout << "Izquierda" << x =" p0.x" y =" p0.y" x =" p0.x" y =" p0.y" den =" dotProduct(left_normal," x="LowerRightCorner.x;" y="(LowerRightCorner.y-UpperLeftCorner.y)/2;" num =" dotProduct(right_normal," temp =" num/den;" t_right ="temp;"> 1)? NOINTERSEC: temp;

//if( t_right != NOINTERSEC ){
den *= -1;

if( den > 0) tE = getmax(tE,t_right);
else tL = getmin(tL, t_right);
std::cout << "Derecha" << den =" dotProduct(bottom_normal," y="UpperLeftCorner.y;" x="(LowerRightCorner.x-UpperLeftCorner.x)/2;" num =" dotProduct(up_normal," temp =" num/den;" t_up="temp;"> 1)? NOINTERSEC: temp;

//if( t_up != NOINTERSEC ){
den *= -1;
if( den > 0) tE = getmax(tE,t_up);
else tL = getmin(tL, t_up);
std::cout << "Arriba" << den =" dotProduct(up_normal," y="LowerRightCorner.y;" x="(LowerRightCorner.x-UpperLeftCorner.x)/2;" num =" dotProduct(bottom_normal," temp =" num/den;" t_bottom ="temp;" bottom="true;"> 0)tE = getmax(tE,t_bottom);
else tL = getmin(tL, t_bottom);

std::cout << "Abajo" << x =" p0.x" y =" p0.y" x =" p0.x" y =" p0.y">

No comments: