I'm looking for a C# implementation of a Spline,
not to draw it, but to traverse it.
Basically I have a 2D game and I want an object to move on a predefined path.
Any ideas how to implement this ?
Thanks,
SW
Have a look at some equations on how to interpolate splines:
http://en.wikipedia.org/wiki/Spline_interpolation
This may also help: Calculate a bezier spline to get from point to point
When I had to do this for a game years ago, I implemented a form of parametric spline curve that was simple to build and required little in the way of CPU resources. What I built is similar to what's in the linked article. One really nice thing about this type of spline is that the math is not at all advanced.
Unfortunately, I don't have access to the C source code for my implementation.
Also check out Numerical Recipes, and netlib.org.
Related
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.
These days I am trying to develop two algorithms in c#. Self Organizing Map, Particle Swarm Optimization and Glowworm Swarm optimization. I know how the algorithms work but there is an issue which I am not sure where to start from.
Agents in the search space which try to find the best solution have some coordinates(x and y). I don't know how am I should represent the position of agents visually in a form in each iteration. One option may be using charts in c# and represent point so that in each iteration I am going to change the position of the agent(point) in the chart. Another way may be using drawing classes in c# and drawing circles or points in a panel based on the x and y coordinates. Which classes of .net should I use to represents points in a search space visually(in a 2D space).
I hope you understood me and thank you for reading this post.
If your design variables are N-dimensional, N>3, it is not an easy job to visualize the entire domain of interest. You can either project the N-Dim to 2D or 3D to get a "section" of the fields.
I have an image processing question, using C#.
Say I have some schematic diagrams in BMP format, the diagram contains component shapes which are connected to each other.
I wrote a simple program to detect square shapes in the diagram as one component, and record the location of it. However, the next level is to detect more complicated shapes like a few arcs joined together. Note that these shapes can be different sizes in the image. Does anyone know any good method of doing it? without downloading any library (this is my limitation now).
After detecting the shapes, I also need to record which shape is connected to which, so later on, I can redraw them. I have one week to do this, so thanks a lot for any help!!
I'm using C#.
Have a look at this paper. My understanding of their approach:
Detect edges
Detect corners by looking for perpendicular edges
Detect polygons by looking for groups of corners
Detect circles using Hough transform
This is a fairly difficult research problem. Even with a powerful computer vision library like OpenCV, implementing an effective solution within 1 week would be a demanding task.
Have you taken a look at using EmguCV? It is an open-source C# wrapper of OpenCV. It also has a shape detection sample you might interested in.
To answer an old post I had, I have done what I needed to do in 2 weeks time, it worked well. I actually ended up using different algorithms for different shapes. The algorithms are a bit self inventions, but a good method I want to mention is that get the histogram and then use projection on different axis helped a lot.
I am going to make a game like XNA example game "Platformer1" which comes with the XNA. But I need longer levels which doesn't fit in the screen (like Super Mario levels). How can I manage this kind of level? Do I need to use a 2d camera that follows the sprite? If I do this way how can I load the level? I am a bit confused and I am not sure if I could explain my problem clearly. Hope someone can help?
The tutorial based on Platformer Starter Kit in MSDN has a step Adding a Scrolling Level which guides you through creation of longer levels. The tutorial is very detailed, I highly recommend it.
I couldn't find the tutorial in the section for XNA Game Studio 4.0, but differences should be minimal. According to the comment at the bottom of the page, all you need to change is replace
spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None, cameraTransform);
with
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullCounterClockwise, null, cameraTransform);
in the tutorial code.
If you want to create a side scrolling game, then I would look into parallax scrolling. A quick google/bing will help you find lots of tutorials. Also, another useful tip is to search YouTube for XNA videos has we a lot of posters share their source code .
Here is a link to Microsofts Parallax Scrolling.
Sounds like you have a few problems ahead of you.
But I need longer levels which doest'n fit in the screen(like super mario levels). How can I manage this kind of levels.
There are several ways to do this, but a fairly easy way would be to have a 2d array (or sparse array, depending on how large your levels are) of a class named Tile that stores info about the tile image, animation, ...whatever.
Yes, you'll probably want a "camera". This can be as simple as only drawing a certain range of that array or a more featured camera that uses transforms to zoom out and translate across your level.
Hopefully this will help get you started.
I've done a decent amount of work in XNA, and from my experience, there are 2 ways to draw a 2D scene:
1) Strictly 2D. This method is much easier, but has a few limitations. There is no "camera" per se, what you do is move everything underneath the fixed 2D "camera". I say "camera" in quotes because the camera is fixed (as far as I know). The upside is that it's easy, the downside is that you can't easily zoom in or out or do other camera effects.
2) 2D in 3D. Set up a 3D world with a 2D plane. This is more flexible, but is also more challenging to work with because you will need to set up a 3D world and 3D camera. If this is your first attempt with making a game, I would highly recommend against this method.
I'm really only familiar with the strictly 2D method, and you would want a list of map objects that have a 2D coordinate. You would also want to store which section of the map you are looking at, I do this with a Rectangle or Vector2 that stores this. This value would move forward as the character moves. You can then take your 2D map objects' coordinate and subtract the (X,Y) of the top-left of what you are looking at to determine an object's screen position. So:
float screenX = myMapObject.X - focusPoint.X;
float screenY = myMapObject.Y - focusPoint.Y;
An other thing to note, use floats or Vector2/3 to store locations, you may not think it's required now, but it will be down the line.
It might be overkill, but my SF project uses XNA to draw a Strictly 2D scene that you can move around: http://sourceforge.net/projects/asteroidoutpost/
I hope this helps.
Have a look at Nick Gravelyns tutorials. They helped me tonne when I was first starting out - Really really worth a look for learning a lot on 2D games.
All the videos are now on youtube here
Draw two circles which has intersect each other, from that I need to find that intersect point using c# using directx. I need to find two points.
Are you sure you need DirectX here? This is purely mathematical problem. See this:
(source: uwa.edu.au)
This has nothing to do with DirectX really, or even C#. It's just geometry. See this page for the appropriate formula and reasoning.