Jump to content
  • Advertisement

Android_s

Member
  • Content Count

    426
  • Joined

  • Last visited

Community Reputation

164 Neutral

About Android_s

  • Rank
    Member
  1. Thanks "Annonymous Poster", that's almost exactly what i need. =)
  2. Hey! First of all; Merry Christmas! =) Now...i'm preparing to make an easy xml-like map format for my engine and i want to easily be able to read the file and i want everything to be expandable. I was thinking the map file could look something like this... object <object-type> <object-name> { <object-data> .... } My problem is that i don't know how let the scripting class will "know" of the object-type classes i have. Makes any sense? =/ Ok, say i have a class CCamera and i want to create that from the script like: object CCamera "a_camera" { position 0.0 0.0 0.0 } ...how can i parse CCamera and create an instance of it in a nice way? I don't want for example a large if/else/switch/case chunk. I was wondering if there's a nice way to do this?
  3. Quote:Original post by templewulf So, create a single pointer, allocate an array of integers based on the count variable you mentioned, and change the pointer to refer to each int in that array, whenever you need to access it. Hmm, i wouldn't recommend you start dabbling with pointers if you've "just started learning C++". But templewulf is correct that you can think about variables as regions of memory. I would recommend you go with an array and fill it with values, it would be an easy way to solve the problem you have in an easy way, and not necessary an ugly way either. =)
  4. Android_s

    Did i do it right?(Can i do it better?)

    I gave your code a quick overhaul and this is what i came up with without too much difference. =) I've commented a few things that i thought could be changed. // first of all, you don't need cstdlib nor windows.h, just // include the needed headers #include <iostream> #include <ctime> using namespace std; // you had a few variables here as globals. No need to have them // here, just create them inside main. int main() { // you made a lot of rand() variables here, but rand() never // change unless you call srand first, which you never did, so // for me the calculations of these variables always boiled // down to 2, which then is just silly. =) srand((unsigned int)time(0)); cout << "Try to guess a number: " << endl; // this is really everything you need to pick a number between 1-100, // not forgetting about the srand BEFORE any rand() calls. =) int secretNumber = (rand() % 100) + 1; // in C++ you usually don't create local variables until // you need them. =) int x = 0; bool done = false; while(!done) { // this variable always increase, you can aswell put it here, // in this case it dosn't make a difference =) ++x; // you asked why your program didn't register the first // input. Well, it did, but look at your code and see what // happens if you don't "get it on the first try". =) int guess; cin >> guess; cin.ignore(); if(guess < secretNumber) cout << "Too low" << endl; else if(guess > secretNumber) cout << "Too high" << endl; else { // you hade a \n in the below line, IMHO, don't mix that with // endls ;P cout << "Good job! you've got it right in.." << x << " trys" << endl; done = true; } } cin.get(); return 0; } There are probably 100 ways you can improve this, but this will give you something to think about i hope... =)
  5. Android_s

    translucency/transparency

    Quote: ok, so a good analogy would be that translucent is stained glass for example? Transparent... =) Well, to be strict, you should first render all your opaque polygons front to back, then you render your transparent back to front... This involves sorting your polygons after their depth, and if you want to be really strict, split polygons that intersect other polygons... However this is not often done in realtime systems (not that i know at least) because it *can* be a rather expensive operation. If you've ever played "GTA:Vice City" you can see some wird effects when seeing trees through other trees or plants...this is happening because they didn't sort the transparent surfaces... In your case you should at least sort the transparent surfaces and then render them correctly, even the cube's surfaces. =) There are a few ways to do this, but it often involves checking the polygon's vertices depth and then approximate where it's depth would be. Then you use a fast sorting algorithm (qsort for example?) and then render them.
  6. Android_s

    translucency/transparency

    What do you mean by grid? Is is a "grid" texture and you have your alpha channel set up to match the grid? You might need to set the glBlendFunc() parameters, if i remember correctly it's glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); (hmm?) =/ You might have the transparency sorting problem aswell. Make sure you draw all your transparent surfaces back to front, or you may get wierd resuslts when seeing a transparent surface through another transparent surface. Wait, you said you turned off transparency? Hmm, i have no idea why that happens...are you really sure everything is set up the way you think it is? =)
  7. Android_s

    Programming is hard :(

    Quote: The school system we have here is very good and i believe the computers science is prity mutch the same as you Americans have, but what we lack are game developent schools and programs. I can't say for sure, but i think that if you read computer science at a university you will come far on that. If you really want to attend a game developement school...i don't know how it looks in finland, but i do know that many schools have popped up here in Sweden, if that's something for you. =) Quote: The only way i hear in Finland you can get into the industry is through the demo scene. I think most game companies look at what you can do and a bit about how you are as a person, but most of all how you write your code. If you can't write functional and readable code you might have trouble adjusting to working with 30+ other programmers. =) I don't think that the demo scene is the only way in...but then again, i really don't know for sure about Finland.
  8. Android_s

    Programming is hard :(

    IMHO... Don't change language! If you keep spending time infront of C++ you will learn eventually. When you learn to program you learn 2 things (as someone said earlier) , you learn the syntax of the language you learn to "program". =) C++ dosn't necessarily have to be more evil than other languages. And those things about memory management...i'd say that if you learn them from start they will come as second nature in a few years, you simply pick up that shit you left! I noticed this when i tried JavaME a year ago, and at first i was really not comfortable with that garbage collecting but i got used to it. When i then switched back to C++ i forgot a lot of cleaning, not good! I started with C++, and many things above the level of loops, if-statements and functions were completely impossible to learn. It took me 3 months to wrap my head around pointers! >_< And that about programming is only for a few gifted ppl, it's bullshit imo. Unless you count motivation, dedication and curiosity as gifts... ;P Just hang in there...everyone runs their head into the wall at times, even pros! ;)
  9. Android_s

    How to move the camera in OpenGL?

    Hmm, i may be rusty on basic OpenGL, but are you really supposed to draw your objects in the projection matrix!? It really sounds like this is your big problem with objects not resizing. Try setting up your viewing parameters first, then go to modelview matrix and do all transforms/renderings, and see how that works... Quote: By the way, is this a way to move a camera? or I just moved the objects around (not camera) When you make for example an FPS camera, you do just as what you said above, you move all objects around. I would really recommend you looking into the matrix math of making a simple camera. You can get a pretty good understanding on how it works in this way. A short explanation (and probably what gluLookAt does internally) of what happens is that you take your "cameras" matrix, then you make a few sweet operations on it and thus you move your entire scene so it's seen through the "cameras" eyes and render it. There are 1000 ways of doing cameras, some pretty simple, some quite advanced involving quaternions and stuff, and you can even use that gluLookAt as suggested, but be aware that you must do some math regardless of what you choose...
  10. Android_s

    Cg lighting problem

    Well, BUMP!, sorry... Isn't there anyone that can discover something wrong with my code? Come on, you don't have to be shy... ;P ...perhaps i posted in the wrong section? =/
  11. Android_s

    Cg lighting problem

    Hey! Was trying to make something cool with Cg shaders, but i realized how much i suck at Cg scripting, so i need some help. =) I'm tyring to make a simple lambert & phong shader, but it dosn't look correct. The diffuse lighting seems really...hmm, ambient in a way, and the specular...it really seems like an environmap. =P Ok, so this is the c++ code where i enable the shader. Not sure if i'm supposed to supply the inverse TRANSPOSE of the modelview matrix, but my resources from nVidia suggest i should... cgGLEnableProfile(vProfile); cgGLEnableProfile(fProfile); cgGLBindProgram(vProgram); cgGLBindProgram(fProgram); cgGLSetParameter3fv(cgpLightPos, lightPos); glPushMatrix(); gluLookAt(2,2,3, 0,0,0, 0,1,0); glPushMatrix(); float mat[16]; glGetFloatv(GL_MODELVIEW_MATRIX, mat); RotateMatrix_Y(mat, mat, scene_yRot); RotateMatrix_X(mat, mat, scene_xRot); glLoadMatrixf(mat); cgGLSetStateMatrixParameter(cgpModelViewProjMatrix, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); cgGLSetStateMatrixParameter(cgpModelViewInvertMatrix, CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE_TRANSPOSE); glBegin(GL_QUADS); glNormal3f(0,0,1); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 1); glColor3f(1,0,0); glVertex3f(-1.0f,-1.0f, 0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0, 0); glColor3f(0,0,1); glVertex3f( 1.0f,-1.0f, 0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 0); glColor3f(0,1,1); glVertex3f( 1.0f, 1.0f, 0); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1, 1); glColor3f(1,1,0); glVertex3f(-1.0f, 1.0f, 0); glEnd(); glPopMatrix(); cgGLDisableProfile(vProfile); cgGLDisableProfile(fProfile); glPopMatrix(); I can't spot anything wrong there except perhaps that inverse transopse thing. So for the vertex shader script struct VertIn { float4 position : POSITION; float4 color : COLOR; float2 texCoord : TEXCOORD0; float4 normal : NORMAL; }; struct VertOut { float4 position : POSITION; float4 color : COLOR; float2 texCoord : TEXCOORD0; float3 vertEye : TEXCOORD1; float3 normalEye : TEXCOORD2; float3 lightVecEye : TEXCOORD3; }; VertOut vertmain( VertIn IN, uniform float4x4 modelViewProj, uniform float4x4 modelViewInv, uniform float3 lightPos) { VertOut OUT; OUT.position = mul(modelViewProj, IN.position); OUT.texCoord = IN.texCoord; OUT.color = IN.color; // to view space OUT.vertEye = mul(modelViewInv, IN.position); OUT.lightVecEye = normalize(lightPos - OUT.vertEye); OUT.normalEye = mul(modelViewInv, IN.normal).xyz; OUT.vertEye = normalize(-OUT.vertEye); return OUT; } I actually don't know at all if this really works. I keep asking myself the question why i have to transform vert and normal to viewspace anyway, and not the lightVec. I also found out that i get fancy inverted specular reflection if i don't invert the vertEye param...omg why!? ;P Last, the fragment shader struct FragIn { float4 color : COLOR; float2 texCoord : TEXCOORD0; float3 vertEye : TEXCOORD1; float3 normalEye : TEXCOORD2; float3 lightVecEye : TEXCOORD3; }; float3 reflect(float3 N, float3 L) { return 2.0 * N * dot(N, L) - L; } float4 fragmain(FragIn IN, uniform sampler2D frameTex : TEXUNIT0, uniform sampler2D depthTex : TEXUNIT1) : COLOR { float4 color; float3 V = normalize(IN.vertEye); float3 N = normalize(IN.normalEye); float3 L = normalize(IN.lightVecEye); float diffuse = clamp(dot(L, N), 0, 1); float3 R = reflect(N, L); float specular = clamp(pow(dot(R, V), 1.0), 0, 1); float4 alpha = IN.color; alpha[0] = 0; alpha[0] = 0; alpha[0] = 0; color = (diffuse * IN.color) + (specular * IN.color) + alpha; return color; } This one is a mess if you ask me...although it dosn't look that wrong to me... I'm really lost...what i want to know is why to-viewspace and if anyone of you guys can see any real screw up. =) cheers!
  12. Android_s

    winsock recive problem

    Dosn't recv() take a timeout parameter? I can't really look it up myself right now, but check MSDN, if i remember correctly it should be there =)
  13. Android_s

    help with segmentation fault on MD2 file

    Ah, hehe! The most hard-to-crack bugs are often the most easiest/silliest to solve. You really should check if everything loads correctly. The MD2 function you have written returns bool, caatch it! =)
  14. Android_s

    help with segmentation fault on MD2 file

    Quote: As i said the skybox and texture loads fine which is Targa Yes, but as you also said the MD2 texture is RLE. Are you 100% sure the other images also are RLE? Did you try to load the skybox texture as the MD2 texture? This is simple elimination. Have you also stepped through your code during runtime, into every single little function (especially CTargaImage::Load()) and made sure< your data is correct? Don't always trust that things will work in one place just because it did in another, until you have confirmed all data. =) You said the gluBuild2DMipmaps() gave you the seg. fault, the you can hopefully rule out there's anything wrong woth your MD2 loading code (for now). You could also see if you get any error returned from gluBuild2DMipmaps() (perhaps not very likely, but can't hurt to check all GL functions you have there). int ret = gluBuild2DMimpaps(); if(ret) char *str = gluErrorString(ret);
  15. Android_s

    help with segmentation fault on MD2 file

    Did you try to remove the Run Length Encoding from your image files? The only thing i can think of is that it really IS your CTargaImage::Load() func that dosn't work correctly. You could try to load an image that you already know will load and display correctly, and use that for texture for now. If that should work then we know for sure. If not, perhaps it's something else that you havn't wrote...i mean with your compiler or something like that...
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!