Graphing variables in real time for debugging in C# - c#

I'm working on a project in C# using XNA. It would be useful to have a way to graph the value of certain variables in real time as the game is running. (Just for debugging, I don't want the graphs in the final project.)
This seems like something that has probably been done before, but I can't find anything other than this:
http://devmag.org.za/2011/02/09/using-graphs-to-debug-physics-ai-and-animation-effectively/
I'm willing to write my own system or use someone else's. If there is an existing released project, I'd like to find it so I don't have to reinvent the wheel. If not, what;s the best way to handle this?
Thanks!

You could probably write a pretty easy system using XNA.
You should have something very basic for plotting lines:
public void DrawLine(Point first, Point second);
Run this system on every frame to collect the variable's value. Keep track of previous value.
Draw a line between previous value to current value.
If the sampling frequency is high enough, you can get a pretty decent looking graph like this.

You could write the values you want to check in a csv file, then draw a graph with excel. Here's a tutorial on writing a csv file writer/parser in C#.
The XNA hasn't support for drawing single line/pixels to screen directly (need to pass through a SpriteBatch). The only thing else I can imagine of is using a texture2D and draw your graph's pixels on it. You'll have to keep the texture in front of the camera though, with some strange matrix magics of which I don't actually know much. :P

The Xen graphics API has this feature. It appears to be for some built in variables, such as FPS, but it's all open source so I suspect it will be easy to add graphs of your own: http://xen.codeplex.com/
EDIT
I just remembered that Farseer physics also has code to do this http://farseerphysics.codeplex.com/. It's probably easier to rip out than the Xen graphs.

Related

Creating Checkpoints in XNA

I'm making an XNA 4 game, and I want to create checkpoints for certain areas in my stage. I figured I could create a "ghost" object of the player object that would be created whenever the player reaches a checkpoint. And when you want to reload that checkpoint, you'll start to where that ghost player is.
As for now, I thought this would be an easy way to achieve this (although I think XML may be a better solution, but I've no idea on how to use that, yet). But the player has too many variables (health, stamina, ammo, bleeding timer, silver keys, golden keys, coins, infection, position, speed, angle, states [involve dying, infected, bleeding, burning, dodging, etc], I just thought that statemets like "continuep1 = p1;" (both are instances of the same object) would re-assign all the variables to the values that the other class contains, but when I tried to re-load "p1 = continuep1" it wouldn't work. It doesn't seem to do anything.
So I'm wondering, do I have to re-assign ALL the variables one by one? Should I start using XML? Or is there a way to assign all the variables without having to do it one by one? (I'm not asking for code, unless the last question is possible)
In my opinion I would say yes, start using xml. Don't worry about using xml, it's pretty simple once you get your head around it. A great way to learn would be to see your characters information displayed in xml format.
I think the most ideal option would be to serialize your game. So this involves storing the state of your character, the position it is at, the direction it is facing(which texture is currently loaded) and the stats(health, staming, bleeding etc).
With this you could reload your game from the last save when the player dies or when the game is next played. This would solve both cases.
This tutorial on making a top-down RPG game in Xna 4 is very good in my opinion and goes into good detail. Many of the techniques in this tutorial apply to more than just this genre and style of game.
http://xnagpa.net/xna4rpg.php
Part 11A(Game Editor) is the first part of a tutorial guiding the reader in making an editor for their game. With this Winforms project items, classes, quests etc can be added to the game and are stored as Xml files. At the bottom of page 6, and pages 7 and 8 outlines methods to serialize and deserialize your game.
In Part 11C(Game Editor), particularly at the bottom of page 9 and page 10. A save game method is introduced which serializes the game. You can also look at the new game and open game methods too.
These methods work with DataManager classes which store the items, classes etc in Dictionary's. This may be how you want to model your game information, if not the code in these guides may have to be altered to work with your solution.
I thought it best to provide my source for learning on this subject, rather than regurgitating it. I would recommend reading around this, not just the pages I've pointed to. Furthermore, in a later tutorial the serialization goes a step further and the files are stored in .xnb, which is a much more secure way to store information.
I hope this has helped and that you appreciate the guide in the right direction as opposed to just being given the answer. Besides, this isn't a task that would be solved in one method anyway.
Let me know how you get on and I'd be happy to help more.

How to create side scrollable 2d terrain in unity?

Hi iam trying to build a game in which the skater will skate on the irregular terrain which is 2D and side scrolling. Iam not getting how to instantiate a terrain dynamically and in different shapes along x-axis.. I want to achieve something like this http://thegoldenmule.com/labs/TerramorphicGenesisAlgorithms/. Please help.
Assuming you're referring to the 'circle hill' setting on the demo you linked, here's what I'd try:
Step 1: generate some nice 1D noise. My guess is the linked demo is only using two octaves, so I'd start with that. These points will end up being spread apart when you generate pixels for the actual line. It looks like the linked demo had them about 50 pixels apart.
Step 2: use spline interpolation to get values between the points generated in step 1.
To get a sense of how this works, try this demo (make sure to change the setting to cubic spline though). You'll probably need to experiment with the parameters of step 1. My hunch is you'll want to avoid noise that it too erratic & you'll need to space the resulting points out a bit. Something like this:
Alternatively, when I was looking for a spline demo/library, I came across Curvy - it might provide what you want & save you the time of rolling your own code. If not, there are probably other spline libraries out there that might work.
I spent quite awhile looking for this and couldn't find much. I finally decided to create my own solution - if you are trying to accomplish this in Unity, I created an asset which will do this for you. For some of the theory behind it, Prime 31 has a good youtube video that explains the general approach to take.
Try this asset from unity asset store.
This is very small, easy to use. Although graphics is pretty bad, you can put some shader or pp effect.

Localization of a robot using Kinect and EMGU(OpenCV wrapper)

I'm working on small WPF desktop app to track a robot. I have a Kinect for Windows on my desk and I was able to do the basic features and run the Depth camera stream and the RGB camera stream.
What I need is to track a robot on the floor but I have no idea where to start. I found out that I should use EMGU (OpenCV wrapper)
What I want to do is track a robot and find it's location using the depth camera. Basically, it's for localization of the robot using Stereo Triangulation. Then using TCP and Wifi to send the robot some commands to move him from one place to an other using both the RGB and Depth camera. The RGB camera will also be used to map the object in the area so that the robot can take the best path and avoid the objects.
The problem is that I have never worked with Computer Vision before and it's actually my first, I'm not stuck to a deadline and I'm more than willing to learn all the related stuff to finish this project.
I'm looking for details, explanation, hints, links or tutorials to achieve my need.
Thanks.
Robot localization is a very tricky problem and I myself have been struggling for months now, I can tell you what I have achieved But you have a number of options:
Optical Flow Based Odometery: (Also known as visual odometry):
Extract keypoints from one image or features (I used Shi-Tomashi, or cvGoodFeaturesToTrack)
Do the same for a consecutive image
Match these features (I used Lucas-Kanade)
Extract depth information from Kinect
Calculate transformation between two 3D point clouds.
What the above algorithm is doing is it is trying to estimate the camera motion between two frames, which will tell you the position of the robot.
Monte Carlo Localization: This is rather simpler, but you should also use wheel odometery with it.
Check this paper out for a c# based approach.
The method above uses probabalistic models to determine the robot's location.
The sad part is even though libraries exist in C++ to do what you need very easily, wrapping them for C# is a herculean task. If you however can code a wrapper, then 90% of your work is done, the key libraries to use are PCL and MRPT.
The last option (Which by far is the easiest, but the most inaccurate) is to use KinectFusion built in to the Kinect SDK 1.7. But my experiences with it for robot localization have been very bad.
You must read Slam for Dummies, it will make things about Monte Carlo Localization very clear.
The hard reality is, that this is very tricky and you will most probably end up doing it yourself. I hope you dive into this vast topic, and would learn awesome stuff.
For further information, or wrappers that I have written. Just comment below... :-)
Best
Not sure if is would help you or not...but I put together a Python module that might help.
http://letsmakerobots.com/node/38883#comments

Enhance 3D kinect render performance inside a WPF application with Helix 3d Toolikt

i'm making a little app for create a 3d model from multiple kinects (in real-time!), and i'm using as BIG source of ispiration the Helix 3D Toolkit kinect example, it works great!
Sadly it has veeeeery poor performance and looks like the CPU gets all the work :( i know i must use something more powerfull than Helix 3D for this kind of stuff but i need to complete my project quickly and i don't have time to learn slimDX, sharpGL, openTK or whatelse (they all require to write a shader to do this kind of stuff, a little too time burning!)
So, this is what i got now:
it's cool but i got very poor performance. I can enhance a little lowering depth sensor resolution to 80x60, getting this:
a little toooo blurry, but with very good performance :D
this result is got creating a GeometryModel3D, editing its Geometry, Material and Transform value. Inside the Geometry now i have a MeshGeometry3D, with good results but poor performance (the cpu need to regenerate all the triangles at every frame!).
The MeshGeometry3D is composed by Positions, TextureCoordinates and TriangleIndices properties, like MSDN says. I like to mess all and i tried to remove the TriangleIndices values getting this:
Useless but with better performance. But now i have some hope, looks like i have lots of lines (or very distorted triangles?) with some good placed vertices.
What i can do for having something accetable here? Even something like a cloud point it's perfectly fine, i just need to have nice performance!

How to make a circle to move in C#?

I want to write a simple game like pacman in C# in order to learn
the new language.
However, I don't know how to make a circle move?
Which part of knowledge in C# is needed?
You should check out XNA Game Studio from Microsoft. It's a version of Visual Studio that's targetted especially for writing games. You use C# but get a lot of things for free - graphics, sound, timing...
Here's a tutorial for making a ball move in XNA.
The simplest way would be to move your circle a small bit with every tick of a timer control.
If you want to learn a new language stay away from all fuss and just look into the most essential parts.
Having knowledge about previous programming languages helps a lot, espesially if one of those are Java.
You don't need to look into XNA for this, all you really do need is to Start Visual Studio, create a new Windows Form, drag over an PictureBox and start playing with the KeyEvents.
Your game does not have to be awesome for you to learn the very basics of C# and .NET. And you certainly don't need to dig down in the deep jungle of XNA!
Once you have your form up and running with a PictureBox or two and you have conqured the Event-system, take a look at the other fundamental parts of .NET that makes your life easier. Properties, Generics, Data Sources and much much more.
Well, for a simple single player game like that, some of the most important things you need to know about are data structures and GDI.
Data structures are important because you need to store information such as what does a map look like? Where are the walls? Can you go from one end to the other? How does the map draw itself?
GDI is used in C# to draw. This uses the Graphics context. You'll find lots of examples online, and I'd suggest checking out BobPowell.Net GDI+ FAQ to avoid some of the common mistakes.
You probably want to look into XNA - http://creators.xna.com/
Simply download the studio, install, then run Visual Studio C# (mine is Express Edition).
So when you run, you create a new Windows Game Project and you've created your first game.
Good to read up some books and articles on XNA.
Book: Microsoft XNA Game Studio 2.0: Learn Programming Now! by Rob Miles.
if you mean how to move an object around in a circular movement, then you just need math knowledge:
int circlePosX = centerX + Math.Cos(degrees) * radius;
int circlePosY = centerY + Math.Sin(degrees) * radius;
radius is here how big you want the circle to be, and degrees is the position ion the circle the object is moving.
Here's an answer to a question about a radar-type game that demonstrates generally how to do this in C#/WinForms using GDI+ (with a sample and source code):
What would be the best way to simulate Radar in C#?

Categories

Resources