Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Everything posted by SelethD

  1. Ok... I am quite the novice when it comes to game related math, especially in the 3D realm.  So I shall try to convey my problem as clearly as possible, since I do not know much of the terminology.   I have a Camera in 3D space, this camera can be located at any x,y,z and it can face any direction valid for a FPS view. I have a target, the target can be at any location in 3D space along the x,y,z however the target will be STATIC and non movable.   I would like to be able to have my camera position itself in front of the target so that the target will appear a certain size and location on the 2D render screen.   I found online a function, when when supplied with variables of x,y (location of target to be displayed on 2D screen) and height (the height the target should display on the 2D screen) the function will return a Vector3 stating where the target should be placed in 3D space, so that it will render at the x,y at desired height on the 2D render screen.   The problem I am having is converting that Vector3 into something that I can use to position my Camera (since my target is stable) in the correct position to get the same result.   This is what I am doing so far... the code is in Lua   -- This line is calling the function I found online, I am requesting a Vector3 position so the target will be shown on the 2D render at position screenW/2, screenH/2 (so that should be in center of screen) and I want the object to appear to be .5 the size of my screen's height so thats the second screenH/2.  The last argument is the unit size of the object (2 units high)   local pos = ScreenSpace.ScreenToWorldByHeight(screenW/2,screenH/2,screenH/2, 2)   Now the result is ... pos = (0,0,-2)   -- Meaning i need to have the target positioned -2 away from my camera on the Z axis to display as needed.   This is the same result no matter which way my camera is facing, so I know the result is based off of my camera's .. facing vector?   So I tried this to get my new camera position...   newCamPos = TargetPosition - pos   This however, causes my camera to be positioned at the targets location offset by +2 on the Z axis, when in reality, I need it to be +2 on the Z axis in relation to how the Target is facing, the targets facing vector.   So I am lost... is there an easier way to do this?  What terms should I search for?  Or if you have any tips or tricks to share that would be great.   Thanks      
  2. Not sure if it will be needed by anyone, but after experimenting I did find a solution.   --first i set up some vectors local g_up = Vector3.new(0,1,0)  --global up local v_forward = target.lookVector local v_right = -g_up:Cross(v_forward) local v_up = -v_forward:Cross(v_right) local p = target.position   --get a new position, based off of moving down the vectors (also the 'loc' variable is what was returned by the function in the above post) p = (v_forward*(-loc.Z))+p p = (v_right*loc.X)+p p = (v_up*loc.Y)+p   local cam = Camera cam.position = p cam.lookAt = p+(target.lookVector * -2))    I dont know if its the best way to do this, but it works, so... unless it gives me issues, ill use this   Thanks
  3. I am sure this is something that has been answered a million times over, but for the life of me, I cant seem to figure it out, nor can I find any helpful info.   I have a mesh (quad) and meshrenderer created in c#.  I would like to give the meshrenderer a material that already exists in my resources folder....   Assets/Resources/JmaMaterial   I load the material with...  Material mat = Resources.Load<Material>("JmaMaterial");   If I assign it to my meshrenderer like this....       Material BodyMat = new Material(mat); mMeshRenderer.material = BodyMat;   This works, no problem... however, if I want to add 2 materials to my quad (one for character body, another for chatacter hair)   It doesnt seem to work, this is how im doing it...           mMeshRenderer.materials = new Material[2];         Material mat = Resources.Load<Material>("JmaMaterial");         if (mat != null)         {             mBodyMat = new Material(mat);             mHairMat = new Material(mat);             mMeshRenderer.material[0] = mBodyMat;             mMeshRenderer.materials[1] = mHairMat;         }         else Debug.Log("failed to find material");     So... obviously im doing something wrong, I try to Google about assigning multiple materials to a mesh, but all the results either have no solution, or they explain how to do it in the editor, not in code.   Is this even the correct way to do an image with multiple parts?  (body + hair) Instead of having one quad with 2 materials, should I instead go with 2 mesh quads and each have 1 material?   Thanks for any help 
  4. Its too bad there is no apparent 'native support' for 8bit images in opengl anymore.  However, I did not know it was getting a copy of the entire palette on each call, I tried to suggestion of making one copy to an array, and using the array, and the results were 100% faster.   I cant even tell how long its taking to load, as it zips through the files.   Thanks so much.
  5. I am working on a project, that uses some legacy graphics, that are in an 8bit indexed bitmaps.  These are the ones with a 1 byte pixel, pointing to an array of 256 colors.   So far, this is how I have been doing things.... (note, I'm using C#, with OpenTK, although a solution in C++ can be easily converted) Bitmap bitmap = new Bitmap(path); System.Drawing.Imaging.BitmapData textureData = bitmap.LockBits( new Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); int srcmax = textureData.Height * textureData.Stride; byte[] origBytes = new Byte[srcmax]; Marshal.Copy(textureData.Scan0, origBytes, 0, srcmax); bitmap.UnlockBits(textureData); this gives me the bitmap pixel data (the 1 byte index numbers) in textureData. So now, I very slowly and very painfully, go through the data, as such.... //loop through all the pixels byte[] data = new byte[(bitmap.Width * bitmap.Height) * 4]; int srcloc = 0; int dstloc = 0; byte index; Color color; for (int y = 0; y < textureData.Height; y++) { srcloc = y * textureData.Stride; for (int x = 0; x < textureData.Width; x++) { index = origBytes[srcloc]; if (index == 0) { data[dstloc] = 0; data[dstloc + 1] = 0; data[dstloc + 2] = 0; data[dstloc + 3] = 0; } else { color = bitmap.Palette.Entries[index]; data[dstloc] = color.R; data[dstloc + 1] = color.G; data[dstloc + 2] = color.B; data[dstloc + 3] = color.A; } dstloc += 4; srcloc++; } } as you can see, I am looking at the color, pointed to, by each pixel index... and manually reversing the red, and blue values, and also, setting alpha to 0, when the index number is 0.  This converted data is then used to create an opengl texture, as follows... GL.Enable(EnableCap.Texture2D); uint textureID = 0; GL.GenTextures(1, out textureID); GL.BindTexture(TextureTarget.Texture2D, ret.ID); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (float)TextureWrapMode.Clamp); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (float)TextureWrapMode.Clamp); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)TextureMinFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)TextureMagFilter.Nearest); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, pixelData); GL.Disable(EnableCap.Texture2D); Now... this totally works, I end up with a rgba opengl texture2d, with transparency that can be used to texture a quad  and it looks perfect.... only problem is the super slow speed of going through each pixel, as some of these images are > 800x800   So... If anyone knows of a better solution, something faster, or if you know of anything I seem to be doing wrong (opengl wise, as I am an opengl noob) please let me know.   Thanks
  6. It is definately the 'looping' through the indexes that is causing the slow operation.   I have been searching and searching online for a solution, and came across something interesting...   I've seen  GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bitmap.Width, bitmap.Height, 0, PixelFormat.ColorIndex, PixelType.UnsignedByte, data); now, the PixelFormat is ColorIndex.... this is what I need... however, when I use this, I get pure black images, no transparency... So, I think I must be missing the 'color palette' somewhere... I'm trying to discover, how to let opengl know the data of the colorpalette tha the ColorIndex will look at.   I also read this... "Similarly, to offset the color indices of a bitmap to the palette entries you have defined for it, use glPixelTransferi(GL_INDEX_OFFSET, bitmap_entry);"   it says 'the palette entries you have defined', and im assuming this is 'bitmap_entry', but nothing shows 'HOW' to define the palette entries     So... I'm feeling more lost than ever, surely surely someone has used indexed graphics, and knows how to do this, but the lack of information on the web is troubling, i'm thinking, is it even possible anymore?     Thanks for any help
  7. Thanks so much for your input.   Well, the case with Palette.Entries[0], is that it's alpha value is non 0, and I really don't care what color the pixels are for index 0, as long as it is transparent.  I cant edit the original images, unless there is some magical opengl, trick to mass convert data or something, I'm afraid I'll have to check and set to alpha 0 each time I hit an index 0 byte.   I see what you mean, as far as writing 1x4 bytes, not sure if this would be a speed increase, but its something I will try, just to see if I get different results.   It is a time critical piece of code, and I do have it in a 'title/loading' screen, its just.... slow loading.   Now you mention, am I sure its 'super slow'... yeah, it kinda is... and actually that is a bit surprising, even for an 800x800 image... I would think it would be faster on a modern computer.  So, I'm wondering if the part that is taking up so much time, might be the part of the code where I am reading in the Bitmap, with LockBits, and copying its data.   I plan to keep trying and experimenting   If anyone has any other input or have used 8bit indexed bitmaps.... please share some secrets, thanks.
  8. Thanks for the replies, I wouldn't even begin to know how to batch my sprites, as each of the 100 sprites would contain different textures.  No duplicating textures.   I see what you mean now about not needing to call 'end' on the shader.     I think I understand about the 'setvariable' once, ,then just bind different textures.  I will give this a try XD    Thanks again.
  9. Sorry if I am unsure of the proper terms to use,  this is all fairly new to me.   I am working on a game, that uses 8bit indexed graphics (for palette shifting/swapping effects).   After about a month of searching tutorials, forums, etc... I am at the point, where I am doing this.....   Each 'character' has a reference to a sprite (object containing a Texture2D) which holds my character image (using the red value of rgb to be an index to the color palette per pixel)   And each 'character' has a local Texture2D for holding that 'character's unique color palette (since different players might color their character's skin, hair, eyes , etc... a different color)   So, each character has to pass its 'image' and 'palette' to the shader.... this is how I am doing it.   Every time I draw a 'character' I call this member function public void RenderAt(float posx, float posy, DuShader shader) { GL.ActiveTexture(TextureUnit.Texture0); mCurrentFrame.Bind(); shader.SetVariable("texture", (int)0); GL.ActiveTexture(TextureUnit.Texture1); mPalette.Bind(); shader.SetVariable("colorTable", (int)1); GL.ActiveTexture(TextureUnit.Texture0); shader.Begin(); mCurrentFrame.RenderNoBindAt(posx, posy); shader.End(); } My issue with this is that I am having to call shader.Begin, and shader.End per draw.  I am no expert at openGL, but it just screams at me as 'bad code'   My original thought , was to have the shader.Begin located at the beginning of the draw loop, then have all my Render calls happen, then at the end call shader.End   This however, did not work,  for some reason, I cannot execute the code....   GL.ActiveTexture(TextureUnit.Texture0); mCurrentFrame.Bind(); shader.SetVariable("texture", (int)0);   from between the shader.Begin and shader.End calls, it only works when the code is executed 'before' the shader.Begin   I have no idea why this is the case.   My understanding of shaders and howto use them is from examining about 30+ articles and tutorials over a period of about 4 weeks :P   So... finally my question... what is the 'best' meaning most correct or efficient way to have multiple draw calls to a shader, where the two textures (image and palette) are never the same, and not have to begin and end my shader for each one.   Here is my shader.begin and shader.end code... public void Begin() { GL.UseProgram(mProgram); } public void End() { GL.UseProgram(0); } And the actual GLSL fragment shader... uniform sampler2D texture; uniform sampler2D colorTable; void main() { vec2 pos = gl_TexCoord[0].xy; vec4 color = texture2D(texture, pos); vec2 palPos = vec2(color.r,0); vec4 newColor = texture2D(colorTable, palPos); newColor.a = color.a; gl_FragColor = newColor; } The output i get is correct, meaning it 'works' Ijust need to know if im using it correctly or a better way of doing this.   Thanks in advance, I know its a long winded question, and I tend to ramble :P  
  10. Just my 2 cents, but I would think, unless it really affects gameplay, I wouldnt worry about each screen being a little different than the other. Not sure exactly what type of game you are making, but I have seen many games where the screens do not match up, but was not necessary for accurate gameplay.
  11. SelethD

    Post-christmas GD games giveaway

    Whenever I see a topic that you have replied to, or initiated, it always gets my interest.  Great job.
  12. SelethD

    You Don't Need to Hide Your Source Code

    I have to agree with wicked357, I think the most logical reason to be careful with sharing your source would be to help prevent cheating... Granted, I have done my fair share of that, in my day, and I know from experience, that not having the source made hacks, and bots extreamly difficult to create.   Also, if your source is server code, it could have database information that could compromise the security of user accounts or other important things on your system.   But for small games, single players, or just a stripped down framework, there is no reason to worry about sharing. 
  13. SelethD

    Rush 2 - Looking for Feedback

    I tried it out, using IE (I know most people use other browsers, but you should always try to be a cross browser compatible as possible)   There are only a few little things that I noticed   1) When loading the resources, after pressing the 'Play' button, it sort of just 'hangs' , at first I thought my window locked up, but then the game started, so, maybe  a 'loading' screen or progress bar would help to show that it didnt just lock   2) The screen will scroll smooth most of the time with the player, but on occasion the screen will shake, almost like there is an earthquake happening.  Not sure if you are doing that on purpose?!?!  If you are... cool, but if not, might want to check out your screen movement (camera movement) code.   I really think you have a cool idea, and I see lots of potential here.  Good job XD
  14.   If this is not the correct forum, my apologies.  I thought, since I am a beginner to web or mobile games, this would be the best place to ask the quesiton.     I have been programming 'forever' in C++ and recently in C# with a sprinkle of Java thrown in for flavor.  However, all my games or apps are the standard .exe, run this in windows, variety.     Recently though, I have been trying to learn what language or languages I need to know to make games on a mobile device or that can be played from a web site.     I know the Apple market is fairly proprietary, and thus not owning a Mac, I dont think I have any possibility for developing anything for the IOS market.     The Android market, has so many different devices I'm confused of which one I should target (or if I even need to target anything specific) and definately what is the best Game Creation language to program it in.     I would love for my little games to not only be played on a mobile device, but also be playable from a web browser.  So I'm not sure if I could use the same language, or if the mobile device, and the web based, would need different languages for the program to be in.     My apologies if this is an 'over asked' question.  I promise you I have googled myself silly over the last few weeks trying to find answers.  I seriously just have lousy luck searching for answers.   BTW, I am only able to code from a windows platform.   Thanks in advance for any advice, or links you can provide to help me make the transition into the web / mobile device gaming arena.
  15. Wow, you guys have given a LOT of useful information.  I cant express how grateful I am.  This will give me enough options to research and experiment with to last me a while.    Thanks again.
  16. SelethD

    XNA - Making A Sprite Fire A Projectile

    I didnt look through all the code posted, so not sure if this will help.  However, this is how I would do it.   Since you have a sprite manager, you need to be able to 'create' sprites, manage them while they are alive, and eventually destroy them after a certain time, or condition.   For the projectile, you need to 'create' it at the location of your player, and let your sprites hold a heading and velocity.   so when player fires, create projectile sprite, set its heading to whatever heading your player has, set its velocity to something fast, then let the sprite manager, continue to update its movement, check collisions, and draw the projecting, until it gets off screen or hits something, etc... then let the sprite manager destory the object.
  17. I need to do some vector operations on a 2d Asteroids type game.   I found this page here.....   http://geom-java.sourceforge.net/api/math/geom2d/Vector2D.html   Unfortunately, I have no idea what to 'import' to get this to work.   I saw in an online example someone used the following....   import math.geom2d.Vector2D;   when I tried this, I only got....   error: package math.geom2d does not exist import math.geom2d.Vector2D;   I am totally new to Java, and im not sure what I am doing wrong, other than there might be something I need to download extra? And if so... how will others run my java app or applet if they too dont have the 'something' i might be missing?   Thanks for any help  
  18. SelethD

    How do I import Vector2D

    ok, thank you so much.
  19. SelethD

    where to start

    I have to agree with jbadams on all points.  It can not be stated enough, that to really learn and grow at programming, you MUST program.  So many people I see 'want' to program, and they have 'read' so many books (which is good), but they never actually get started in actual 'coding'.  So even if its for 30 min a day, just sit down and play with the language.   This leads to my next point, overwhelm yourself.  Dont try to make the next big MMO, FPS, or whatever... just start out making games with what you have learned.   If all you know how to do is print text out to the console, and take in input, make a little number guessing game.  Once you get to functions, and arrays, with some file IO, make a little text adventure, with limited commands.   That being said... as jbadams pointed out, C++ is probably not the best place to just jump in and start making games.  I started out in C++ in 1992, and only a few years ago picked up C#, and only this year Java.  That has given me the perspective, that just for making casual games, or testing out a new idea, it is so much easier to get something up and running in C# with XNA, or in Java.   I feel that each language is like a tool, so to be competent at your craft (programming) you will need all the different tools, so you will eventualy need to learn multiple programming and scripting langues, but just for getting down the 'flow' of making a game, you might want to look at something a bit more 'forgiving' like a managed language.   Good luck, and remember, just CODE.
  20. SelethD

    xna dead?

    I see so many of these XNA Dead threads, and really, I feel that even if there is no support for XNA anymore, there is still such a huge advantage to making a project with XNA if only for the fact, that you are learning so much in the way of game programming, that the experience is well worth it.   I started using XNA a few years ago, and that led me to learn C# (since I was only C++ before that) and since learning C#, I now have a Java class, and I feel really comfortable with the managed sort of langauges.  Also, my XNA classes and functions I have ported to C++/OpenGL, so though I dont use XNA anymore, there is nothing that I have lost in using it, but only gained.   So in conclusion, it really doesnt matter if XNA is dead or not, just program, and learn, and have fun. 
  21. SelethD

    Removing NPC economy.

    I would think, that after a while, people would store up so much of a quantity of raw materials, the trade for items might get way out of porportion.  Or the world becomes so saturated with raw materials, that new players are given so many things from previous players, that you loose the 'fun' factor of obtaining the raw items.   Perhaps if there was an 'expiration date' on a raw item, so that you could not store up large quantities of it, without it going 'bad' and being unusable.  Even crafted items might have some sort of 'durability' that would eventually require the re-creation of the object, or the rapair of it.
  22. In C++ I am wondering if this is possible or not. I have an object... MyObject it has a constructor MyObject::MyObject(string objName){ } Suppose I need to use this object, within another class.... class OtherClass { MyObject obj1; MyObject obj2; } This will give me an error, because its wanting it to look like... class OtherClass { MyObject obj1("first name"); MyObject obj2("second name"); } However, I wont know what first name, and second name are until later in the program I could do this..... class OtherClass { MyObject* obj1; MyObject* obj2; } ... then later on .... OtherClass otherClass; otherClass.obj1 = new MyObject("first name"); etc..... But I would really like to have the actual object, and not a ptr to an object. Is it possible, or am I forced to use pointers. Thanks.
  23. Oooooh, I see.... So, its sort of like when you create a constructor for a derived class from a base class. With the dreivedClass : baseClass Thanks so much.
  24. I have always used ... unsigned char* when needing to read in bytes... however, I am using an API that requires me to use a vector. So this is what I have in my objects .h file std::vector<unsigned char> image; Question is... what do I put in my destructor? Do I need to delete it, dispose it, clear it, take it to dinner and a movie? What? Thanks.
  25. SelethD

    More Collision Problems

    I have found that when doing collisions, if I forget and do an >= instead of a > in my if statements, I will get trapped in the 'solid' boject, by only 1 pixel, and get the 'stuck / vibrating' scenario you described. So double check your logic.
  • 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!