Jump to content

  • Log In with Google      Sign In   
  • Create Account

Gavin Williams

Member Since 04 Dec 2010
Offline Last Active May 19 2016 02:54 AM

#5250026 Please help me fix my Mono class.

Posted by Gavin Williams on 31 August 2015 - 07:05 PM

If you are talking about the box that you are dragging with the mouse there are a couple of ways you can assign it's velocity. And you can also just use it's offset directly as you say.

If you use the offset between the last and new positions then you are skipping the velocity step for that object (and that's ok), by plugging the displacement vector of the mouse-driven object directly into the problem, you don't have to worry about the velocity, it's inherent to the movement. And you can just compute the displacement vector of the other object, from it's velocity (0 if it's stationary). It's then a geometric problem alone. But the velocity is actually v = s / t (where v = velocity, s = displacement, t = time). In this case you may still need to compute the velocity of the mouse-driven object if you want any kind of inertial response. But you don't have to if you're not worrying about inertia. 

Another way that I've seen mouse movement done, such as in Farseer Physics is to use springs. So a spring between the mouse and the object is set up and it can be set to be quite rigid, then the object will fly to the mouse position as though it were tied to it with a tight rubber band. In this system, the mouse-driven object's velocity is used normally by the physics engine. And it looks just like any other object in the system. But it's movement will not fit to the mouse-movement curve quite as tightly. But it is an effective technique.

#5249871 Please help me fix my Mono class.

Posted by Gavin Williams on 31 August 2015 - 06:57 AM

You haven't implemented continuous collision detection as was recommended to you in your previous post 

I can see that you're moving in the right direction with using Minkowski sums. But you are still doing discrete collision detection :


With regard to colliding two non-rotating axis aligned boxes, you construct the Minkowski sum in order to simplify the collision system of the two boxes, transforming the system to one containing a box and a point. You should also transform the velocities to make the the Minkowski sum the stationary object, and the point the moving object. This is a 'relative frame of reference' in order to simplify the problem to a line-box intersection test. 

Look into swept volumes as phil_t recommended, in the previous thread.

Edit : You're CheckMinkowskiSum method is actually not representative of the way Minkowski sums are used in continuous collision detection.

#5248192 Moving from Xna4 to MonoGame 3.4

Posted by Gavin Williams on 22 August 2015 - 03:25 AM

1. I haven't used XNA for a long time, but I worked with mono-game a while back and it looks almost identical to XNA as i remember. There is the namespace Microsoft.Xna.Framework.Content and it's all loaded as you would expect with content.Load<type>(). I don't know about custom content, I would guess that it's exactly the same situation as with XNA.

2.XNA and monogame provide their own input system : Microsoft.Xna.Framework.Input, which is what i used. But if you prefer to consume windows messages, then it should definitely work ok with monogame. XNA to monogame is pretty much a direct mapping.

#5246634 DirectX Camera Jitter

Posted by Gavin Williams on 14 August 2015 - 10:32 PM

You shouldn't be scaling mouse movement by the time delta. Mouse movement should have a direct mapping to rotation. These lines:


XMMATRIX xRotation = XMMatrixRotationY(((float)-deltaX  * (float)timer.Delta()));
XMMATRIX yRotation = XMMatrixRotationX(((float)-deltaY * (float)timer.Delta()));

This is wrong. You're camera movement should be tied to the frame-time just like all movement. Otherwize, a 30 fps game would result in a more sluggish camera rotation compared to when it was running at 60 fps. 

In any case, it doesn't explain the issue.


Edit : Unless of course, you're not taking input snapshots per frame, but rather updating input at a frame-independent rate, such as by directly pushing windows msgs into your engine.

#5233478 Texturing a Minecraft-style cube

Posted by Gavin Williams on 07 June 2015 - 10:18 PM

An alternative to using a texture atlas is to use a texture array to store all your cube faces. In order to use the texture array in your shader you'll include an additional texture index in your vertices, so all vertices on one face will share the same texture index.

Texture arrays don't have the edge issues that an atlas can have. I've found arrays useful for cube face textures, walls and tile based terrain, as well as for sprites (where the sprites are the same size).

#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