|
Let There Be Light! Oct 08, 2009 |
|---|
| That's right! and God is not saying it, I AM!
Here are some images of my lighting work for Interactive Computer Graphics. I wrote the code here from scratch. The only portion of OpenGL function I use is "drawPixels." All the math and all the programming is my work. I am very proud. Ambient Lighting
 Diffuse Lighting
 Phong(Specular) Lighting
 Here they are combined nicely.
 TextureI have also been working on textures.
 
Building Blocks 
| | View Comments | | Leave a Comment | | | Java-like instanceof Oct 04, 2009 |
|---|
So I was hoping c++ had a Java-like instanceof function. It didnt as far as I could find... Lame. Instead I have to include an enumerated value in all of my subclasses to determine which subclass of a light i am dealing with... This sucks.
enum type {AMBIENT, DIFFUSE, PHONG};
class Light{
public:
Light(unsigned int color, float strength, type lightType);
unsigned int getColor();
type getType();
virtual void update(vector meshes);
protected:
type lightType;
unsigned int color;
float strength;
};
Thoughts, anyone? Is there a better way? | | View Comments | | Leave a Comment | | | Forward Declaration Oct 03, 2009 |
|---|
| Something tells me Forward Declaration as a means to avoid Cyclic Dependencies in C++ is a bad idea... I am using them anyway because it seems to be a super simple solution to what can be a REALLY ugly problem... Anyone have any thoughts on this? I am interested in hearing what others think. All I know is Java handles this for me and C++ doesn't. Some people claim it means I have probably made some bad design decisions, but I have a hard time believing that (not because I am perfect, but because if it was a bad design thing, Java would probably stop it from occurring as well instead of handling it for me.)
For those who dont know what I am talking about, I will give a quick example: I have a class which contains a reference to another class in the header. The second class I mentioned contains a reference in its header to the first class I mentioned. For each I must include the header of the other class. This causes a "Cyclic Dependencie."
Here is an example of a Forward Declaration:
#ifndef SCENE_H_
#define SCENE_H_
#include
#include "gui.h"
#include "framebuffer.h"
#include "tmesh.h"
#include "path.h"
#include
class Light; // THIS IS THE FORWARD DEC.
class Scene {
private:
FrameBuffer *fb;
vector meshes;
PPC *ppc;
vector lights;
.
.
.
#endif
| | View Comments | | Leave a Comment | | | Sliding Window Buffer Sep 17, 2009 |
|---|
The last few days I have been writing some utilities and data structures for use in my STCP (Simplified Transport Control Protocal) Layer. I have never really done a code-review over blog before but I figure it cant hurt.
Nor have I posted much code here, so its a good test for my formatter.
What I have been working on most recently is the Sliding Window Buffer to keep track of data being passed to the application layer and to the network layer. It is not done because currently it does not have any of the reliability utilities it will require. eg production into specific locations in the buffer and the ability to peak into specific locations in the buffer. Anyway, here is the code: (oh, I have to warn you... It has been a while since C/C++ was my main language so some if this stuff may be bad ideas. I am happy to take any constructive criticism)
#include /
#include /
#include /
#include /
#define BUFFER_SIZE 3072
struct sliding_window_buffer{
int window_start;
int window_end;
char *buffer;
}to_application, to_network;
static void init_buffer(struct sliding_window_buffer *swbuffer, int start){
swbuffer->buffer = (char *)malloc(BUFFER_SIZE);
assert(swbuffer->buffer);
swbuffer->window_start = start;
swbuffer->window_end = swbuffer->window_start;
for(int i = 0; ibuffer[i] = '\0';
}
}
static void consume(struct sliding_window_buffer *swbuffer,
int bytes, void *ret){
if(swbuffer->window_start == swbuffer->window_end
&& swbuffer->buffer[swbuffer->window_start] == '\0'
&& swbuffer->buffer[swbuffer->window_start+1] == '\0'){
//IT APPEARS THE BUFFER IS EMPTY, THERE IS NO DATA TO CONSUME
}
else{
//IF THE DATA TO CONSUME DOES NOT CROSS FROM END TO BEGINNING
if(swbuffer->window_end+bytesbuffer+(swbuffer->window_end%BUFFER_SIZE), bytes);
//SET THE MOVED DATA TO THE NULL CHARACTER TO EMPTY THE BUFFER
memset(swbuffer->buffer+(swbuffer->window_end%BUFFER_SIZE), '\0', bytes);
//MOVE THE END OF THE WINDO TO ITS NEW LOCATION
swbuffer->window_end = (swbuffer->window_end + bytes)%BUFFER_SIZE;
}else{
//THE DATA STARTS AT TH END AND CROSSES TO THE BEGINNING OF THE BUFFER
//MUST CONSUME IN TWO PARTS AND THEN COMBINE THE PARTS TO RETURN
void *part_one, *part_two;
int size_of_part_one = BUFFER_SIZE-swbuffer->window_end;
int size_of_part_two = bytes-size_of_part_one;
part_one = malloc(size_of_part_one);
assert(part_one);
part_two = malloc(size_of_part_two);
assert(part_two);
//GET PEICES
//THIS RECURSIVE CALL SHOULD TAKE CARE OF MOVING OUR WINDOW
//AND RESETTING THE BYTES
consume(swbuffer, size_of_part_one, part_one);
consume(swbuffer, size_of_part_two, part_two);
//REASSEMBLE
memcpy(ret, part_one, size_of_part_one);
memcpy((char*)ret+size_of_part_one, part_two, size_of_part_two);
free(part_one);
free(part_two);
}
}
}
static void produce(struct sliding_window_buffer *swbuffer,
int bytes, void *prod){
//IF THE BYTES TO MOVE ARE NOT TOO LARGE FOR THE BUFFER
if(byteswindow_start == swbuffer->window_end
&& swbuffer->buffer[swbuffer->window_start] != '\0'
&& swbuffer->buffer[swbuffer->window_start+1] != '\0'){
//IT APPEARS THE BUFFER IS FULL, THERE IS NO ROOM FOR YOUR DATA
}
else{
int space_left;
//DECIDE HOW TO CALCULATE THE AMOUTN OF SPACE LEFT
//DEPENDS ON THE ORDER OF THE START AND END OF THE BUFFER
if(swbuffer->window_end>swbuffer->window_start){
space_left = swbuffer->window_end-swbuffer->window_start;
}else{
space_left = swbuffer->window_end-swbuffer->window_start+BUFFER_SIZE;
}
//IF THE BYTES TO MOVE IS GREATER THAN THE SPACE LEFT
if(bytes > space_left){
//FIT THE SIZE TO MOVE IN BYTES TO THE SIZE LEFT IN THE BUFFER
bytes = space_left;
}
//IF BYTES WILL FIT BEFORE THE END OF THE BUFFER
if(bytes+swbuffer->window_startbuffer+swbuffer->window_start, prod, bytes);
}else{
//BYTES SPAN FROM END TO BEGIN
//WILL REQUIRE TWO COPIES
memcpy(swbuffer->buffer+swbuffer->window_start,
prod,
(BUFFER_SIZE-swbuffer->window_start));
memcpy(swbuffer->buffer,
(char*)prod+(BUFFER_SIZE-swbuffer->window_start),
bytes-(BUFFER_SIZE-swbuffer->window_start));
}
swbuffer->window_start = (swbuffer->window_start+bytes)%BUFFER_SIZE;
}
}else{
printf("ERROR: BYTES ADDED WERE LARGER THAN THE BUFFER");
}
}
void destroy_buffer(struct sliding_window_buffer *swbuffer){
free(swbuffer->buffer);
}
int main(){
//SOME TESTING... NOT STRENUOUS
init_buffer(&to_application, 200);
void *half = malloc(strlen("some_bytes")/2);
consume(&to_application, strlen("some_bytes")/2, half);
printf("Empty: %s\n", half);
void * some_bytes = malloc(strlen("some_bytes"));
memcpy(some_bytes, "some_bytes", strlen("some_bytes"));
produce(&to_application, strlen("some_bytes"), some_bytes);
consume(&to_application, strlen("some_bytes")/2, half);
printf("first 5: %s\n", half);
consume(&to_application, strlen("some_bytes")/2, half);
printf("second 5: %s\n", half);
consume(&to_application, strlen("some_bytes")/2, half);
printf("third 5: %s\n", half);
destroy_buffer(&to_application);
return 0;
}
edit: I am not taking this down, but I just noticed that though it compiled nicely, I forgot to run it... haha. I got some nasty errors. I will replace the code here when I figure it out.
edit: It has been updated. It was pretty obvious. I was thinking I had malloc'ed the buffer struct, so when I went to destroy it, I tried to free it and well... that was illegal! | | View Comments | | Leave a Comment | | | Rip Van Winkle Awakes Sep 12, 2009 |
|---|
I have not written in FOREVER, but I wont say any more about that because it does not make for good content. Instead I want to talk about my first few weeks at Purdue.
Grad school started like 3 weeks ago and it has been in full swing since day one. Before classes even started, I had my first assignment. Before I tell you about that, I want to tell you about my classes.
So I am taking Interactive Computer Graphics, Computer Networks and Algorithms. All three courses are PhD qualifying courses and so I will most likely be taking three Quals this semester. I hope I pass them all. If I can, then I only need one more Qual(Programming Languages I hope). The PhD qualifying progress is quite intensive. Instead of going into detail, I will just point you to the degree description on the CS homepage.
Ok, so homework so far has been NO PIECE OF CAKE. The first assignment in networking was the implementation of an HTTP server in C/C++. In order to test the server, we wrote a multi-threaded load generating client and then a report on the results of our server. (some of the ugliest code I have ever written. I am not happy with the way it turned out.) The next assignment in Networking is the implementation of a reliable TCP layer to sit underneath our server. Other than the simplification of some parts of the TCP layer, the main difference between my TCP and the real underlying TCP is that my TCP will handle dropped packets. I am getting better with C and C++ with everything I do, so hopefully I will be happier with the end result of this project.
In Computer Graphics, my first assignment was to implement some 3D Vector and Matrix classes and show that they work using OpenGL graphics.
There is so much more that I could say about my upcoming projects (programming and written homeworks) but I will just leave it all at that for now.
I am beginning to feel overwhelmed. With the amount of work which is required here. Ball State was a walk in the park compared to everything I have to do. I am sure its because it is grad school, but the professors leave much more up to the students. So far I have not really been taught much of anything. They just tell us to go off and learn it for ourselves... Its kinda weird.
Wish me luck, this is not going to be easy... | | View Comments | | Leave a Comment | | | MS Silverlight on FF Jun 26, 2009 |
|---|
| Ok... I know I have not posted in a while and I am fairly sure no one cares and this is just here for me at this point, but I wanted to ask in case someone, anyone, was reading... Are you as surprised as me that Silverlight runs on FF?
I never saw it coming... I think Microsoft made a smart move here. I thought they were gonna make it only work on IE7 and 8... Nice work MS... You have surprised me... | | View Comments | | Leave a Comment | | | "NuCube" - Working Title Apr 21, 2009 |
|---|
Howdy. I picked up an old project recently. Sometime last semester I started writing a 3D puzzle game. Its really just another color matching, block dropping, puzzle game. At the start of the game, you see a 4x4 grid in which you are expected to drop different color blocks. Combinations of 6 or more are destroyed, dropping any boxes which may have been placed on top of them. The 3D aspect adds an interesting challenge of remembering what blocks might be hidden from view. I never got it into working condition last semester, but in just a few short sessions I managed to get it into a playable state.
 The camera rotates by holding down the right mouse button and dragging. You can move 360 degrees around the cube, but I opted to remove the ability to change the vertical angle. It added an unnecessary level of complexity to an already overly complex user control system. Speaking of which, the controls to move the blocks around are WASD but they do not move with the camera, so if you move 180 degrees from the original position, you have effectively reversed the controls(Not Fun). I am open to suggestions on how to fix that ugly aspect.

 As you can see, by the opening screen, I could use some nicer graphics, but I am not an artist. Maybe I can get an artist friend to make me a cool logo or something.
 Here is a link to everything. Its pretty large because I think the source may also be in the runnable jar. Just Unzip it and open the runnable jar (should work if you have Java installed. If you dont have java installed, then you need to install it anyway, so go to http://java.com/getjava/) - Oh, and lastly, I wanted to say that I used JMonkeyEngine. If you dont already know, its a nice scene graph based 3D game engine. That is all for today I think. Later! | | View Comments | | Leave a Comment | | |
|
|
Links
Recent Posts
Archive
|
|