XNA a Simple 2D Point Light - c#

i want to make a 2D Point Light , in XNA, i was able to find some helpful information but is too advance for me , since i dont know nothing about Shaders
http://www.soolstyle.com/2010/02/15/2d-deferred-lightning
so my best aproximation is use a texture and use alpha blending, but im not happy with this result
so i was wondering, what is the most simple method to make a simple 2d point light?, if is there some Code examples, better

You can see a great example of how to do simple 2d lighting using XNA here at Shawn Hargreave's blog:
http://blogs.msdn.com/b/shawnhar/archive/2007/01/02/spritebatch-and-custom-blend-modes.aspx
"With multiplicative blending, I can draw a couple of rotated copies
of this sprite over my scene. Note how the light isn't just drawn as
white, but actually brightens up whatever scenery lies behind it:"

Related

Emgu Camera Calibration

I am using emgu/opencv to find the position of some flat blobs. I can currently find their positions in pixels and would like to convert this to world coordinates (in/mm). I have looked at emgu's camera calibration example, but I am having trouble actually applying it to get what I want. Using the example, I believe I can get the intrinsic matrix, but I am not really sure what to do with it. My camera is fixed and is looking down at the fixed plane the blobs are on. Any help would be appreciated. Thank you.
It sounds a little like you just want to know the size of flat objects that are located on the same plane as a calibration pattern. If that´s the case this is quite easy if the camera is looking normal onto the plane (no perspective distortion). You can then just calculate a pixel to millimeter conversion factor from the calibration pattern and you are done.
If that´s not the case and you want to fully calibrate your camera, you can either move your camera or if you only have one image use a 3D- calibration pattern. This is to avoid that all points are coplanar which leads to a degenerated solution.

How can I draw a Texture without using SpriteBatch in XNA?

So I'm working on a project, where I have a 3d cube-based world. I got all of that to work, and I'm starting the user interface, and the moment I start using spritebatch to draw a cursor texture I have, I discovered that XNA doesn't layer all the models correctly, some of the models that are further away will be drawn first, instead of behind a model. When I take out all the spritebatch code, which is just this:
spriteBatch.Begin();
cursor.draw(spriteBatch);
spriteBatch.End();
I find that the problem is fixed immediately. The cursor is an object, the draw method is just using spriteBatch.draw();
The way I see it, there are two solutions, I could find a way to draw my cursor and other interfaces without using SpriteBatch, or maybe there is a parameter in spriteBatch.Begin() that I could plug in to fix the issue? I'm not sure how to do either of these, anyone else encounter this problem and know how to fix it?
Thanks in advance.
This does not answer the question!
I'm not sure if you could (or should) draw 2D without a spritebatch, however I've had the same problem with 3D model rendering when using 2D spritebatch, and the solution on solution I've found on GameDev helped me solve this:
Your device states are probably wrong. This often happens when mixing
2D and 3D (for example the overload for SpriteBatch.Begin() which
takes no arguments sets some device states that are incompatible with
3D rendering. No worries though, all you have to do is to make sure
that the following device states are set the way you want them:
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
Basically, you first call the SpriteBatch methods for 2D draws, then the above code (which should ensure proper 3D rendering), and then draw your 3D models. In fact, I only used the first two lines - BlendState and DepthStencilState and it worked as it should.
Have you had a look at this overload?
You can use the last parameter, layerDepth, to control in what order sprites are drawn. If you use that, make sure to check out the sprite sort mode (in the SpriteBatch.Begin(...) call) as well. Does this cover what you need to do?
Edit: Also note that this implies using the correct perspective matrix, drawing in 2D (I'm assuming you want your cursor to display in 2D on top of everything else), and after all the 3D stuff (it's quite possible to draw sprites at Z=0 for example, making objects in front of that obstruct the sprite).

Map format in 2d racing game

I have little experience in writing a simple games on XNA, but now i dont have knowns to solve my problem.
So, i want to write simple racing 2d-arcade, and i dont know how i can do maps for this game.
I decided do this so:
I draw a picture-map in mspaint. Black - its grass, white color -
its road, red color - road markings, blue - water, green - forest,
etc.;
After the image is loaded, I override textures in XNA - on white
color i place texture of road, on black color i place texture of
grass and etc.
So i have 2 questions.
I think in the right direction?
How i can to know color in desired pixel and how i can pour all white color, not each pixel separately? Second question not required, because i can just do second image with normal textures, and place this on second layer, right?
Sorry for really bad english. And thanks for answers advance.
In MSDN forums, man with the nickname Mad Martin adviced do so:
Draw the final picture in paint with the mixture of textures like you
want it on the screen. Draw this texture directly. Now you'r game
logic needs to know where the road is in that texture. There are two
ways i can think of:
Make the road a spline and calculate the exact layout of the game. Probably a bit steep for beginners, but the most powerful.
Make a separate texture like yours with just two colors(black no road, white road). You can then check via the coordinates of the cars
whether you are on the road or not. You can do this either on the CPU,
by readign the texture into an array with Texture2D.GetData, or you
can do this on the GPU. Either way needs a little fiddling around, so
your cars dont hang on the edges of the road.
i think that it's quite useful answer, so i close question.

Restrict movement on reaching map border or any objects

I'm totally new in game-dev and would like to know the best practice about above question.
Let me explain more.
I want to create 2D game with top-down view and with free movement (without snapping to the grid) just like any Zelda game on GameBoy.
How should I store map bounds? Is there a way to do this automatically? For example I have a texture with background and texture with foreground where black color should appear transparent and should allow to move in space of it.
Thanks in advance.
For easy 2D collision detection, you'll probably implement bounding boxes.
Basically you will create a rectangle that represents every Game Object. The coordinates and size of the rectangle will be the same as the Texture2D (it is common to make this a property on the given class). Every time you update the position of your Texture, you update the position of your bounding box.
Now to check for collision, just loop through your game objects and see if any of the bounding boxes intersect.
Once you get the idea, you'll see that its very easy to implement. XNA also provides some math helpers to abstract the math (though its simple addition and subtraction).
Try this link for a more in depth explanation with code examples: http://www.dreamincode.net/forums/topic/180069-xna-2d-bounding-box-collision-detection/

Calculating Elliptical Orbit in OpenGL?

As everyone knows, satellites around the earth don't go in a perfect circle. They are more an elliptical orbit.
I'm trying to represent this using OpenGL to draw an orbit around the earth. Currently, I draw a dashed-line composed of 360 markers which makes a series of dashes around the globe in a nice perfect circle.
If I have the Orbital inclination, Perigee and Apogee what would be the way to calculate this circle? I'm trying to find a formula or white paper or something to get me in the right direction....
What this is crazy, of course they are perfect orbits. No but seriously sounds more like a need Physics formua. Try..
http://scienceworld.wolfram.com/physics/Orbit.html
or
http://physics.info/orbital-mechanics-1/
Don't have really any experience here, but if you plan to actually track satellites you will want to use the Keplerian elements ( http://en.wikipedia.org/wiki/Orbital_elements#Keplerian_elements , http://en.wikipedia.org/wiki/Orbital_elements#Orbit_prediction) which get published for satellites. Note that real satellites have perturbation in their orbits so the Keplerian elements for a satellite are regularly updated. If you just need something that "looks" like satellite orbits then the idealized ellipses form the other answer will be fine.

Categories