Sunday, March 30, 2008

easy 2d movement.

Now for something rather simple a few days ago I explained a bit of moving in an array. But now lets say we want to move in a 2d plane and have any angle of direction. Well lets say the top left corner is position 0,0 and that looking directly right is rotation 0. So now that we have all our references lets make a formula that will let us move a unit in any direction. According to our references 0 is looking right, therefore if we are looking directly right we are going to move only in the x field therefore we need to use cosine in order to move since cosine of 0 is 1, also sine of 0 is 0. Now if we consider that the rotation is made clockwise, and that 90 is looking downward, then using cosine for x and cosine for y works well. Therefore we need to store a position variable and a rotation variable and each time we move forward the new position will be position + (cosine(angle),sine(angle))*unit and moving backwards would be position - (cosine(angle),sine(angle))*unit. Very easy. Now for collisions there are a bunch of different ways. the easiest is the collision between two dots. Basically a collision happens only if the two dots are in the same position. We could also have a collision between a dot and a circle. First you get the distance between the dot and the circle, then get the radius of the circle. If the distance is smaller than the radius then there is a collision. We can have collision between two circles, this time we also need the distance between the center of the two circles, then if the distance is smaller than the sum of both radius we have a collision.
There are many different collision tests each of them get more complex depending on geometry of the objects, but thats all for today.
back to the code

argc and argv

So today's brief blog is about the argc and argv in that appear besides the main function when dealing with c++ console applications. Basically argc is the number of arguments that the program gets when its open, and *argv[] is an array that contains the arguments. The first argument tends to be the direction in your hard drive of the program, and the next arguments may vary. For example you could open your program using the command prompt and write something after the dir of the program, and that will become the argument. Separate it by space and you will have more arguments. Now, what things can we do with this. I mean, we might like to use the command prompt, but the users usually don't so whats use for them?
One nice thing about it, its opening files. Try making a file and end it with anything you want after a dot like .test and create a program that uses the second value of argv to open and read from the file. Then open your file with the program. Guess what, the second value will be the direction to the file. So you will have your own custom file.

back to the code.

Friday, March 28, 2008

NODES! and dynamic stuff

yay for nodes I say, they make adding dynamic content easy when making a class of nodes, each class will contain something, it can be numbers and stuff variables and functions that will affect and work and stuff. Virtually anything you want to store there but not only that, each node class will be pointing to the next node class, so they will contain a pointer. This is very useful for having dynamic data.
Picture this, you have a ball, the ball bounces around. You have two balls doing this, no prob. You want to add a bunch of balls that do different things by themselves, we might have a problem. Specially since computer works rather linearly, each line of code is executed one at a time so how can you even have several objects doing things at the same time. Well you can have each ball pointing to the next one and then all you need is to go from one ball to another calculating the behavior and when you reach the end of the list of nodes you begin again. and suddenly, we have the impression that we have object oriented programing! since each object will require some time of the machine to calculate its behavior, since the machine tends to be fast (unless you have enough calculations to slow down your pc in each object)
now here is an example of stuff in c++
class ball
{
//some variables
public:
ball();
~ball();
void behavior();
ball *next;
};
so then we can create a pointer that will always point to the first element and a pointer that will move in a way that it will stop when
pointer->next == NULL
=D FUN

but I say this is not the only approach to have some dynamic objects you can add dynamically and access them one by one.

we could have an array of pointers. actually a dynamic array of pointers.
here we have someting like that
class pointaray
{
int size, **data;
public:
pointaray();
pointaray(int);
~pointaray();
int value(int);
void set(int,int);
void add();
void del(int);
};
yeah doesn't explain much that but with several functions I can create some objects, destroy some objects, and dynamically modify the array and add elements by going
data[x] = new int;//and or any other class I want to handle there.
this method loosely explained here, well has some advantages and some bad stuff. the good thing is you can quickly access a point in the array if you know the number, the bad stuff is you have to have more functions.
While the other method just go to the next, but you have to crawl one by one. Well some ideas and tools you might need to use in the future.

Thursday, March 27, 2008

Thinking in Triangles and vertex

Well lately I been looking into the wonderful world of openGL. Making 3d programs seem easy until you start digging in the books and making the code. So as part of a quick warning, coming from a noob in the library, you have to start thinking in triangles and vertex. You could also have quads but basically the graphic card (the wonderful thingy in your pc that does most of the magic of the grafics) works with triangles. A relief is that you don't have to make all the libraries for drawing objects in a 3d space, so some rotations and perspective are already programed, yay. Also each vertex can be colored and each triangle textured and the library along with the graphic card does the work of making it look 3d. YET this doesn't mean your just going tell the program to load an object just like that and have a world done without making first an engine. The basic is, all triangles have to be declared, a triangle consists of 3 vertex and each vertex consists of 3 opengl floats, so its a lot of information per triangle, but thats where the magic of opengl pipeline works with, it connects directly to the grafic card so that large amount of information can pass quickly to the grafic card prossesed and from there to your monitor. A prosses that is done quite fast considering most of todays games have thousands to sometimes millions of vertex in each frame that are constantly changing.

here is a bit of simple code
glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();
Of course the complete code for displaying an opengl window is more complex. and varies depending on OS, but I will dedicate this blog just to give a heads up idea of what your gonna get into the future, so your not surprised later. So to start making your work easy you will need arrays of vertex and loops to display thousands of triangles efficiently and without loosing your head hard coding shapes.

that for now and back to the code.

Wednesday, March 26, 2008

Yay for rss

I have now added rss (Really Simple Syndication) to my blog. Now people can subscribe to my rss and they receive news feeds of new interesting (hardly interesting) blogs about things. That way you can keep up to date to my ramblings about computers and mental problems. I also added a bunch of buttons that are better to use by moving your mouse over the Subscribe section and using the scroll down because there a bunch haha.
By the way to add rss to your blog is rather simple using feedburner, a site where you set a feed site just follow the simple instructions, and adding the feed link to the blog on the customize section, settings, side feed section. also this site http://www.toprankblog.com/tools/rss-buttons/ is good for making rss buttons quickly. >.> maybe I overdid it.
yay.

Now lets see how this Post appears on the rss.
back to the code.

Tuesday, March 25, 2008

Basic formulas for array movement and data storage

So we want to play with numbers we want useful formulas now and then so lets start this.
we have one dimension
0
is a zero one number only one in size, lets call this dimension x
0,1,2,3
x is now of length 4 so x < 4 =" 9." 4 =" 2" x =" number" 1="4" 1 =" 6" 4=" 1" 4 =" 9" x =" Floor(number/(4*3))%4" y =" Floor(Floor(number/(4*3))/4)" z =" Floor(number/(4*3))" position =" position" position =" position" p =" 0" 0 =" 1" 1 =" 1">>0 = 1
1 is the bit in position 0
p = 1
1<<1 2 =" 0">>1 = 0
0 is the bit in position 1
P = 2
1 <<2 4 =" 4">>2 = 1
1 is the bit in position 2
just so you know the bitwise operators are close together with the tables of truth but they operate at a bit level, so think of every number as a bunch of truths and false

Ideas...

Well here is an idea for you to steal so I can whine later. I have already started developing it so its not just a dream. Now see, there are many kinds of rpgs out there, but we can divide the map systems in two categories. We have the most common, the preset maps, those wonderful maps fully made by the hand of artists are great, people can travel in them, do stuff in them, and get familiar with them, so they can always come back and say, I know this place. But these kind of maps are limited, require time to make and in the end, they are explored several times and they get old. Then comes the random maps, here we can have unlimited fun, several variables can cause a virtually endless (A.K.A HUGE calculable number that we should not worry calculating). What happened with these kind of map is that you never know what you will get, you can never return to a place you like, and in the end, it starts becoming just random, the random feel that just tells you this is not virtually endless is just the same but moved around.
So my proposal is, lets break the barrier and dig deep into development, (lets forget how much ram it will eat each time you enter a new map), lets work with pseudo random (basically the current random is also pseudo random but I'm talking about a more controlled random). In this process we will ask the player were to go, the player can say anything that comes out of their head, and then our system starts to work.

Basically we need key words, your common regular chat AI has them, to affect the variables. Lets not say you want to go to a castle and end up in a cave. Below the keywords comes other types of processes (some of them already programed by the way) in which we will turn the entire string into numbers. We need to ensure that no matter how long the string or short, the same amount of numbers are extracted from the string. And once we have enough numbers that are pseudo random but come from that string, we can go and work with the carefully developing of the map, and several other objects, colors virtually everything we can add a variable to and fuck up the ram. no not really the process is simple we are creating the objects on the go after that it works as your regular game just with custom made objects.

Now picture this, by working on the lowest levels of programing and slowly building up is so we can do this, having total control of the output and what we will generate is a good idea, since that we can create custom walls, custom floors, with custom colors. But always following intelligence, not going and adding numbers everywhere. Processes of symmetry, of keeping patterns. Basically we build the patterns, and rules that will apply to create a unity, then we add styled effects and generate more artistic looking environments. Preset patterns are good guidelines to keep things in place, we don't want the extreme to look too extreme. So basically become an artist, and study yourself, then put those rules on code and let them freely interact and develop, the more deep you go the more different environments can exist(no more random generators that use the same walls for everything but a generator that generates the walls). If we want we can create textures and pretty much everything an artist does and fine tune it until allmost all maps are unique and beautiful.

now stick some sockets, some server and some other algorithms and we have something.

well that is for today I'm back to the code.

Lunatic Night walk. The nocturnal Pilgrim

Lunatic night walk.


So on march 25, 2008 I lost my mind I tough it was time to do something different so I decided lets open those gates and go outside. It was 12:45 am and I was talking in the internet with my best friend, as he kept telling me not to do it that it was too late in the night to go for a go for a walk, but I went out anyway it was nice outside.


After reaching the college's lateral gate I decided I was taking a regular path, and it was boring so I decided to just change the path a little, so I walked in the empty area by the college. in there I smelt the sent of cow manure and heard the beautiful sound of water. Also I saw a hobo sleeping. Also I went and took the bridge on the north since the gates to the highway on the back of the college were closed. The bridge looked awesome, there was moss growing all over the metal fence around it and a tree had its branches growing inside the bridge wish gave a feeling of some kind of jurasik park movie.

So I went to pay a visit to my old art building. Before getting there I got the feeling I was just in a nightmare, as the street entered the mountain light went to a sudden stop revealing a rather pitch black area. I felt I was just dreaming, that I was just in another nightmare where the expected happens. But while entering the darkness I could see a bit, so I felt secure, specially since it was still a known place. it was later when I pushed on past the art building that the tension got worst. Story short I was fearing the sidewalk would end, in the way someone yelled at me junky and then some Doberman or pit bulls, it was to dark to see but rather large and black started barking and pushing the fence. I finally found the end of the sidewalk and had to move back. As I walked back I herd howling from the dogs and winning also some of the howls sounded rather strange and terrifying. accompanied by other noises I doubt came from dogs.

so after retracing back I went back to college, were I saw two nocturnal birds that are endangered specie, one before entering the bridge again and another in that area with the yellow arrows that means I walked in and then walked back. in the rest of this way, My good friend Gerson called me, so I told him I was just insane.

So out of college and back to the main highway, I went to walk in front of "La cerveseria India" and to my amazement there were people working in it, and thru one door I saw how many of the distinctive golden cans passed by. But I kept walking until I reached the city. And then I just walked a long road. And walked.

on and on.

and on

I was starting to get creeped out houses were getting older and uglier, places started to look more and more abandoned, the only thing that kept me going was, the smell of laundry detergent and candles... Candles? I smelt some strong sent of sencted candles. What made me feel rather odd, but all I could hear was some music comming from a cars mechanic place. I was starting to worie, because there was no other streets I could take until I saw a black cat. I said, time to move back, but then I saw a white cat and ended up walking around some huge abandoned building in where I heard some low whinnying or maybe a tv. but I don't think a tv was possible in that weird place where stairs seem to come and go from darkness to nowhere. I turned back the place looked rather spooky, I ended up behind a gas station so I went back the same street I came in

then I decided to turn and see the plaza, wish was rather cute. the church was close at that hour. so I couldn't see it

as I left the plaza I went tru a street that had a nice smell of bakery but nothing was open, so I kept on walking until in one street I saw a hobo walking toward me so I walked faster and turned the next street. then reached the bus terminal where I saw someone coming out of one of the offices.

finally I walked back and in here I had the odd experience that while I was walking a car flashed my eyes from the distance and I scratched my eyes for a second finding out the street was completely empty the car had dissapired from the entire highway. Then I went to wallgreens the only place open in the entire city where there was two people buying things, the cashier had to move to another cash register since the one he was in didn't scanned wet things. I was buying some passion fruit juice.

AND I got home where I drank 4 sleeping pills and 2 pain reliving pills and slept till next class.

casualties: My converse shoes have holes in their soles.

4 am