Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!

Gavin Williams

Member Since 04 Dec 2010
Offline Last Active May 28 2015 05:40 AM

#5200693 Still a little confused about changing structs

Posted by Gavin Williams on 29 December 2014 - 06:48 PM



I'm still a bit confused about structs being copied when they are modified. I have a ray class, with two vectors ...


    public class Ray
        public Vector3 Origin { get; set; }
        public Vector3 Direction { get; set; }

        public Ray(Vector3 origin, Vector3 direction)
            Origin = origin;

            Direction = direction;

            /* this doesn't work*/
            //Direction = direction;

What I don't get is why direction.Normalize() modifies direction, but Direction.Normalize() doesn't modify Direction.

Edit : My running theory, is that after Normalize is called, both direction and Direction are copies local to the constructor, and in the first case, it is actually assigned to the global, but in the second, it is left unused.

#5197439 Game Entity object graph serialization

Posted by Gavin Williams on 10 December 2014 - 01:27 PM

Binary is simple and effective for saving game-state.

#5197437 Want to become a Computer Scientist

Posted by Gavin Williams on 10 December 2014 - 01:24 PM

@Olof Hedman - no but it's damn hard. Most people who start a degree will not reach master or doctorate level. It does take unusual commitment.

#5196427 Please give me some lectures for directx programming

Posted by Gavin Williams on 05 December 2014 - 06:39 AM

There are a couple of books you could get ...

Introduction to 3D Game Programming with DirectX 11 - Frank D. Luna

Practical Rendering and Computation with Direct 3D 11 - Jason Z. Matt P. Jack H.

There is also a commonly referenced website:




Direct X is a pretty huge topic, just asking for 'advice' on using it is almost like asking for advice on programming. What do you want people to say?

Here's some advice ... it's really great, very interesting, powerful, but difficult at times. You will need to spend A LOT of time learning it, and much more mastering it. Read Books, read websites & blogs on rendering topics and techniques, look at sample code. Start with creating your device, then render a triangle, then a cube, then get your cube to rotate. Texture it. Add lights. Learn High Level Shader Language - that's a must! HLSL is awsome but it can be difficult to debug and get working. Learn to use Graphics Diagnostics in VS. Beyond that any advice is going to start getting pretty specific. Good luck.

#5195650 how to create gui buttons with DirectX 11?

Posted by Gavin Williams on 01 December 2014 - 02:04 AM

If you have SpriteBatch available, you can use that ...

            if (srvNormal == null) // then render a simple text button
                // set viewport - sprite batch uses full viewport
                Viewport windowViewport = new Viewport(0, 0, UI.Window.ClientSize.Width, UI.Window.ClientSize.Height);

                // render background
                if (State == States.Down)
                    SpriteBatchDraw.DrawSolidRectangleAA(new RectangleF(absRegion.X + 2, absRegion.Y + 2, absRegion.Width - 4, absRegion.Height - 4), Color.White);
                    SpriteBatchDraw.DrawSolidRectangleAA(new RectangleF(absRegion.X + 5, absRegion.Y + 5, absRegion.Width - 10, absRegion.Height - 10), Color.Black);

                     // cost [3949-5037 ticks]
                    RenderTarget renderTarget2D = UI.Window.RenderTarget2d;
                    renderTarget2D.Transform = Matrix.Scaling((absRegion.Width - 4) / (float)absRegion.Width) * Matrix.Translation(2, 2, 0);
                    renderTarget2D.DrawText(Text, TextFormat, new RectangleF(absRegion.X, absRegion.Y, absRegion.Width, absRegion.Height), Brush);

If you don't have a SpriteBatch facility, then you're right, you can use screen co-ordinates.

#5195629 I am all prepared to get into game development, how do I start then?

Posted by Gavin Williams on 30 November 2014 - 11:43 PM


They only support the respective programming language in their name,

That used to be true, as of.. think its 2013, maybe 2012, either way they changed it. One install for all three languages.

are generally limited in their functionality and not allowed for use in commercial projects

They are almost completely fully featured, there are only a few things that you can't do with express that you can with the paid versions. Also I don't know where you read that but as far as I know you can use them for commercial projects just fine.

As for the OP, I highly recommend Visual studio 2013 express edition(desktop, since I doubt you want to write those silly windows store apps.)



In regards to your suggestion that store apps are silly, I don't think this is good advice at all to give someone starting today. They will take what you are saying to heart, and it's bad information to be bandying around. WinRT, with which store apps are built with is being lined up as the successor to Win32. As of next year, with the coming of Windows 10, WinRT apps will have equal billing on the desktop by the expansion of their windowing options, ie non-docked / snapped & desktop integration. WinRT is not a silly little toy cooked up to appease the mobile crowd only. Yes, it targets mobile very well, but the WinRT / XAML stack and the language projections provide a powerful system that will be just as effective for desktop application in the next generation of Windows. Arguably, it will be preferable to using traditional technologies as it is fleshed out.

I have worked with WinRT a little, and I completely believe that there will come a time, when it doesn't make sense to use Win32 and the traditional desktop model any more.

And with the availability of Community Edition, I would choose that over express from now on.

#5194523 real time reflections from arbitory surfaces.

Posted by Gavin Williams on 24 November 2014 - 07:36 PM

You need to ask a question please.

#5164924 Exporting non-indexed vertex data from 3DSMAx

Posted by Gavin Williams on 05 July 2014 - 01:33 PM

I think the answer is to write a custom exporter using MAXScript, which I'm trying to do now.

#5150015 limit on the how many bytes that can be passed across shaders

Posted by Gavin Williams on 27 April 2014 - 09:12 PM

Have a look here for the limits:




So, the register limit looks to be 32 for shader inputs/outputs. You are creating 4x3x3+2 = 38 registers. So even with your a 'fix' for the alignment / padding, you will still be breaching the register limit. You will need another solution.


Edit: I agree with spazzarama below. I took a second look at it.

#5149750 ReportLiveObjects() isn't giving me enough information.

Posted by Gavin Williams on 26 April 2014 - 07:17 PM

Ok, so something I have never realized, is that a second (debug) device needs to be created in order to use reporting.

device3DDebug = new DeviceDebug(Device3D);



Gives the proper output. Thanks Mona2000


Edit: Some useful references




#5144921 change 1D addres to 2D addres

Posted by Gavin Williams on 07 April 2014 - 12:14 AM

Do you expect someone to have a faster method ? Do you have a performance issue with this code ?

If you are stressing over optimizations with code like this, I'll be surprised if you ever get anything done, really!

Just write your code, there is nothing wrong with your code unless you know there is something wrong. Especially this code, it's about as simple as it gets. There are a couple of ways to do it, but they boil down to the same thing, a few ops, which is totally not worth worrying about.

Come back when you have a function that's taking 10,000 ticks to complete, then we can talk about optimization.

#5127720 AMD's Mantle API

Posted by Gavin Williams on 31 January 2014 - 07:24 AM

Wow, the first I heard of Mantle was seeing an anouncement today that Battlefield 4 supports it as an alternative to DX with the 14.1 beta drivers. Here's a link to the BF4 page with performance comparisions ..



#5117530 Collision problem

Posted by Gavin Williams on 17 December 2013 - 04:24 AM

Are you a machine ? You've collided with human beings in a public forum and banged square up against their strange habits of communicating in words.


Hello, what is your code and model number. We can exchange code in your native language. What will we make ? Physics, excellent. Do we understand one another ?

#5084178 Test for a range not being covered by a list of ranges.

Posted by Gavin Williams on 08 August 2013 - 11:19 AM

I just want to mention an immensely useful article by Eric Lippert http://blogs.msdn.com/b/ericlippert/archive/tags/shadowcasting/ which helped me get a grasp of the traditional way to compute visibility.

#5081615 Please help me get started

Posted by Gavin Williams on 29 July 2013 - 10:33 PM



I've sent through the solution, I've included a few details in the email, and removed a couple of things from the project that would cause a crash. If you have any question, just put them up here, as I don't check my email that often.


In regards to smooth animation and smooth frame-rate. It's almost impossible to get a consistent frame-rate, so the best strategy is to accept that every frame is going to last a different amount of time and write your physics to accommodate different frame times. As you'll see in my solution I use inter-op in the Clock class to access the performance counter. This gives me the highest accuracy reading of elapsed time over the frame. This is not the only way to measure frame-time but it's the way i do it. I then use that time to scale the velocity. So a short frame will result in a shorter movement over the frame while a longer frame will result in greater movement. So over many frames, you're objects do move smoothly.