Hi i am new to directx c#. i have a problem in one project. i draw two cubes which is one after another (ie x and y same location z is different), but the problem is when i view the front cube it is transparent and back cube is visible through front cube, i checked the transparency, no transparent level has been set. cullmode=null,Can anyone suggest what was the problem in tat?
And I think that the pixel of back cube overlaps with the front cube , how to overcome this?
here the screen shots..
Front Facing: http://postimg.org/image/6irstpv75/
Top View:http://postimg.org/image/o7ktw54h3/
Welcome :)
Please, consider adding tags to your post (programming language, "DirectX" etc) Without knowing which language you use (edit: c#... you should write it in tags... Soo, which framework? SharpDX? SlimDX? :)), i cannot be more specific.
Looks like you dont use DepthBuffer: you draw your distant cube first and closer cube after it, so it override existing pixels on BackBuffer.
Related
Since I don't have 10 reputation to post an image, I am going to leave a link of the game picture. http://thinkfun.com/mathcounts/play-rush-hour
This is what I want to create. A game where a rectangle must pass through other rectangles through the hole to win the game. The main rectangle can only move forward and other rectangles can move either right, left, up or down depending on their position. You must move the other rectangles in a way that they could make a way for the main rectangle to pass.
Here is my plan how I am going to create this game:
Create all the forms, import all the images and graphics to get ready to work with them.
Write code for 1 rectangle that would be able to move around.
Write an algorithm that wouldn't allow for rectangles to go through each other.
Make a winning hole.
Code other rectangles, make a full game.
Make fancy animations.
Import statistics : score, move counter and etc.
Here are my questions that I wanted to ask before trying to develop this game.
(Oh, and by the way, I am using Visual Studio C# form )
I assume that these rectangles are not going to be buttons, then what kind of a "button" (or whatever you call those extra features ) should I use?
How do I make a skin for those rectangles? So I can make it look like wood and make a nice skin for the main rectangle.
These are all my questions so far. I would like to know how to overcome those problems and I would like to hear some extra tips. Thank you very much for your time!
Use Graphics to draw your rectangles. Else make an object to hold info for it and you can import an Image as your "skin".
See number 1.
First off: Do you want to create a game or learn winForms? If the answer is create a game. Chose a Game Engine (Unity is nice, and uses c#) and work with that instead.
If you want to learn winForms you'd probably want a PictureBox, then add your code your code in OnMouseUp, OnMouseDown, etc. Good luck :)
I'm currently working on a project where I have a character walking in front of a projector screen. Like the one you see in classrooms. I also have a projector which is projecting an image onto it using the Projector component.
Now my question: I know how to have the image projected on my character, but I was wondering if it's possible to do this more realistically, because now it's more of an on-off type situation. I kind of want the image to change on the character as it walks in front of the projection.
Is this possible? And if it is, how?
It is possible!
Turns out I had my projector shader set to diffuse, so it just slammed the texture on everything it hit. I set that to Projector/light and it got better.
After that I set the texture itself to clamp instead of multiply at it's own settings. That fixed the multiply problem.
Last thing was to edit the image to have a white border around it, because it was repeating the edges. Now it's perfect!
Hope this helps anyone searching this.
I am making a WPF program with the possibility to modify data graphically in 3D. In order to give the user the option to select multiple graphical objects at the same time, I want to implement a selection rectangle. (Just like the one in windows explorer.) A common functionality in programs like this one is to have 2 different functions for the selection rectangle, and that the user can somehow choose which of the methods should be used.
Any object that is partially or completely inside the rectangle is selected.
Only objects that are completely inside the rectangle are selected.
The 2nd method is straight forward by using the bounding box of each object, and check if it is inside the rectangle. The 1st one on the other hand, seems to be quite some work. All my graphical objects are complicated 3D figures, and can be rotated by the user in any way. At the moment I am unable to find any other way than checking if any of the triangles in the mesh of any of the objects cross my 2D rectangle, and that can be quite time consuming.
I have little experience with WPF 3D, but I have done this before in OpenGL. Then I could tell OpenGL to draw a specific area of the screen, and the collect a list of objects that was visible in the specific area. All I needed to get the functionality I wanted was about 5 lines of code.
I guess my question is this:
Is there a way to do this with WPF 3D, similar to the OpenGL approach?
If not, is there any other smart way to find all objects (Visual3D) in a viewport that is partially behind a 2D rectangle?
I refuse to believe I am the only one with this kind of problem, so I hope a clever mind can point me in the right direction.
Regards,
Sverre
Thank you for your answer!
The 2D-rectangle is just in front of the camera and extending infinitely forward. I want to get any object that is partially or completely inside that frustum.
The camera we are using is an orthographic or perspective projection camera (System.Windows.Media.Media3D.ProjectionCamera). The reason we are not using the matrix camera is that we are using a 3rd party tool that does not support the matrix camera. But I am sure there is a way to get the matrix from a projection camera as well, so that is hopefully not the problem.
In theory your solution sounds like just what we need, but I am not sure how to proceed. Do you have any links to sample-code, or can you give some more hints on how to actually implement this?
Btw: Since we are working with WPF, we do not have direct access to DirectX. At least that’s what we have concluded after some research. You mention use of the z-buffer, which we haven’t been able to access through WPF. If you know a way to access the z-buffer, it’s greatly appreciated! This is of-topic, but we have struggled to disable the z-buffer for some time, but have given up…
Best regards,
Sverre
Is your intersection region a 2d rectangle or a frustrum based at a 2d rectangle and extending infinitely forward (or perhaps to some clipping limit)? If it can be construed as a viewing frustrum, then you can leverage the existing capabilities of the graphics system to render the scene using a Camera View and Projection that corresponds to your originating rectangle, with all lighting and shading disabled and colors chosen specifically to 'tag' the different objects in your scene. This means you can use the graphics hardware to perform the clipping/projection as a 'rendering' operation, then simply enumerate the pixel values as 'tags' to determine the objects present in the rectangular view.
If you need to restrict selection to an actual 2d slice (or a very shallow frustrum), you can use the Z-buffer (if you can get access to it) to exclude tagged pixels that are outside the Z range of your desired selection frustrum.
The nice thing about this approach is that you probably already have the Camera matrix (it's the same matrix used for your window for selection) and only need to change the Projection matrix to be a sub-set of the viewing window.
A 'smart' way would be to transform the rectangle into a box using the Camera's matrix
And then do a intersection of all the objects and the box.
Here's the setup: This is for an ecommerce art site where some paintings are canvas transfers. The painting wraps around the sides and top and bottom of the canvas. We have high-res images of the entire painting, but what we want to display is a quasi-3D representation of the image in which you can see how the sides of the painting wrap around the canvas. Here's a rough sketch of what I'm talking about:
My question is, how can I rotate an image in 3D space? The approach I think I'd like to take, is to cut off a portion of the top and side of the image, and rotate then in 3D and then stich it back on to the top and side to give it the 3D look. How do I go about about doing that? It can be done using any .Net technology (GDI+, WPF etc.).
In WPF using the ViewPort3D class you can create a cuboid which is 8x5x1 units. Create the image as a texture and then apply the texture to the front face (8x5) and the side faces (5x1) and the top and bottom faces (8x1) using texture coordinates. The front face coordinates should be: (1/9, 1/6), (8/9, 1/6), (1/9, 5/6) and (8/9, 5/6) for the front face, and from the nearest edge to those coordinates for the sides, e.g. for the left side: (0, 1/6), (1/9, 1/6), (0, 5/6) and (1/9, 5/6) for the left side.
Edit:
If you then want to be able to perform rotations on the 3D canvas model you can follow the advice here:
How can I do 3D transformation in WPF?
It looks like you're not needing to do real 3D, but only needing to fake it.
Chop off four strips along the top, bottom, left and right of the image. Toss the bottom and right (going by your sketch in the question). Scale and shear the strips (I'm not expert enough at .net/wpf to know how, but it can do it). The top would be scaled vertically by a factor of 0.5 (a guess - choose to fit the desired final 3D-looking image) and sheared horizontally. The result is composited onto the output image as the top side of the canvas. The left strip would be scaled horizontally and sheared vertically.
If the end user is to view the 3D canvas from different angles interactively, this method is probably faster than rendering an honest 3D model, which would have to do texture mapping and rasterizing the model into a final image, which amounts to doing the same math. The fun part is figuring out how to adjust the scaling and shearing parameters.
This page might be educational: http://www.idomaths.com/linear_transformation.php
and this could be useful reference http://en.csharp-online.net/GDIplus_Graphics_Transformation%E2%80%94Image_Transformation
I dont have any experience in this kind of stuff. But when i saw this question, the first thing comes to my mind is the funny Unicornify for SO.
In this making of article by balpha, he explained how the 2d unicorn sphere is rotated in 3d space.
But the code is written in python. If you are interested, you can take a look into that. But am not exactly sure this would help you.
The brute force approach (which might be the easiest approach), is to map the u,v texture coordinates for each of the three faces, onto three billboards representing three sides of the canvas (a billboard is just two triangles that make a rectangle). Then, rotate the whole canvas (all three billboards) using matrix transforms. Tada!
Alternately, you can move the 3-space camera position with a transform, rather than the canvas. Six of one, half the other - as they say.
HI all,
I'm developing a software to control light show ( through DMX protocol ), i use C# and wpf to develop my main software (.net 4.0)
To help people preview their show, i would like to make a live 3D visualizer...
First, i thought that i could use wpf 3D to make the visualizer, but i need to work with light ..
My main application should send property ( beam angle, orientation (X,Y), position(X,Y), Brush ( color,shape,effect)) to the 3D visualizer
But i would like to be able to move light (position in the scene) by mouse during execution and had value in return...
So ..
Does XNA is the easiest way to doing that ?
Can you help me for that :
Generating light (orientation , bitmap like filter in front of light )
Dynamically moving object with mouse and get position in return
Dynamically add or remove fixture
All of your advice, sample, example are very welcome ... I don't espect to have a perfect result at the first time but i need to understand the main concepts for doing that
Thank You !!
XNA does not contain any functionality for managing a "scene" - you will have to implement that yourself. For example: you might make a Light class containing the information about your light (position, orientation, etc), and then have a List<Light> of them, which you update and render yourself.
I will now assume that you have a 3D model of a "Light" (as in: the metal box containing the lightbulb) and also a 3D model of a stage. And that you can figure out how to render them - there are plenty of tutorials online for simple model rendering in XNA. Here is a starting point.
So your 3rd requirement ("Dynamically add or remove fixture") should be fairly simple once you can render things. Just add and remove Lights from your List of them based on user input. See the Input namespace.
And your 2nd requirement ("Dynamically moving object with mouse and get position in return") should also be simple. If you want your user to move lights by clicking and dragging, just keep track of the mouse position between frames and apply that as an adjustment to the clicked Light's position (or rotation).
To figure out which Light the user clicks in the first place, a good starting point is the Picking Sample.
I am assuming here that the user will click the Light (metal box) itself to move/rotate it. If you would rather have the user click and drag the endpoint of the light (the spot it projects) - that is more difficult. One idea that comes to mind: Intersect a ray from your Light with the stage to find the centre of the projected spot. At that point draw a dummy "handle" object (like a sphere) that the user can click and drag around. When the user finishes dragging, figure out the new orientation for the Light to make that the new centre.
Finally your 1st requirement ("Generating light (orientation , bitmap like filter in front of light )") is the tricky one. My understanding of this is that you want a way to draw the endpoint of the beam of light on your stage model? If so, what you are looking for is called Projective Texture Mapping. Presumably you will have a circular texture for basic lights, and perhaps other textures for gobos.
The quick-and-dirty way to do this would be to draw your stage model, once for each light, with additive blending (so that each light added with the other lights and the black had no effect), with a colour set to whatever you want the light colour to be, and with a black and white texture (a white circle on black background) drawn with TextureAddressMode.Clamp, with a shader that draws the texture with projective texture mapping which is set up with the light as the projection point.