Texture onto 3D car mesh - c#

I have a 3D car mesh object. How can I reflect a 3D text onto the 3D mesh surface?
I'm using Visual Studio 2008 C# Express. The 3D car mesh object is ready for use in C# project.
That is, I must use it in my C# project, not in Blender.
All the development processes that I need must be done in C# development environment.

You should use a 3D modeling tool like Blender, AC3D or similar. This will help you create the "model" and placing any textures on it. Then you will also need some kind of drawing engine so you also can load and draw the model in your app.

It's unclear specifically what you're talking about here.
Did you mean Text, or Texture?
Simply texturing the model - If you're using blender to create the model, texture it, and export it in .x or another format and render it using an appropriate library.
Reflecting Text - Look into projective decals.
Or a bit more advanced
Reflection of the environment - To simulate reflective surfaces you're going to need to program a shader. Look into HLSL, GLSL, CG, or you can do the shader in ASM. - Reflection Mapping
EDIT: Added link to reflection mapping.

If you need Direct 3D access at run-time, try using SlimDX.

Related

Drawing in Unity using C#

I currently have a WinForms C# application. I have a .txt file with GPS coordinates of some points (borders of buildings, roads etc.), and using Graphics.FillPolygon method in System.Drawing I am drawing these on a Panel. However, I got an idea that for what I am trying to do (it basically is a 2D game), a Unity 2D project would be more suitable and easy to use (mainly because of easier view handling using the cameras). However, I don't know how to do this drawing in it. I just need to somehow get these coordinates drawn in Unity, but I don't know how to do it.
Note: I already have some minor expirience with 3D in Unity, but I am a total newbie to 2D.
Thanks
There is no GDI/canvas implementation built into Unity. Drawing these in rastered 2D would be quite hard in Unity (basically putpixel level, or finding some third party library).
You have an alternative, though - you can draw these shapes in 3D, ignoring the third dimension. You have a few methods for this:
Line renderers - this one will be the easiest, but forget about anything else than just drawing the outline, no fill etc.
Make your own mesh - This will let you use the geometry with your scene. It's an retained mode API (you init your geometry once)
Use the GL namespace - This will be only rendered on the screen, no interaction with the scene. It's an immidiate mode API (draw everything on every frame)

Projecting a LibNoise sphere-mapped image on a model

I've used the .NET port of LibNoise to create a planetary map using its built-in sphere projection. However, now I want to wrap that texture around a sphere in XNA. I've got a sphere model, but I know very little about UV wrapping, etc. It's entirely possible, if not plausible, that the way I've put UV coordinates on my model absolutely will not work with the generated texture.
I've set up a small test project rather than fiddle around in my main game. It's your basic rotating model project. I'm using BasicEffect on the model and setting the Texture parameter as my map. However, all I see is the model with its default diffuse color and no texture.
For your convenience, the full code of the project:
Game1.cs
PlanetTerrainMap.cs
Required files:
sphere.fbx
EarthLookupTable.png
Also, I totally recognize that my map does not look like a map. I can handle that issue later. I just want to see all that crappy grain noise on the sphere so I can move forward.
Do I need to use a custom shader? Or do I need a different model?
Have you tried opening this in Blender? It's a great way to confirm if the UV coordinates specified in your model line up to the texture that your trying to use. If it's not going to render after it's imported in to Blender, it's highly likely you won't get it to Render in XNA without specifying the mapping yourself.

How to make a map editor in XNA

I have made a terrain that is generated from a height map file where each pixel (black to white) represent the height of the terrain at the corresponding location.
Now, my question is how would one make a map editor for something like that? I can think of two general ways:
1) The map editor modifies the height map file and regenerates the terrain based on that.
2) The map editor directly alters the vertices of the map, and later upon saving process it generates a height map based on those vertices.
Do you have any good tutorials or resources as to how to get either one to work? I have no idea where to begin.
Check out the XNA Terrain Editor by Eric Grossinger.
I've played around with this thing a little bit and it's pretty slick and should, at the very least, give you some ideas if not an out-right solution.
This book: Building XNA games is an excellent reference and has a great overview of how to create your map editor. The only downfall is it's in XNA 2.0 so you would have to do some converting, but the idea remains the same.

What is the best template to use in C# Visual Studio 2008 for a 2D game?

Is it WPF? WFA? A custom template?
I currently use WFA, and it just doesn't seem anywhere near optimal. And no, I'm not asking for a referral to DirectX, or another language.
Thanks.
Do you want it to be really 2D, or you you want a "2.5D" game where 3D objects move in 2D?
For most basic 2D, like turn-based games or simple animation where very fine human input control is not necessary, the System.Drawing tools used in a WFA will probably be fine. You have access to a lot of the tricks, like using small images as sprites, rendering vector graphics, as well as the must-have elementary shape-drawing functions. You can use Image objects like Bitmaps to simulate page-flipping (create a Bitmap, draw the shapes on it, then call Graphics.DrawImage()), or simply use SetRedraw(false) on the control you're using as the Graphics pane to freeze what's there while you're drawing the next window.
WPF has some tools that are a major leap forward. Look at the System.Windows.Media.Media3D namespace; it has tools for 3D vector algebra and geometric primitives, allowing you to create 2.5D games with vertex shading and all the tricks. The basic structs can be referenced and used for their mathematical power, or you can build a WPF application that will integrate them into a graphics pane. You'll have to research this yourself; I'm a lightwight with WPF.
If you want your game to really get some FPS, you're going to have to use an accelerated platform like DirectX. XNA Game Studio is a free .NET-compatible API that wraps a lot of the DirectX functionality, allowing you to create .NET apps with accelerated graphics without requiring messy native code hookups. Creating and running apps on just about any .NET-compatible platform (including Windows) is free; you have to pay a fee and join the "XBox Creator Network" to publish even free games for XBox 360.
XNA, and the Box2D.XNA physics engine if your game requires 2D collision detection and physics. XNA takes care of hiding all that crazy DirectX stuff from you. It has a great content pipeline, which lets you add content to your game very easily. My favorite framework for small games.

How to animate rotating cube in C#?

I would like to do something like this: a rotating cube on a form. I don't want to use any external library or dll, just pure .NET 3.5 (without directx). And a cube build with lines only. Could you please tell me how to do this?
I don't want to use external libraries because I don't need > 100 MB library to do this thing right? I want only to animate a rotating cube made with lines.
This is how you go about making a Cube in GDI+
C# 3D Drawing with GDI+ Euler Rotation
http://www.vcskicks.com/3d-graphics-improved.html
C# 3D-Drawing Cube with Shading
http://www.vcskicks.com/3d_gdiplus_drawing.html
Study assignment? This can be done with some simple 3D maths. You just need to understand the basics of matrix algebra, 3D transformations, and 3D->2D view transformation. The DirectX tutorial covers this, but you can google for it and you'll get plenty of other tutorials.
Added: Just to clarify - I'm not suggesting to use DirectX or anything. You can do this with standard System.Drawing tools. You just need to understand the math, and that's explained in the DirectX tutorials.
You might try using WPF and the 3D Tools source code released by the WPF team.
3DTools
Assuming you are using WPF for your GUI:
Make an animated PNG of the cube using a graphics program.
Use the APNG WPF Control to insert the image into your GUI.
This will yield a small assembly size and transparent background if needed.
You need a way to represent 3d points. There is no ready struct for that in .NET unless you use directx or WPF.
Then with a standard euler rotation matrix applied to the points you get the transformed points. If you only do rotations you can get away with 3x3 matrix, but if you want translation you better use 4x4 matrices and homogenous points.
After this you need a way to project those 3d points to the 2d canvas. Depending whether you are using perspective or orthographic projection the projection matrix will look a bit different.
Look into WPF in general, it will help you do this with a few measly lines of code. You can also host a WPF window in Forms.
http://msdn.microsoft.com/en-us/library/aa970268.aspx

Categories