# Napivo

Member

16

106 Neutral

• Rank
Member
1. ## 2d indicator for turning a spacecraft in 3d space

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. ## Where can I start (3D math)

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. ## 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. ## Replacing IDrawable and IUpdateble

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. ## 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. ## 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

8. ## XNA Sprite performance problem with Matrix's

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; }

10. ## Finding a target from a list of numbers

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. ## Finding a target from a list of numbers

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. ## 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. ## 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. ## 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. ## Having 2000 sprites

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.