• What are you working on? V7
    2,001 replies, posted
I think I'll try to code portals in xna... I'm thinking about something like this: You get the relative position and rotation from the camera to portal A. Then you render the scene with that position and rotation, viewed from portal B. When you have that texture, you project it onto portal A and voila?
[QUOTE=efeX;20332862]Do you dare paste it? :v:[/QUOTE] His might be longer. 2 more lines for me and mine would be 1,000 lines.
[QUOTE=s0ul0r;20332933]I think I'll try to code portals in xna... I'm thinking about something like this: You get the relative position and rotation from the camera to portal A. Then you render the scene with that position and rotation, viewed from portal B. When you have that texture, you project it onto portal A and voila?[/QUOTE] Yeah or just use the stencil buffer and skip projecting a texture.
[QUOTE=TheBoff;20323021]In C++ does an enum belong in a .cpp, or a .h file?[/QUOTE] If it's part of the interface, put it in the header. If it's internal to a single file, put it in that file.
[QUOTE=The Inzuki;20333283]His might be longer. 2 more lines for me and mine would be 1,000 lines.[/QUOTE] //Ughh... //Win 1000.
I generically don't have a lot in main.cpp But I program for iPhone, where if you use main.cpp, your going crazy. e.g. main.cpp in my "Gold Digger" game (Windows): [code] #include <allegro.h> #include <cstdlib> #include <cmath> #include <ctime> #include <time.h> #include <iostream> #include <fstream> #include <dir.h> #include <string> #define debug false // --------------------------------------------- \\ /* CUSTOM *.H FILES */ /* * === player.h === * Contains the player model */ #include "player.h" /* * === rock.h === * Contains the rock model */ #include "rock.h" /* * === rect.h and misc.h === * Contains the rectangle model * Contains misc functions */ #include "rect.h" #include "misc.h" // --------------------------------------------- \\ using namespace std; // used for FPS regulation volatile long counter = 0; void intCtr() { counter++; } int main(int argc, char *argv[]) { // Thanks to anihex for finding the game's directory. if (!debug) { string AppPath = argv[0]; int FoundAt = AppPath.find_last_of("/\\"); AppPath = AppPath.substr(0, FoundAt+1); chdir(AppPath.c_str()); } allegro_init(); install_keyboard(); install_timer(); install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, 0); set_color_depth(16); int sW, sH; sW = 640; sH = 480; srand( (unsigned)time(NULL) ); bool fullscreen = false; set_gfx_mode( GFX_AUTODETECT_WINDOWED, sW, sH, 0, 0); // classes Player player; player.init(); Rock rock; rock.init(); // variables bool exit = false; // [[[ bool rrd = false; // Man, I love how I aligned these. int dir = 0; // They look all neat and stuff!!! int errors = 0; // :) int scrn = 1; // ]]] BITMAP *buffer = create_bitmap(sW, sH); BITMAP *menu = load_bitmap("data//bitmaps//menu.bmp", NULL); BITMAP *spritesheet = load_bitmap("data//bitmaps//sprites.bmp", NULL); BITMAP *items = load_bitmap("data//bitmaps//items.bmp", NULL); BITMAP *bg = load_bitmap("data//bitmaps//background.bmp", NULL); BITMAP *about = load_bitmap("data//bitmaps//about.bmp", NULL); SAMPLE *bgm = load_sample("data//sounds//Spazed.wav"); SAMPLE *getg = load_sample("data//sounds//sound1.wav"); time_t creation = time(NULL); string error = ""; if (buffer != NULL) { error += "\nBuffer created!"; } else { error += "\nBuffer created incorrectly!"; errors++; } if (menu != NULL) { error += "\nMenu created!"; } else { error += "\nMenu created incorrectly!"; errors++; } if (spritesheet != NULL) { error += "\nSpritesheet created!"; } else { error += "\nSpritesheet created incorrectly!"; errors++; } if (items != NULL) { error += "\nItems created!"; } else { error += "\nItems created incorrectly!"; errors++; } if (bg != NULL) { error += "\nBackground created!"; } else { error += "\nBackground created incorrectly!"; errors++; } if (about != NULL) { error += "\nAbout created!"; } else { error += "\nAbout created incorrectly!"; errors++; } if (bgm != NULL) { error += "\nBGM created!"; } else { error += "\nBGM created incorrectly!"; errors++; } if (getg != NULL) { error += "\nGet_Gold created!"; } else { error += "\nGet_Gold created incorrectly!"; errors++; } LOCK_VARIABLE(counter); LOCK_FUNCTION(intCtr); install_int_ex( intCtr, BPS_TO_TIMER(90) ); // Note: // - My code is iffy while (!exit) { Rect pc = player.returnCoords(); while (counter > 0) { //input if (scrn == 1) { if (key[KEY_ENTER]) { play_sample( bgm, 255, 128, 1000, true ); scrn = 3; } else if (key[KEY_A]) { scrn = 2; } } else if (scrn == 2) { if (key[KEY_X]) { scrn = 1; } } else if (scrn == 3) { if (key[KEY_LEFT]) { if (pc.x+player.returnSpeed() > 0+player.returnSpeed()) { player.move( LEFT ); } } else if (key[KEY_RIGHT]) { if (pc.x+player.returnSpeed() < 615+player.returnSpeed()) { player.move( RIGHT ); } } else if (key[KEY_UP]) { if (pc.y-player.returnSpeed() > (-1)) { player.move( UP ); } } else if (key[KEY_DOWN]) { if (pc.y+player.returnSpeed() < 435+player.returnSpeed()) { player.move( DOWN ); } } if (isCollision(player.returnCoords(), rock.returnCoords())) { error += "\nCollision detected at [x="+tostr(player.returnCoords().x)+" y="+tostr(player.returnCoords().y)+"]"; player.givePoint(rock.returnPoints()); if (player.returnPoints() % 10 == 0 && player.returnPoints() > 1) { // On the rare change of you having a whole numb er divisible by 10, you get 3 extra speed ;) player.setSpeed((player.returnSpeed()+1)); error += "\nPlayer has a score that is a multiple of ten! ["+tostr(player.returnPoints())+"]"; error += "\nPlayer's speed is now "+tostr(player.returnSpeed())+""; } if (rock.returnPoints() == 5) { player.setSpeed((player.returnSpeed()+1)); error += "\nPlayer's speed is now "+tostr(player.returnSpeed())+""; } play_sample( getg, 255, 128, 1000, false ); rrd = true; } } counter = -1; } // menu screen if (scrn == 1) { blit( menu, buffer, 0, 0, 0, 0, 640, 480 ); } else if (scrn == 2) { // about screen blit( about, buffer, 0, 0, 0, 0, 640, 480 ); } else if (scrn == 3) { // game screen // draw bitmaps /* layer 0 - bg */ blit ( bg, buffer, 0, 0, 0, 0, 640, 480 ); /* layer 1 - items */ rock.draw( buffer ); if (rrd == true) { rock.init(); rrd = false; } /* layer 2 - player */ player.draw( buffer ); // draw text textprintf_ex(buffer, font, 0, 0, makecol( 255, 255, 255 ), makecol( 0, 0, 0 ), "Score: %i Points! You are moving at %i MPH!", player.returnPoints(),player.returnSpeed()); if (debug) { // debug mode here textprintf_ex(buffer, font, 0,16, makecol( 255, 255, 255 ), makecol( 0, 0, 0 ), "DEBUG MODE IS ON"); bool iscollision = isCollision(player.returnCoords(), rock.returnCoords()); textprintf_ex(buffer, font, 0,24, makecol( 255, 255, 255 ), makecol( 0, 0, 0 ), "Player Collision: %s", ((iscollision)?"true":"false")); textprintf_ex(buffer, font, 0,32, makecol( 255, 255, 255 ), makecol( 0, 0, 0 ), "Player x: %i | y: %i | w: %i | h: %i",pc.x,pc.y,pc.w,pc.h); } } // blit buffer blit(buffer, screen, 0,0,0,0, sW, sH); // clear the buffer clear_bitmap( buffer ); if (key[KEY_ESC]) { error += "\nESC Pressed... Exiting..."; exit = true; } } // destroy the bitmaps created destroy_sample( bgm ); destroy_sample( getg ); error += "\n\nSAMPLE bgm destroyed...\nSAMPLE getg destroyed..."; player.dealloc(); rock.dealloc(); error += "\n\nPlayer deallocated...\nRock deallocated..."; destroy_bitmap( spritesheet ); destroy_bitmap( menu ); destroy_bitmap( items ); destroy_bitmap( bg ); destroy_bitmap( buffer ); destroy_bitmap( about ); error += "\n\nBITMAP spritesheet, menu, tems, bg, buffer, and about destroyed..."; // Write to the logfile error += "\n\nGame exited with "+tostr(errors)+" error(s)"; logfile(creation, error); return 0; } END_OF_MAIN(); [/code]
You anger the OOP gods.
[QUOTE=Ortzinator;20337165]You anger the OOP gods.[/QUOTE] That's no less of an abomination when it comes to the procedural paradigm either.
Ok so I started to code the portals now, but the Camera just doesn't seem right. I have 2 portals, rotated 90 degrees to each other. Here's the code that calculates the View matrix to render the texture for the 1st portal from the view of the second portal with the given translation/rotation: [code] worldMatrix = Matrix.CreateTranslation(-terrainWidth / 2.0f, 0, terrainHeight / 2.0f) * Matrix.CreateRotationY(angle); Vector2 vecY1 = new Vector2(portal1.Normal.X, portal1.Normal.Z); Vector2 vecY2 = new Vector2(portal2.Normal.X, portal2.Normal.Z); float rotY = (float)Math.Acos((Vector2.Dot(vecY1, vecY2) / (vecY1.Length() * vecY2.Length()))); Matrix rotMat = Matrix.CreateRotationY(rotY); //Calculates the rotation of the camera vector, based on the rotation of the portals to each other. Vector3 origin = portal2.Origin - (portal1.Origin - camPos); origin = Vector3.Transform(origin,rotMat); viewMatrix = Matrix.CreateLookAt(Vector3.Transform(origin, worldMatrix), Vector3.Transform(portal2.Origin + origin, worldMatrix), new Vector3(0, 1, 0)); DrawScene(gameTime); //Render the scene to texture. [/code]And to illustrate what I'm aiming for: [IMG]http://img687.imageshack.us/img687/2974/portalkd.png[/IMG] It also kinda works, but right now I'm not using any stencil buffer or sthg like that, all I do is render the texture and draw it to a quad. Also, right now I'm only rotating the translation vector over the y-axis, since the 2 portals are only rotated to each other on the y-axis.
[QUOTE=s0ul0r;20337234]Ok so I started to code the portals now, but the Camera just doesn't seem right. I have 2 portals, rotated 90 degrees to each other. Here's the code that calculates the View matrix to render the texture for the 1st portal from the view of the second portal with the given translation/rotation: [code] worldMatrix = Matrix.CreateTranslation(-terrainWidth / 2.0f, 0, terrainHeight / 2.0f) * Matrix.CreateRotationY(angle); Vector2 vecY1 = new Vector2(portal1.Normal.X, portal1.Normal.Z); Vector2 vecY2 = new Vector2(portal2.Normal.X, portal2.Normal.Z); float rotY = (float)Math.Acos((Vector2.Dot(vecY1, vecY2) / (vecY1.Length() * vecY2.Length()))); Matrix rotMat = Matrix.CreateRotationY(rotY); //Calculates the rotation of the camera vector, based on the rotation of the portals to each other. Vector3 origin = portal2.Origin - (portal1.Origin - camPos); origin = Vector3.Transform(origin,rotMat); viewMatrix = Matrix.CreateLookAt(Vector3.Transform(origin, worldMatrix), Vector3.Transform(portal2.Origin + origin, worldMatrix), new Vector3(0, 1, 0)); DrawScene(gameTime); //Render the scene to texture. [/code]And to illustrate what I'm aiming for: [IMG]http://img687.imageshack.us/img687/2974/portalkd.png[/IMG] It also kinda works, but right now I'm not using any stencil buffer or sthg like that, all I do is render the texture and draw it to a quad. Also, right now I'm only rotating the translation vector over the y-axis, since the 2 portals are only rotated to each other on the y-axis.[/QUOTE] Or you can: Render the scene with the area of the portal marked not to render in the stencil buffer. Transform the geometry so that the it's aligned correctly with the portal. (You'd do this by rotating until the location of the 2nd portal was the same as the first.) Occlude anything that's between the portal and the players view or mark the areas that are not the portal to not render in the stencil buffer. Render the scene again. That's honestly probably simpler than fucking with rendering to a texture.
That was my first approach, I think I'll look into the stencil buffer since nullsquared also said so :D
[QUOTE=i300;20336681]I generically don't have a lot in main.cpp But I program for iPhone, where if you use main.cpp, your going crazy. e.g. main.cpp in my "Gold Digger" game (Windows): [code] #include <allegro.h> #include <cstdlib> #include <cmath> #include <ctime> #include <time.h> #include <iostream> #include <fstream> #include <dir.h> #include <string> #define debug false // --------------------------------------------- \\ /* CUSTOM *.H FILES */ /* * === player.h === * Contains the player model */ #include "player.h" /* * === rock.h === * Contains the rock model */ #include "rock.h" /* * === rect.h and misc.h === * Contains the rectangle model * Contains misc functions */ #include "rect.h" #include "misc.h" // --------------------------------------------- \\ using namespace std; // used for FPS regulation volatile long counter = 0; void intCtr() { counter++; } int main(int argc, char *argv[]) { // Thanks to anihex for finding the game's directory. if (!debug) { string AppPath = argv[0]; int FoundAt = AppPath.find_last_of("/\\"); AppPath = AppPath.substr(0, FoundAt+1); chdir(AppPath.c_str()); } allegro_init(); install_keyboard(); install_timer(); install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, 0); set_color_depth(16); int sW, sH; sW = 640; sH = 480; srand( (unsigned)time(NULL) ); bool fullscreen = false; set_gfx_mode( GFX_AUTODETECT_WINDOWED, sW, sH, 0, 0); // classes Player player; player.init(); Rock rock; rock.init(); // variables bool exit = false; // [[[ bool rrd = false; // Man, I love how I aligned these. int dir = 0; // They look all neat and stuff!!! int errors = 0; // :) int scrn = 1; // ]]] BITMAP *buffer = create_bitmap(sW, sH); BITMAP *menu = load_bitmap("data//bitmaps//menu.bmp", NULL); BITMAP *spritesheet = load_bitmap("data//bitmaps//sprites.bmp", NULL); BITMAP *items = load_bitmap("data//bitmaps//items.bmp", NULL); BITMAP *bg = load_bitmap("data//bitmaps//background.bmp", NULL); BITMAP *about = load_bitmap("data//bitmaps//about.bmp", NULL); SAMPLE *bgm = load_sample("data//sounds//Spazed.wav"); SAMPLE *getg = load_sample("data//sounds//sound1.wav"); time_t creation = time(NULL); string error = ""; if (buffer != NULL) { error += "\nBuffer created!"; } else { error += "\nBuffer created incorrectly!"; errors++; } if (menu != NULL) { error += "\nMenu created!"; } else { error += "\nMenu created incorrectly!"; errors++; } if (spritesheet != NULL) { error += "\nSpritesheet created!"; } else { error += "\nSpritesheet created incorrectly!"; errors++; } if (items != NULL) { error += "\nItems created!"; } else { error += "\nItems created incorrectly!"; errors++; } if (bg != NULL) { error += "\nBackground created!"; } else { error += "\nBackground created incorrectly!"; errors++; } if (about != NULL) { error += "\nAbout created!"; } else { error += "\nAbout created incorrectly!"; errors++; } if (bgm != NULL) { error += "\nBGM created!"; } else { error += "\nBGM created incorrectly!"; errors++; } if (getg != NULL) { error += "\nGet_Gold created!"; } else { error += "\nGet_Gold created incorrectly!"; errors++; } LOCK_VARIABLE(counter); LOCK_FUNCTION(intCtr); install_int_ex( intCtr, BPS_TO_TIMER(90) ); // Note: // - My code is iffy while (!exit) { Rect pc = player.returnCoords(); while (counter > 0) { //input if (scrn == 1) { if (key[KEY_ENTER]) { play_sample( bgm, 255, 128, 1000, true ); scrn = 3; } else if (key[KEY_A]) { scrn = 2; } } else if (scrn == 2) { if (key[KEY_X]) { scrn = 1; } } else if (scrn == 3) { if (key[KEY_LEFT]) { if (pc.x+player.returnSpeed() > 0+player.returnSpeed()) { player.move( LEFT ); } } else if (key[KEY_RIGHT]) { if (pc.x+player.returnSpeed() < 615+player.returnSpeed()) { player.move( RIGHT ); } } else if (key[KEY_UP]) { if (pc.y-player.returnSpeed() > (-1)) { player.move( UP ); } } else if (key[KEY_DOWN]) { if (pc.y+player.returnSpeed() < 435+player.returnSpeed()) { player.move( DOWN ); } } if (isCollision(player.returnCoords(), rock.returnCoords())) { error += "\nCollision detected at [x="+tostr(player.returnCoords().x)+" y="+tostr(player.returnCoords().y)+"]"; player.givePoint(rock.returnPoints()); if (player.returnPoints() % 10 == 0 && player.returnPoints() > 1) { // On the rare change of you having a whole numb er divisible by 10, you get 3 extra speed ;) player.setSpeed((player.returnSpeed()+1)); error += "\nPlayer has a score that is a multiple of ten! ["+tostr(player.returnPoints())+"]"; error += "\nPlayer's speed is now "+tostr(player.returnSpeed())+""; } if (rock.returnPoints() == 5) { player.setSpeed((player.returnSpeed()+1)); error += "\nPlayer's speed is now "+tostr(player.returnSpeed())+""; } play_sample( getg, 255, 128, 1000, false ); rrd = true; } } counter = -1; } // menu screen if (scrn == 1) { blit( menu, buffer, 0, 0, 0, 0, 640, 480 ); } else if (scrn == 2) { // about screen blit( about, buffer, 0, 0, 0, 0, 640, 480 ); } else if (scrn == 3) { // game screen // draw bitmaps /* layer 0 - bg */ blit ( bg, buffer, 0, 0, 0, 0, 640, 480 ); /* layer 1 - items */ rock.draw( buffer ); if (rrd == true) { rock.init(); rrd = false; } /* layer 2 - player */ player.draw( buffer ); // draw text textprintf_ex(buffer, font, 0, 0, makecol( 255, 255, 255 ), makecol( 0, 0, 0 ), "Score: %i Points! You are moving at %i MPH!", player.returnPoints(),player.returnSpeed()); if (debug) { // debug mode here textprintf_ex(buffer, font, 0,16, makecol( 255, 255, 255 ), makecol( 0, 0, 0 ), "DEBUG MODE IS ON"); bool iscollision = isCollision(player.returnCoords(), rock.returnCoords()); textprintf_ex(buffer, font, 0,24, makecol( 255, 255, 255 ), makecol( 0, 0, 0 ), "Player Collision: %s", ((iscollision)?"true":"false")); textprintf_ex(buffer, font, 0,32, makecol( 255, 255, 255 ), makecol( 0, 0, 0 ), "Player x: %i | y: %i | w: %i | h: %i",pc.x,pc.y,pc.w,pc.h); } } // blit buffer blit(buffer, screen, 0,0,0,0, sW, sH); // clear the buffer clear_bitmap( buffer ); if (key[KEY_ESC]) { error += "\nESC Pressed... Exiting..."; exit = true; } } // destroy the bitmaps created destroy_sample( bgm ); destroy_sample( getg ); error += "\n\nSAMPLE bgm destroyed...\nSAMPLE getg destroyed..."; player.dealloc(); rock.dealloc(); error += "\n\nPlayer deallocated...\nRock deallocated..."; destroy_bitmap( spritesheet ); destroy_bitmap( menu ); destroy_bitmap( items ); destroy_bitmap( bg ); destroy_bitmap( buffer ); destroy_bitmap( about ); error += "\n\nBITMAP spritesheet, menu, tems, bg, buffer, and about destroyed..."; // Write to the logfile error += "\n\nGame exited with "+tostr(errors)+" error(s)"; logfile(creation, error); return 0; } END_OF_MAIN(); [/code][/QUOTE] :psyboom:
[QUOTE=jA_cOp;20337206]That's no less of an abomination when it comes to the procedural paradigm either.[/QUOTE] It's an affront to all programming. No need to restrict it any further than that.
So I'm making a game. I'm not aiming at the tiny 2d games I usually like to make or the crappy 3d games I try to make. I'm going for a legit game here and I'm going to try to do it with OO. I've run into a problem since I've never used OO in a game before. And that's structure. At the moment I'm thinking of using a class for each major part of the game. And then a 'parent' class that handles all of them. Is this a good way to do it or is there a better way?
[QUOTE=Jawalt;20337849]So I'm making a game. I'm not aiming at the tiny 2d games I usually like to make or the crappy 3d games I try to make. I'm going for a legit game here and I'm going to try to do it with OO. I've run into a problem since I've never used OO in a game before. And that's structure. At the moment I'm thinking of using a class for each major part of the game. And then a 'parent' class that handles all of them. Is this a good way to do it or is there a better way?[/QUOTE] What programming language are you going to use? What you're talking about doesn't really have anything to do with object-orientation. What you're describing is basically modularization of any non-trivial program. I'm sure there are a lot of good free resources out there explaining OOP, although it might not be in your programming language of choice.
[QUOTE=jA_cOp;20337953]What programming language are you going to use? What you're talking about doesn't really have anything to do with object-orientation. What you're describing is basically modularization of any non-trivial program. I'm sure there are a lot of good free resources out there explaining OOP, although it might not be in your language of choice.[/QUOTE] I'm using C++ so I'm pretty sure there are but almost all of the tutorials I've found have been on the code side of things while I've got the code side of things down pat pretty well, I want to learn more about OOP like theory I guess you could say. I know a couple non-OOP languages and I liked them and I don't really like OOP but I'm also not extremely familiar with it so I'm trying to give it a chance. I don't know.
I don't quite get stencil masking oO I mean, I have to draw first my scenery, then write the stencil mask of the quad and ONTO that the scenery again? could someone explain in pseudocode how to do that? (XNA)
[QUOTE=Jawalt;20338005]I'm using C++ so I'm pretty sure there are but almost all of the tutorials I've found have been on the code side of things while I've got the code side of things down pat pretty well, I want to learn more about OOP like theory I guess you could say. I know a couple non-OOP languages and I liked them and I don't really like OOP but I'm also not extremely familiar with it so I'm trying to give it a chance. I don't know.[/QUOTE] OOP isn't so much "organization" as it is encapsulation. I'm sure you used data structures for organization in languages without OOP specific features, too. The difference is that when following the object-oriented paradigm, you treat these data structures differently, they aren't just logical collections of data anymore; but fully self-aware and self-contained entities, whose interactions with other entities are clearly defined. It is the clear separation of interface and implementation. The idea is to create a program where modules are as loosely coupled as possible, and as difficult to misuse as possible, in turn making your program easier to maintain and debug as it grows. Online C++ tutorials rarely tell you [I]why[/I] all these features are in place, so it might be a good idea to reflect a bit on what they teach you; how this feature can make your program easier to fit in your head, reducing bugs and increasing productivity. Some features aren't as useful and arguably do more harm than good, like C++'s "protected" keyword... You can, and probably are doing, the same thing in languages without much direct support for it, too. For example, blankthemuffin and I are working on a game engine in C where we are using OOP heavily, including proper encapsulation. The object-oriented paradigm is much wider than just "classes".
Ok so now I have that fucking stencil buffer done but.... OF COURSE, it doesn't work as it did with rendertargets... Here's what I have now... [media][URL]http://youtube.com/watch?v=l64UFSTg15o[/URL][/media] And yeah, that's the code basically: [cpp] viewMatrix = Matrix.CreateLookAt(camPos, camLookAt, new Vector3(0, 1, 0)); device.Clear(Color.Black); // ------ Draw the scene as background ----- DrawScene(gameTime); // ------ Draw the scene as background ----- device.RenderState.StencilEnable = true; device.RenderState.StencilFunction = CompareFunction.Always; device.RenderState.StencilPass = StencilOperation.Replace; device.RenderState.ColorWriteChannels = ColorWriteChannels.None; device.RenderState.ReferenceStencil = 1; quadEffect.World = worldMatrix; quadEffect.View = viewMatrix; quadEffect.Projection = projectionMatrix; quadEffect.TextureEnabled = false; quadEffect.Texture = heightMap ; GraphicsDevice.VertexDeclaration = new VertexDeclaration(graphics.GraphicsDevice, VertexPositionNormalTexture.VertexElements); // ----- Draw the mask into the stencil buffer ----- device.Clear( ClearOptions.Stencil,Color.Black,1f,0); quadEffect.Begin(); foreach (EffectPass pass in quadEffect.CurrentTechnique.Passes) { pass.Begin(); GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionNormalTexture>( PrimitiveType.TriangleList, portal1.Vertices, 0, 4, portal1.Indexes, 0, 2); pass.End(); } quadEffect.End(); // ----- Draw the mask into the stencil buffer ----- Matrix rotMat = Matrix.CreateRotationY(rotY) * Matrix.CreateRotationX(rotX) * Matrix.CreateRotationZ(rotZ); Vector3 origin = portal1.Origin - camPos; origin = Vector3.Transform(origin, rotMat); viewMatrix = Matrix.CreateLookAt(Vector3.Transform(portal2.Origin - origin, worldMatrix), Vector3.Transform(portal2.Origin + origin, worldMatrix), new Vector3(0, 1, 0)); device.RenderState.StencilEnable = true; device.RenderState.StencilFunction = CompareFunction.Equal; device.RenderState.ReferenceStencil = 1; device.RenderState.ColorWriteChannels = ColorWriteChannels.All; // ----- Draw the scene onto the portal ----- DrawScene(gameTime); // ----- Draw the scene onto the portal ----- device.RenderState.StencilEnable = false; [/cpp] At least I have good camera control. [editline]11:01AM[/editline] I just can't find any fucking way to get that clipping away -.- the farplane is already set to 300000....
Nice, but does anyone have any idea about light's in DirectX? All i get is that the scene goes black.
You need to either turn lighting off (fullbright) or use DX's built in light system, or make a light system yourself using shaders.
I tried the DX's built in but failed epicly. Any ideas how to write a shader?
I just got a new graphics card so I haven't been really productive lately. :v: Anyways, I'm currently learning the awesome that is reflection in C#, and using it to make a console-like system.
[QUOTE=Tobba;20340420]I tried the DX's built in but failed epicly. Any ideas how to write a shader?[/QUOTE] Would this work? : [URL]http://www.toymaker.info/Games/html/shaders.html[/URL] Edit: They have lighting - [url]http://www.toymaker.info/Games/html/vertex_shaders.html#examp3[/url]
I just did my first success with the built in light. I make a vertex shader for lights and shadows later [editline]03:11PM[/editline] even tho it looks like shit :argh:
[QUOTE=s0ul0r;20338523]I don't quite get stencil masking oO I mean, I have to draw first my scenery, then write the stencil mask of the quad and ONTO that the scenery again? could someone explain in pseudocode how to do that? (XNA)[/QUOTE] I'm a bit strapped on time atm so I can't help, but I hope you know pseudoform is open source...
Got the lights to look a bit better. Have a pic: [img]http://dl.dropbox.com/u/4838268/light.bmp[/img]
[QUOTE=nullsquared;20342381]I'm a bit strapped on time atm so I can't help, but I hope you know pseudoform is open source...[/QUOTE] Already looked into that, but since I'm no c++ coder and don't know anything about the structure there, I just looked into the portal.cpp file, looked through some of the ogre functions and, yeah maybe I'll dig into that later on again.
Does anyone know how the point and spot lights work in DirectX? i've only gotten directional to work
[media]http://www.youtube.com/watch?v=uNBl1tdBiRo[/media] I have been very lazy. Basically doing no work at all. Anyway, enjoy bullet-patterns. Gonna re-do collisions soon.
Sorry, you need to Log In to post a reply to this thread.