How to augment the live rgba stream with a 3d model? - c#

I am trying to augment the live RGBA stream from Kinect sensor with some 3D models using XNA (i.e. adding 3D models into a live video scene).
I succeeded in augmenting the scene with 2D sprites (e.g. circles) but I cannot add 3D objects (I think the objects are there but they hide because of the video texture). I can see 3D objects if I don't draw the video stream, but as I start applying video stream, objects disappear.

In XNA 2D and 3D rendering calls are handled differently:
2D renderings are executed without using a depth buffer (have a look at this SO post)
3D renderings are executed using a depth buffer by default
So what you want to check is if the z coordinates of the objects you want to render are right:
If the rendered pixels of your 3D model are farther away than your RGBD data, your RGBD video stream overwrites your 3D model's pixel or they are discarded right away if they are rendered after your RGBD data.
Try moving your whole RGBD data away from the camera and see if your 3D model appears. To achieve this just increment the depth values of your data. Otherwise decrement your 3D models z coordinate until you can see it. Watch out as this may result in the 3D model being rendered behind the camera.

Related

Texture rendering issue when scaling with a matrix

I am working on a game (in XNA/MonoGame) in which I have large world consisting of many individual tiles with different textures. I store my world as a 2D array and to render it, I simply loop through every tile and draw it at the correct position.
Recently I implemented a zoom feature in my camera. My game's camera is made in the 'usual' XNA way where you have create a matrix based on position and scale and that pass that into your SpriteBatch.Begin() calls. My transform matrix is calculated as so:
Transform = Matrix.Identity *
Matrix.CreateTranslation(-(int)Position.X, -(int)Position.Y, 0) *
Matrix.CreateTranslation(Origin.X, Origin.Y, 0) *
Matrix.CreateScale(Scale);
The problem I am now facing is when I zoom in (by changing the camera's scale variable) some tile textures look odd at some zoom levels. Here are some pictures showing what I mean:
Here is a map at perfectly fine zoom level:
Here is a zoomed out (and cropped) view of the same map, notice how the sand texture is wierdly "upscaled":
I do not have much experience with graphics programming and really have no idea what this is caused by, but it makes the map look very janky.

Mapping textures to DirectX sphere?

I am writing a virtual globe using DirectX similar to Google Earth. So far, I have completed tessellation, and have tested with a wrapped texture over the entire sphere, which was successful. I have written the texture coordinates to correspond with the latitude and longitude (90lat,-180lon = 0,0 and -90lat,180lon = 1,1).
For this project, I need to layer several image tiles over the sphere. For example, 8 images spanning 90 degrees by 90 degrees. These tiles may dynamically update (i.e. tiles may be added or removed as you pan around). I have thought about using a render target view and drawing the tiles directly to that, but I'm sure there is a better way.
How would I go about doing this? Is there a way to set the texture to only span a specific texture coordinate space? I.e. from (0, 0) to (0.25, 0.5)?
There are three straight-forward solutions (and possibly many more sopisticated ones).
You can create geometry that matches the part of the sphere covered by a tile and draw those subsequently, setting the correct texture before each draw call (if the tiles are laid out in a simple way, you can also generate this geometry using instancing and a single draw call).
You can write a pixel shader that evaluates the texture coordinates and chooses the appropriate texture using transformed texture coordinates.
Render all textures to a big texture and use that to render the sphere. Whenever a tile changes, bind the big texture as a render target and draw the new tile on top of it.

XNA Model won't compile?

I'm working on a game in XNA, and i'm loading a model from blender. The model didn't have a texture until now, and when it tries to compile I get this error:
The mesh "", using BasicEffect, contains geometry that is missing texture coordinates for channel 0.
The model loaded before this point. I know I have to add the texture file in the same location as the .x file in my content, and I did that. The .x file contains the segment that references the texture.
Material ShipMat {
0.640000; 0.552144; 0.594688; 1.000000;;
96.078431;
0.500000; 0.500000; 0.500000;;
0.000000; 0.000000; 0.000000;;
TextureFilename {"shipTexture.jpg";}
}
I'm using the add-on DirectX exporter for blender, because when I tried exporting my model as a .fbx it didn't load the texture and it was rotated in an odd direction. Any Ideas? Thanks in advance.
For a texture to work, each model vertex needs texture coordinates.
Sounds like the model did not export from blender with a texture coordinate element for each vertex. Most likely, your model vertices only have position, color, & maybe normal elements only.
Just go back to blender, apply any old texture you want, then re-export it & swap out textures in Xna and you will get what you're expecting now.

VBO best methods OpenGL

Does it make more sense to store the coordinates for a single cube in a VBO and use camera translation/rotation to place each block in its proper place on the map, or does it make more sense to store the entire map in a VBO and just draw from that?
It's not a minecraft clone, but it is a 3rd person top-down camera angle world that builds terrain from cubes
Simply taking the question at face-value, it seems to me the OP is considering a multi-pass render scheme vs rendering large amounts of geometry using VBOs.
If this is correct, then rendering large amounts of geometry will win over a multi-pass rendering scheme. Of course, the correct way to efficiently render many cubes is to batch them by material(s) and perform instanced rendering.

isometric tile engine

I am making an RPG game using an isometric tile engine that I found here:
http://xnaresources.com/default.asp?page=TUTORIALS
However after completing the tutorial I found myself wanting to do some things with the camera that I am not sure how to do.
Firstly I would like to zoom the camera in more so that it is displaying a 1 to 1 pixel ratio.
Secondly, would it be possible to make this game 2.5d in the way that when the camera moves, the sprite trees and things alike, move properly. By this I mean that the bottom of the sprite is planted while the top moves against the background, making a very 3d like experience. This effect can best be seen in games like diablo 2.
Here is the source code off their website:
http://www.xnaresources.com/downloads/tileengineseries9.zip
Any help would be great, Thanks
Games like Diablo or Sims 1, 2, SimCity 1-3, X-Com 1,2 etc. were actually just 2D games. The 2.5D effect requires that tiles further away are exactly the same size as tiles nearby. Your rotation around these games are restricted to 90 degrees.
How they draw is basically painters algorithm. Drawing what is furthest away first and overdrawing things that are nearer. Diablo is actually pretty simple, it didn't introduce layers or height differences as far as I remember. Just a flat map. So you draw the floor tiles first (in this case back to front isn't too necessary since they are all on the same elevation.) Then drawing back to front the walls, characters effects etc.
Everything in these games were rendered to bitmaps and rendered as bitmaps. Even though their source may have been a 3D textured model.
If you want to add perspective or free rotation then you need everything to be a 3D model. Your rendering will be simpler because depth or render order isn't as critical as you would use z-buffering to solve your issues. The only main issue is to properly render transparent bits in the right order or else you may end up with some odd results. However even if your rendering is simpler, your animation or in memory storage is a bit more difficult. You need to animate 3D models instead of just having an array of bitmaps to do the animation. Selection of items on the screen requires a little more work since position and size of the elements are no longer consistent or easily predictable.
So it depends on which features you want that will dictate which sort of solution you can use. Either way has it's plusses and minuses.

Categories