Jump to content

  • Log In with Google      Sign In   
  • Create Account

Muzzy A

Member Since 25 May 2007
Offline Last Active Jun 04 2015 11:15 AM

#5200344 Adding a scrolling camera stuck with the maths

Posted by on 27 December 2014 - 06:03 PM

You can just add or subtract the camera's position


an object is at position

// Screen Coordinates
x = 300;
y = 300;

The camera's top left is at position

x = 200
y = 200

Picturing this in your head you can tell it should render at 100,100 on the screen



objX - camX = 100;
objY - camY = 100;

For input....

You clicked the screen at position

x = 100;
y = 200;

Cameras top left position

x = 200;
y = 200;
// Coordinates in the world would then be...

x = mouseX + camX; // 300
y = mouseY + camY; // 400
gridPos = worldIsoGrid( x,y,widthHalf,heightHalf);

#5199740 Programming a Level Editor

Posted by on 23 December 2014 - 01:36 PM

Having a level editor will make the creation of your levels go MUCH faster.  It will save you a lot of time to go out of the way to create the editor.  Making a 2D editor should take you no time at all. ( Assuming you're using C# Windows Forms for it )

#5197591 Ray/AABB Intersection Incorrect

Posted by on 11 December 2014 - 09:30 AM

Learn a little about AABB to Ray intersect instead of just copying the code.  It's not that difficult if you know vector math.  But there are other guides to help you.


Another topic about AABB to Line Segment ( has Ray to AABB code )

Video Explaining Ray to AABB ( No code, just the math side )

A little guide to creating Ray to AABB Checks ( Has code, gives a little bit of explanation for it too )



After you complete that, I would look into using OBB's instead of AABB's if your cube is going to be changing orientation.

#5195790 Shader always returns white

Posted by on 01 December 2014 - 04:38 PM



My graphics card doesn't support version 3.0 pixel shaders, had to use version 2.0.  I was looking up reasons why ID3DXEffect::ValidateTechnique() would fail and found a topic on here that led me to test the version I'm using.  3.0 works with the vertex shader however... I guess I better put it down to 2.0 just to be safe, just have to be careful with how many calculations I perform.


Before I made this topic I thought about changing those down to 2.0 to see if it worked... I should have done it, but I assumed this computer was new enough to be aware of version 3.0, assumptions can cause problems.  Lesson learned.

#5195652 Finding covered tiles of the brush

Posted by on 01 December 2014 - 02:27 AM

Not an expert on this or anything, but no one else has replied so I will put in my opinion =P



From what your saying it seems like I would personally do something like casting a ray from the camera and get the point of collision on the terrain from that ray.  Then create a vertical cylinder, rectangle, or whatever the shape will represent your brush the best, then test that geometric shape against the terrain to find all of the tiles that are either inside or colliding with the shape.


Hope this helps!

#5144409 DirectX 11 Drawing multiple instances of the same object

Posted by on 04 April 2014 - 12:39 PM

Well this Tutorial explains everything I need. Thanks for the post.

#5143109 A question about where to store the Camera!

Posted by on 29 March 2014 - 01:09 PM

Hi, I'm building my own little renderer and there's a couple things that I get undecided about.


Where exactly do most of you store things like the Camera and Projection matrix?

I've seen and tried several different ways of doing so, but I'm not satisfied by any of them.

  • Save it in the renderer, pass them as parameters to the render functions - Probably the best way, but I don't want Parameters!
  • Make a singleton for the camera ( HORRIBLE! ) to access it anytime.
  • Make a static variable in the render objects that holds a reference to the camera and projection matrix.


I'm just a little curious at how others would do this minor little thing.

#5123221 SIMD Function - Illegal instruction?

Posted by on 12 January 2014 - 11:59 PM

It doesn't support AVX. Thanks for making me double check.

#5097523 WT* ?

Posted by on 28 September 2013 - 06:37 PM

LOL this topic brightened my day.

#5097500 Circle vs Line Segment collision

Posted by on 28 September 2013 - 04:02 PM

struct Segment
    Vector3 start;
    Vector3 end;
struct Sphere
    Vector3 center;
    float fRadius;

This code will find the closest point to the sphere that is on the line segment.

Vector3 point = sphere.center;
// Get the direction of the line segment from start to end
Vector3 line = segment.end - segment.start;
float length = Math::Length(line); // The length of the line
line /= length; // Normalize
// The Vector from the center of the sphere to the start of the line seg
Vector3 toStart = segment.start - point;
// How far up the line the closest point is
float dist = Math::DotProduct(toStart,line);
// ensure that the closest point is on the line segment
if( dist < 0 )
dist = 0;
else if(dist > length)
dist = length;
// Calculate the closest point
ClosestPoint = segment.start + line * dist;

Now you have the closest point, just do a simple radius check

Vector3 toPoint = sphere.center - ClosestPoint;
// For optimization you can use the square distances
float dist = dot_product( toPoint,toPoint ); // Equivelant to LengthSqu()
if( dist <= sphere.fRadius*sphere.fRadius )
    // There is a collision

#5095040 Question about programming in team, and svn...

Posted by on 18 September 2013 - 04:10 PM

There is usually an Interface which tells you what lines of code were changed in a file.  You have to see where they made their changes and merge it with yours into one copy, and usually you can see what that final copy looks like as well.  It's not hard, you just have to be careful when doing it because you can easily leave out someone else's code by accident and they'll have to either redo it, or revert back.

#5094833 Calculus Vs Algebra based Physics

Posted by on 17 September 2013 - 10:02 PM

you don't really need to go to those classes, If you want to do a game just start learning DirectX or OpenGL and as you learn it by osmosis you just start making more and more complex things, and as you go you will find everything you need on the internet. Going to university(in programming) is more about meeting other people.

this actually depends on the person, some people learn much better when being taught the subject in person rather than reading it online.



Anyways assuming this is a standard physics class and not for game programming, yes I agree with Hodgens. Formulas used in programming are all usually derived from calculus, but look like simple Linear Algebra and are usually common and can be found online.  Linear Algebra is the only real thing you need to know. I would say Linear Algebra is a requirement for Game Programming, but that's just me.

#5084492 Box vs Plane Collision Detection

Posted by on 09 August 2013 - 03:28 PM

if it's an Axis Aligned box, things are easy, you can actually treat the center as a radius

struct Sphere { float m_Radius; Vector3 m_Center; };
struct AABB { Vector3 min,max; };
struct Plane { Vector3 normal; float offset; };
int SphereToPlaneCollision(const Plane& plane, const Sphere& sphere)
    float dot = dot_product(plane.normal,sphere.m_Center) - plane.offset;
    if(dot > sphere.m_Radius)
        return 1; // The sphere is in front of the plane
    else if(dot < -sphere.m_Radius)
        return 2; // The sphere is behind the plane
    return 3; // The sphere collides/straddles with the plane
int AabbToPlaneCollision(const Plane& plane, const AABB& aabb)
    // Get the Extense vector
    Vector3 E = (aabb.max - aabb.min)/2.0f;
    // Get the center of the Box
    Vector3 center = aabb.min + E;
    Vector3 N = plane.normal;
    // Dot Product between the plane normal and the center of the Axis Aligned Box
    // using absolute values
    float fRadius = abs(N.x*E.x) + abs(N.y*E.y) + abs(N.z*E.z);
    Sphere sphere;
    sphere.m_Center = center;
    sphere.m_Radius = fRadius;
    return SphereToPlaneCollision( plane,sphere );

#5082678 std::vector<> vs cli::array<>

Posted by on 03 August 2013 - 12:02 AM

The fact that it's managed makes me want to remove it from my computer =P


Thanks for the explanation. I probably wont be using any cli::arrays in the near future lol. I enjoy managing my own memory, I have an attachment to it.

#5079081 Orbit (ellipse) collision detection between many many objects

Posted by on 19 July 2013 - 09:48 PM

There's this thing called the KD Tree I think? It can get quite complex, but basically puts every object in to a list of AABB's and objects only check collision in the surrounding AABB's.


You can define the size of your AABB's yourself obviously. And there's no limit to how big you can make this tree, there's alot of overhead for it, but it's extremely useful when you have a large amount of objects like that.