I had an issue with my new renderer on opengles 2.0
Turns out it's an obscure shader problem
Turns out it's an obscure shader problem
The home of Stainless |
|
22 Comments
At some time we all end up writing some kind of level editor, and one of the issues is moving objects around the scene. 3D editors get around this by having multiple views so you can move the object in the cardinal directions, this isn't always ideal. My solution relies on the objects being on a defined plane, but it can be extended to handle uneven terrain. The idea is simple, and the code not much more complex. Throw a ray from the mouse position through the scene. You are probably already doing this for your picking. Find the intersection of this ray and the plane. Place your object there. Simples. In fact I do it a little differently, I add the difference between the object intersection and the new, but that is a triviality. The advantage of this is that it is view independant, so if you move the camera, the code still works. //Intersection plane Plane p = new Plane(Vector3.UnitY, 0); // new mouse ray Ray nmray = CalculateCursorRay(mpos, editCamera.Projection, editCamera.View); Ray omray = CalculateCursorRay(ompos, editCamera.Projection, editCamera.View); // find the old and new intersection points float? op = omray.Intersects(p); float? np = nmray.Intersects(p); if ((op != null) && (np != null)) { Vector3 opos = omray.Position + (float)op * omray.Direction; Vector3 npos = nmray.Position + (float)np * nmray.Direction; npos -= opos; SelectedObject.Position += npos; } ompos = mpos; The cursor ray calculation is standard, but it is here for reference private Ray CalculateCursorRay(Vector2 mpos, Matrix projectionMatrix, Matrix viewMatrix) { // create 2 positions in screenspace using the cursor // position. 0 is as close as possible to the camera, // 1 is as far away as possible. Vector3 nearSource = new Vector3(mpos, 0f); Vector3 farSource = new Vector3(mpos, 1f); // use Viewport.Unproject to tell what those two screen // space positions would be in world space. we'll need // the projection matrix and view matrix, which we have // We also need a world matrix, which can just be identity. Vector3 nearPoint = GraphicsDevice.Viewport.Unproject(nearSource, ProjectionMatrix, viewMatrix, Matrix.Identity); Vector3 farPoint = GraphicsDevice.Viewport.Unproject(farSource, ProjectionMatrix, viewMatrix, Matrix.Identity); // find the direction vector that goes from the nearPoint // to the farPoint and normalize it.... Vector3 direction = farPoint - nearPoint; direction.Normalize(); // and then create a new ray using nearPoint as the // source. return new Ray(nearPoint, direction); } This is a very simple piece of code, but the number of times I see people
struggling with it, I thought it was a good idea to blog it for other people to reference. Like a lot of people, I grabbed a copy of Modern Warfare 2 as soon as it came out.
However I was very disappointed when I actually came to play it, don't get me wrong, it's a good game, just not great. My main issues with the entire stable come down to three things. 1) Location based logic. The entire stable is based on a location based design. When you get to location A, bad guys start spawning from location B. To stop them, get to location C. Now this is fine as far as it goes, but it goes horrendously wrong if the level designers aren't careful. I remember one spot that was used as a spawn point for bad guys. It was about five feet square, prisoners in Broadmarsh have more room, yet this magic little room had the ability to generate an infinite number of hostile, armed, individuals.In this day and age it is not difficult to model troop behaviour, and it should have been done. 2) Vision system. The bad guys have unbelievably good vision. You can crawl along behind a wall, at night, in the middle of a fire fight. Pop your head out at the end, and have it blown off in 20mS. Just rubbish. 3) Network code. Most people buy this game for the multiplayer game. However it has always had problems with the network code. You can creep up behind a bad guy, aim carefully at the back of his head, fire away until your clip is empty without hitting him once. Then he turns around and kills you with a single shot. Annoying? response deleted I was really hoping that in the new version they had addressed this problem, but it's still there. Along with a brand new one. The lobby code is truely awful. Getting into a game can be an exercise in futility, with orphan lobbies that don't really exist in abundance. I have even quit out of a game because the network connection was too laggy, then find game put me in a lobby with all the same people in it as the game I had just quit, on a different map. I could even hear them playing the game! Naturally thirty seconds later I got the all too common "Game lobby closed" message. Now for me, if I was in charge of QA for the developers, this would be a straight fail. Cancel the release date, we cannot ship this, I don't care if you have paid for the advertising. This got me thinking, which as most of my friends can tell you is dangerous. I had a look through my library of games looking for one that I could say was complete. I couldn't find one. Every single game in my collection has got problems. They vary from hands up, no arguments, bug's, to bad game design, but every single one of them has at least one problem. A few quick examples. Tiger Woods. You have the ability to spin the ball while it is in the air. So you look at the flight of the ball and make a decision on which way you want to spin the ball. However at several points in the game, they move the sodding camera so you cannot see where the ball is going. WHY! Fifa 2009-2010 They have added a new game mode where you play a single player in the team. Hardly original, have a look at player manager circa 1990. The camera and display in this mode is unacceptably bad. On a bright sunny day you cannot tell a player wearing all white from a player wearing all black! All Square Enix games. LET US SAVE THE F(*(*()ING GAME WHEN WE WANT TO! I could go on for pages. So, what has gone wrong? QA has always been the shallow end of the computing gene pool. Testers are the lowest paid members of a development house, but that doesn't mean you have to employ muppets. I have had some really great games testers in the past. One guy sent me a bug report many years ago which listed five keys to hold down with your left hand. Five keys to hold down with your right hand. And instructions to then press the space bar with your nose. The game crashed. The bug fix was "don't do it", but several thousand out of ten for finding it. So it probably isn't the testers. One other problem we always had was the way advertising works. To place an advert in a computer magazine can cost huge amounts of money. A friend of mine, Mel, described it as "Think of a number, double it, add your phone number, and print it on a rate card. 'hick'". The effectiveness of an advert is measured in days. So if the advertising goes out before the game is ready, it is seen as a huge waste of money. Now programmers amongst you would see that as "wait until the game is ready before putting out the advertising", but it doesn't work that way. It really works as "we have paid for the advertising, so the game is going out" In fact in one game, that must remain nameless, it was advertised as having one hundred levels. When it came time to master it, they couldn't fit all of the levels in the game. The programmers wanted extra time to compress the levels so that they could get them all in. No. Just make level 99 impossible to finish. However I don't think it's that either. What I think the problem is, is the industrial nature of games coding now. In my day a game team was two or three people. So they got really involved in the game. It was theirs. Now we have teams of hundreds. I know one guy who has spent his whole career just writing particle systems. It would drive me insane! Hence they have no emotional attachment to the game. My school motto was "Good enough isn't good enough", I think the games industry's motto should be... It's only a game. |