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!


Member Since 14 May 2012
Offline Last Active May 22 2014 06:19 PM

Topics I've Started

help computing positions of points

10 February 2014 - 07:14 PM

I've been trying to figure out a solution for this math problem. It might be simple, it might be impossible. I don't know because I am still very inexperienced in this domain.
I will be referring to this drawing:
The Problem:
This drawing depicts two rectangles lying on the x-z plane. Think of it like you are looking at them top-down (down the -y axis). The black points (H, I, and J) are given as input. The width of the rectangle is always 4. I need to compute the positions of each green point (A through G).
My Partial Solution:
Computing points D through G is easy: 
vec3 forward = normalize(I-J); // direction from J to I
vec3 right = cross(forward, vec3(0,1,0)); // direction from F to G
G = J + (right * 2); // 2 = width/2
F = J - (right * 2);

I can use the same formula to compute D and E.


Where I Need Help:
I don't know how to compute A, B or C! 
Any help or advice is greatly appreciated!

[solved]Help with my ray picker

29 January 2013 - 09:01 AM

Hey guys I'm trying to implement a simple ray picker in Opengl. In my little scene I have a green house that I would like to detect when the user clicks it. I am drawing the rays to the screen so I can debug them, so please have a look at these screenshots:
The red lines are the rays I have cast. The places I clicked are in the first screenshot on the outer endpoints of each ray. The problem is this projection to the far plane does not give accurate results if my goal is to determine if the user clicked the house or not. Should I be orthogonally projecting the rays from their origins? What can I do to fix this? Here is my code:
	Ray computePickingRay(int x, int y)
		glm::mat4 viewProj = projectionMatrix * camera->getViewMatrix();
		glm::mat4 invViewProj = glm::inverse(viewProj);
		int sx = gScreenWidth / 2;
		int sy = gScreenHeight / 2;
		glm::vec4 inV;
		inV.x = 1.0f * (x - sx) / (1.0f*sx);
		inV.y = 1.0f * ((gScreenHeight - y) - sy) / (1.0f * sy);
		inV.z = -1.0f;
		inV.w = 1.0f;
		glm::vec4 nearPlane = invViewProj * inV;
		inV.z = 1.0f;
		glm::vec4 farPlane = invViewProj * inV;
		glm::vec4 dir = (farPlane - nearPlane);
		Ray ray;
		ray.origin = vec3(nearPlane.x/nearPlane.w, nearPlane.y/nearPlane.w, nearPlane.z/nearPlane.w);
		ray.direction = glm::normalize(-vec3(dir.x/dir.w, dir.y/dir.w,dir.z/dir.w));
		return ray;



Terrain not lighting correctly

19 October 2012 - 09:42 AM

Hey guys I have been following the terrain tutorials on Rastertek.com. I'm on Tutorial #3 http://www.rastertek.com/tertut03.html where he teaches how to add basic lighting to terrain. What I have been doing is following his code examples and putting it into my code base which is basically the same as his but slightly more compact. Right Now I have a terrain class named TerrainComponent.cpp and it handles loading the terrain from a heightmap, creating the pixel and vertex shaders for the terrain, and rendering it.The problem is that my terrain is coming out completely white with no lighting at all! Here is a solid and a wire frame screenshot of my terrain:

Posted Image

Posted Image

Here is the screenshot from Rastertek's tutorial:

Posted Image

The code is a little long so I attached a zip file containing TerrainComponent.cpp and the terrain vertex and pixel shaders.
I have compared my code to his for hours and hours and I cannot find what I am doing wrong. Please help!!

P.S. Let me know if you need to see more code.

Tips for programming a road building tool

20 August 2012 - 01:51 PM


I am fairly new to game programming and I am trying to build a simple system where I can construct a road on a plane. I would like to implement a road building tool similar to Cities XL's road tool where you can click and drag the mouse to create curved roads on a terrain.

At this point I know how to get the coordinates of the on the plane according to the mouse click by casting a ray and gathering the result. My first thought is to collect the coordinates and create an array of road models and place them between the mouse clicks, I just don't know how to implement the curve. I googled various curve algorithms but I don't know how to implement them and I don't know if this is the best approach to solving the problem. I'm just looking for advise on how to approach this. Thanks in advance.