Im trying to write a small application that makes isometric shapes. Ive been able to make
a cube / cuboid shape in the picture, but i need to be able to fill in the face of the cubes.
http://peterfleming.net84.net/cube.PNG
I used a drawLine method and mapped points but i was hoping there was an easier, perhaps a drawRectangle method that i could use instead and then fill them in, but so far i havent been able to find any, perhaps because of the isometric nature of the shape.
Any help would be appreciated
What you're after can be easily done with the Polygon class.
Related
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.
So I'm making a simple 2D Sidescrolling game in C# however I've found that using Graphics.drawImage doesn't particularly allow me to update the tiles as I wish. For example, I tell it to draw the image and it stays where I tell it to be. I want to be able to move the entire scene left to right. This would be easier if I had to use a for loop or something and define it's position every time it draws the image.
This may be confusing and I'm certain there's a way of doing it, I just don't know how.
So my question to you is: How can I control the positioning of each rectangle drew on a form so that I can scroll the entire scene to the left when I wish?
I'm certainly no game/graphics expert, so take this with a grain of salt.
A couple things spring to mind.
First, you could pre-render the entire level as one bitmap, then just paint the relevent portion into your picturebox.
Second, the Graphics class has a Transforms property (I may have the name wrong). You could add a linear transformation to the graphics object so the painting coordinates of your tiles wouldnt change, but the graphics object would slide, or I think the graphics term is "translate" the output en-masse.
I'm making a game in C# and XNA, and I was trying to come up with a method to render massive terrains without using a tremendous amount of memory or passing the poly limit hard-coded into XNA.
My solution so far is to create a massive heightmap, and that heightmap is loaded into memory at the beginning of the game in the initialization phase. Then, terrain is only generated nearest to the camera. This is accomplished by projecting a triangle whose vertex is the character and the other two endpoints extend to the sides of the character's viewing area. Then, all the pixels inside that triangle on the heightmap are rendered and drawn into the game, thus only rendering what is seen.
The problem is, I've successfully found (I think, can't test until I get terrain rendering) the three vertices of the triangle. Now I need to find a list of the coordinates for every single pixel inside that triangle - whole numbers only, because I just need a list of pixels to render.
I know it sounds a little confusing, so here's the gist of it:
I have an image, and I project a triangle onto that image. The only thing I know about that triangle are the three vertices. I need a list of the pixels inside that triangle.
I've been Googling around for maybe 20 minutes now, and I figured I midas well go ahead and post something here due to the fact that what I'm trying to do isn't all that common. If I find an answer, I'll be sure to post it here.
But until then, can anyone tell me how to accomplish this?
Edit: A formula, please. If you can provide a formula or algorithm, and an explanation, that would be just perfect.
Edit: I've posted a new question, as I've ditched this method of rendering large terrains. The question is here.
Start here:
http://mathworld.wolfram.com/TriangleInterior.html
One of the non-trivial problems, not mentioned there, that you have to deal with is the pixelization along the boundary.
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.
I'm making a Tetris Clone in C# with XNA, and I'm unsure of how to actually implement the blocks.
I don't think that making the shapes as images will work (because parts are removed when lines are formed), so I Have blocks to make up the pieces like This.
Unfortunately, I don't know how to actually define the blocks to make the pieces, nor do I know how to manipulate them to make them rotate, etc.
Edit: I would also need assistance in learning how to make the Tetris Grid too.
I haven't created tetris before, but after some thinking, I believe that I would use a simple matrix to create my pieces. For example, your whole game board would be one big matrix. A subset of that matrix, say a 4x4 block of it, would be a game piece. Which parts of that 4x4 block would be filled would be determined by which particular piece you want to create. Each part of the matrix can have a boolean flag that would indicate if it's filled or not. This is a very simplistic view of it, but I think it's a viable solution.
Use a boolean matrix to model the state of the screen. Each piece is itself another smaller boolean matrix.
Rotating a piece is as simple as playing with the coordinates a little bit (I left this to you).
About how to render, just draw a piece tile for each true value in your matrix ored with the current falling piece shifted and rotated.
For the blocks, I would strongly suggest working in 3D. You can still make the game look like 2D by locking the camera etc, but you will benefit a lot from working in vector graphics. Your blocks will be simple cubes (flat or with some depth) that you rotate and move around the screen.
For the grid, look at #fortran's and #aaron's answers, a boolean matrix will do the trick.
Maybe this link to Coding4Fun will help. It's in german, but you should be able to get the source code and take a look on how about the problem is solved here.
Just to be sure, here the direct download link.