Jump to content
  • Advertisement

Napivo

Member
  • Content Count

    16
  • Joined

  • Last visited

Community Reputation

106 Neutral

About Napivo

  • Rank
    Member
  1. Maybe you guys can help me out. I have been trying this for days.   I have this 3D space game and want an indicator (2D arrow in the center of my picture) that points in the direction to turn my ship in 3D space. (Up, down, left, right) so that it always points to the shortest angle to the selected object, regardless whether my ship is facing the object or not.   I have the coordinates of the selected object and the player as well as the angle in which the player is facing. Basicaly;   Vector3 PlayerPos; Vector3 SelectedPos; Vector3 PlayerDirectionEuler; or even better Quaternion PlayerDirectionQuaternion;   I have tried so many things, asked and have had so many wrong answers, I can't even remember the 1000 things that didn't work.   The perfect result for me would be a floating point indicating the rotation of my angle in the Z axis.   Please someone give me a hand with this.... It looked so easy when I started but now I am desperate.  
  2. I am pretty well accomplished in 2d math. I have written several games but 3D math I never learned. I am thinking along the lines: Given a quad and a normal how to calculate the counter-clockwise triangles. How to calculate if 2 quads or triangles intersect. How to calculate a bounding rectangle and sphere of an object. I am a real newbie at this, I can't even understand most of the formula's I find on-line. I have taught myself everything about programming and most things I know about math but now I don't even know where to begin. what basics I need nor where to find them Thanks for any help
  3. Napivo

    Replacing IDrawable and IUpdateble

    Just use namespaces properly, this is why they exist. namespace Foo { interface IDrawable { // stuff } } elsewhere class Bar : Foo.IDrawable { // stuff } [/quote] I really don't want to be typing Napivo.Xna.Core.IDrawable all over my code or resolve the name conflict everytime I need both Namespaces which is about everywhere... Maybe I am just too lazy. And yes I know I can shorten it to NXC.IDrawable If I use "using NXC = Napivo.Xna.Core;"
  4. The thing I hate most about XNA are the interfaces IDrawable and IUpdatable, they are completely useless. I have my own implementations of them. iDrawable and iUpdatable. Honestly they are extended versions that I use with my own update and draw managers. Of course that works just fine except that they old ones still exist and that interfaces should start with a capital 'I'. furthermore it is kind of confusing for outsiders. Since they have nothing to do with one another yet almost are the same. Is there any way to not load the interfaces, or disable them is some way or is the only way to get around this, changing the names of my interfaces to ICanDraw, INapivoDraw or .... I don't know. Suggestions for naming these interfaces would be welcome.
  5. Napivo

    A Specific Question About Windows Form

    The thing you want to look into is for c# DllImport attribute. http://msdn.microsof...v=vs.71%29.aspx I have only done this a few times myself and the declarations are not easy at all [DllImport("Advapi32.dll", EntryPoint="GetUserName", ExactSpelling=false, SetLastError=true)] static extern bool GetUserName( [MarshalAs(UnmanagedType.LPArray)] byte[] lpBuffer, [MarshalAs(UnmanagedType.LPArray)] Int32[] nSize ); Hope that puts you on the right track. I'd rather suggest you take a look at XNA It's pretty cool to work with as all those tasks have already been done.
  6. Napivo

    Angle from Rotation matrix ?

    Wow nice link.... Thank you... Wanted to come and ask if I could find the individual matrices when they where combined in this way... This is only for a 2D game Matrix Transform = Matrix.CreateTranslation(new Vector3(-vDrawObject.Origin, 0.0f)) * Matrix.CreateScale(vDrawObject.Scale.X, vDrawObject.Scale.Y, 1) * Matrix.CreateRotationZ(vDrawObject.Rotation) * Matrix.CreateTranslation(new Vector3(vDrawObject.X, vDrawObject.Y, 0.0f)); I guess I will find the answer there Off to read
  7. I hesitated to send this as there are some problems with the tool right now. Nprof is a tool that profiles .net code. trouble is it doesn't work for .net 4 and XNA4. that is not unless you use this workaround. Download Nprof here http://code.google.com/p/nprof/ install it. Then create a batch file NProf.bat and enter set COMPLUS_ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler NProf.exe If you run your program under it, it will upon exit generate a rapport where you can see what parts of your program take the longest. [attachment=5699:Nprof.png] Here you see an example as you can see of the 100% that Test of Nprof takes BadGameClass takes up 90% BadGameClass.BadUpdateFunction 89% so now you know where to look for your problem. The tool doesn't look like much but for me it's invaluable when optimizing my code as I can find out where to put the work to get the best performance.
  8. I have no idea what you mean by "Reimers pixel perfect collision function" but for a game i was writing I needed to make check for lists of literally 100's of bullets with 100's of objects. First trick I used was to only recalculate the matrix and bounding rectangle for each object only when needed. Basically everything was derived from Sprite implementation of iSpriteinfo. Whenever X,Y, rotation, scale and whatever changed sprite would set a needrecalc flag. The next time I needed a matrix or boundingbox it would recalculate them. Also make sure the values actually changes you would be surprised how often the value set is already stored... Second trick was to cache the ColorData I needed for collision checking into a static dictionary of spriteNames. I know this takes up a lot of memory but since I only had a limited amount of sprites that needed to be collision checked and had enough memory I didn't care. The last trick was to write optimized code to compare lists with lists of objects so that I needed to collect the data for the first list of objects only once. I leave you the routines to calculate a bounding box and to one I use to do pixel-perfect Collision checks. I forgot where I converted them from they came from a forum much like these ones but I have been using them for ages. I hope It helps. [size="4"]CalculateBoundingRectangle /// <summary> /// Calculates an axis aligned rectangle which fully contains an arbitrarily /// transformed axis aligned rectangle. /// </summary> /// <param name="rectangle">Original bounding rectangle.</param> /// <param name="transform">World transform of the rectangle.</param> /// <returns>A new rectangle which contains the trasnformed rectangle.</returns> public static Rectangle CalculateBoundingRectangle(Rectangle vrectangle, Matrix transform) { Rectangle rectangle = vrectangle; rectangle.X = 0; rectangle.Y = 0; // Get all four corners in local space Vector2 leftTop = new Vector2(rectangle.Left, rectangle.Top); Vector2 rightTop = new Vector2(rectangle.Right, rectangle.Top); Vector2 leftBottom = new Vector2(rectangle.Left, rectangle.Bottom); Vector2 rightBottom = new Vector2(rectangle.Right, rectangle.Bottom); // Transform all four corners into work space Vector2.Transform(ref leftTop, ref transform, out leftTop); Vector2.Transform(ref rightTop, ref transform, out rightTop); Vector2.Transform(ref leftBottom, ref transform, out leftBottom); Vector2.Transform(ref rightBottom, ref transform, out rightBottom); // Find the minimum and maximum extents of the rectangle in world space Vector2 min = Vector2.Min(Vector2.Min(leftTop, rightTop), Vector2.Min(leftBottom, rightBottom)); Vector2 max = Vector2.Max(Vector2.Max(leftTop, rightTop), Vector2.Max(leftBottom, rightBottom)); // Return that as a rectangle return new Rectangle((int)min.X, (int)min.Y, (int)(max.X - min.X), (int)(max.Y - min.Y)); } [size="4"]IntersectPixels /// <summary> /// Determines if there is overlap of the non-transparent pixels between two /// sprites. /// </summary> /// <param name="transformA">World transform of the first sprite.</param> /// <param name="widthA">Width of the first sprite's texture.</param> /// <param name="heightA">Height of the first sprite's texture.</param> /// <param name="dataA">Pixel color data of the first sprite.</param> /// <param name="transformB">World transform of the second sprite.</param> /// <param name="widthB">Width of the second sprite's texture.</param> /// <param name="heightB">Height of the second sprite's texture.</param> /// <param name="dataB">Pixel color data of the second sprite.</param> /// <returns>True if non-transparent pixels overlap; false otherwise</returns> public static bool IntersectPixels( Matrix transformA, int widthA, int heightA, Color[] dataA, Matrix transformB, int widthB, int heightB, Color[] dataB) { // Calculate a matrix which transforms from A's local space into // world space and then into B's local space Matrix transformAToB = transformA * Matrix.Invert(transformB); // When a point moves in A's local space, it moves in B's local space with a // fixed direction and distance proportional to the movement in A. // This algorithm steps through A one pixel at a time along A's X and Y axes // Calculate the analogous steps in B: Vector2 stepX = Vector2.TransformNormal(Vector2.UnitX, transformAToB); Vector2 stepY = Vector2.TransformNormal(Vector2.UnitY, transformAToB); // Calculate the top left corner of A in B's local space // This variable will be reused to keep track of the start of each row Vector2 yPosInB = Vector2.Transform(Vector2.Zero, transformAToB); // For each row of pixels in A for (int yA = 0; yA < heightA; yA++) { // Start at the beginning of the row Vector2 posInB = yPosInB; // For each pixel in this row for (int xA = 0; xA < widthA; xA++) { // Round to the nearest pixel int xB = (int)Math.Round(posInB.X); int yB = (int)Math.Round(posInB.Y); // If the pixel lies within the bounds of B if (0 <= xB && xB < widthB && 0 <= yB && yB < heightB) { // Get the colors of the overlapping pixels Color colorA = dataA[xA + yA * widthA]; Color colorB = dataB[xB + yB * widthB]; // If both pixels are not completely transparent, if (colorA.A != 0 && colorB.A != 0) { // then an intersection has been found return true; } } // Move to the next pixel in the row posInB += stepX; } // Move to the next row yPosInB += stepY; } // No intersection found return false; }
  9. I think I got it working at least for my needs... this procedure can take a long time when feeding it a lot of numbers where it can't reach it's goal ex three times 1001, 2001, 3001, 4001, 5001, 6001, 7001, 8001, 9001, 1002, 2002, 3002, 4002, 5002, 6002, 7002, 8002, 9002 and then sending it after 100000 but for my cases it will do just fine. /// <summary> /// Finds from a list of numbers /// the numbers that add up closest to a target /// Returns a list of numbers that added up are the closest to the target /// Also returns the rest /// </summary> public static class Knapsack { //for further optimizing... not sure if it will work //static DuplicateDictionary<int, List<int>> Combinations; /// <summary> /// used for sorting numbers High to low /// </summary> /// <param name="x">First number</param> /// <param name="y">Second number</param> /// <returns></returns> private static int CompareHighestFirst(int x, int y) { return y.CompareTo(x); } public static int iterations =0; /// <summary> /// Finds from a list of numbers /// the numbers that add up closest to a target /// Returns a list of numbers that added up are the closest to the target /// Also returns the rest /// </summary> /// <param name="target">Number to be reached</param> /// <param name="numbers">List of numbers to chose from</param> /// <param name="rest">out rest of the target - sum </param> /// <returns>List of numbers</returns> public static List<int> FindBestMatch(int target, List<int> numbers, out int rest) { int sum = 0; bool HasOdd = false; numbers.Sort(CompareHighestFirst); List<int> numberList = (from n in numbers where n <= target select n).ToList(); List<int> bestList; //Check if have Odd Numbers //Make total sum pf numbers foreach (int i in numbers) { if ((!HasOdd) && (i % 2 == 1)) HasOdd = true; sum += i; } //if the total is lower than the target if (sum < target) { bestList = new List<int>(); //Make a list of all numbers foreach (int i in numbers) { bestList.Add(i); } rest = target - sum; return bestList; } else if ((!HasOdd) && (target % 2 == 1)) { //If there are only even nubers and target is odd //make target even target--; bestList = FindBestMatch1(target, numberList, out rest); //Add one to rest rest++; } else { //find the best numberlist bestList = FindBestMatch1(target, numberList, out rest); } return bestList; } private static List<int> FindBestMatch1(int target, List<int> numbers, out int rest) { iterations++; //lists and rest variables to store temp best results List<int> bestList = new List<int>(); int bestRest = target; //Only numbers lower than terget are required. sorted from high to low List<int> NumbersList = (from n in numbers where n <= target select n).ToList(); NumbersList.Sort(CompareHighestFirst); //make a copy of the list to use as new parameter List<int> TempList = NumbersList.ToList(); //only one number if (numbers.Count == 1) { //Just making sure can be removed if (numbers[0] < target) { bestList.Add(numbers[0]); bestRest = target - numbers[0]; } } else if (numbers.Count > 0) { //used to do the checks only ones int last = target + 1; foreach (int i in NumbersList) { if (last > i) { last = i; List<int> newList; int newRest; if (i == target) { //if target is found return it newList = new List<int>(); newList.Add(i); newRest = 0; } else { //it not found yet TempList.Remove(i); //remove ourself from the list //recusivly find the best solution for the rest of our target newList = FindBestMatch1(target - i, TempList, out newRest); newList.Add(i); //add ourself to the new list //For further optimisations No idea if it(s going to work //if (Combinations == null) //{ // Combinations = new DuplicateDictionary<int, List<int>>(); // Combinations.Add(target - newRest, newList); //} } if (newRest < bestRest) { bestList = newList; bestRest = newRest; if (bestRest == 0) { break; } } } } } rest = bestRest; //OutputList(target, bestList, rest); return bestList; } } Thanks for all your pointers
  10. First of all this is not homework... Wish it was then i knew where to go look for even the beginning of an answer. Need to go look up that greedy algorithm but I think I got an idea.... Indeed might try and addup the highest numbers till I reach the target. Then search for each of those numbers a replacement + the rest of what I am searching for... Thanks guys... will let you know when I find it.
  11. I have a list of non unique numbers and I need to find which numbers add up closest to a target but never exceeding it. I would like to find the highest numbers possible from the list with the lowest remainder. How do I even start doing this?. I have been breaking my head... tried brute forcing it.... works well of course but takes ages if the list is > 50 numbers and sometimes the list is as large at 300 numbers. Can anyone please help me out?
  12. Napivo

    C++ ERROR "no match for operator> in .."

    Your cards are so funny especially this one:) http://members.gamedev.net/fruny/forums/magic/working_search.jpg Sorry completely off topic
  13. Napivo

    Having 2000 sprites

    I must agree with mhagain and taking Hodgeman's remarks into account. The advantages of using large Textures are: You only have to load the texture to the video card onceReduce swapping in GPU I just need to look out for Older video card that do not support 4096 x 4096 What I still need to look into is is the compression thing. DXT5 or DXT1. Right now If I load like 4 * 64mb to the video card. That would mean I use 256Mb. In itself that is no problem but still have the screen and background to take into account. Thanks for the info
  14. Napivo

    GameStateManager or ScreenManager?

    What I do is indeed create a baseclass named Screen Abstract Draw() Abstract Update() Now I create the different screens MenuScreen inherits from Screen GameScreen inherits from Screen Whateverscreen inherits from Screen in my game class I have then a Screen CurentScreen property Now all I have to is change the CurentScreen to whatever I want to display. in Game. Update and Game.Draw, I just call CurentScreen.Update and Curentscreen.Update. No need for switch statements The advantage of doing this is that all code for each screen is confined in a separate class. The other thing I know people do and I think that is what you are talking about is to use of FSM (finite state machines) to trigger the transition from one screen to another. I have never done this but it would male sense if you have a lot of screens and need to switch from one screen to a lot of different screens depending on what the user wants.
  15. I'm pretty sure someone answered this one a hundred times but I can't find and relevant data for me. I have like 2000 sprites in my sprite library and can't fit them all in a single texture2D (4096x4096) So I decided to create a spritelib class which generates textures and stores the location of my sprites. That works like a charm but now I read on the Internet that most people frown upon the use texture sizes of 4096x4096 but it looks like these people are talking about 3D worlds with heaps of textures. Right now I am only creating a 2D world and have 3 of those large textures. My questions are: When will this become a problem?If I optimize the draw events to minimize the swapping of textures(which I will surely do) does it matter?If using these huge textures is going to be a problem what would be an optimal setting for texture size? Just need to change a const Thanks for your advice.
  • 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!