Jump to content

  • Log In with Google      Sign In   
  • Create Account


CableGuy

Member Since 24 Oct 2005
Offline Last Active Yesterday, 01:27 PM

#5066638 How to create a level editor

Posted by CableGuy on 01 June 2013 - 03:56 AM

Are you seeking to create a tilemap based level editor or polygonal one? (Also I assume you are aiming at a 2d game)

Both cases usually have different representation of the game world. With a tilemap, a 2D matrix specifying which tile to use at each (X,Y) is the most logical.

A polygonal map representation, at it's most naive form, will store an array of polygons. The representation of the game world greatly affects how you would implement

the level editing area in your editor




#5014117 Dealing with bind-to-edit in OpenGL

Posted by CableGuy on 25 December 2012 - 01:10 AM

I have most of my resources pointed to as shared_ptr's. I know it is not the best solution but it works for now.

Also why do you need to cache the rendering state? In my code, a list is prepared containing all things to be rendered this frame. Then it is sorted to reduce state changes

and then rendered in a single function removing the need to store a global cache.




#4875345 [C++] pass a class's function to another class

Posted by CableGuy on 22 October 2011 - 10:03 AM

A global function and a member function are not the same. even if they appear to have the same signature, a non-static member function always has a hidden "this" parameter.
May I suggest using boost::function?


#4825954 Ray casting, triangle intersection

Posted by CableGuy on 21 June 2011 - 06:57 AM

d is the distance of the plane from the origin - (0,0,0). So d is a property of the plane and does not depend on any other value.
To define a plane you need a normal. But that is not enough. There is an infinite amount of planes sharing the same normal. Adding d makes the plane unique.
But it doesn't matter too much what d represents as long as you follow the two equations that define a plane and a ray.


#4825934 Ray casting, triangle intersection

Posted by CableGuy on 21 June 2011 - 06:20 AM

Taking the plane equation as ax + by + cz - d = 0
we get that d = ax + by + cz
so by substituting a,b,c by the plane normal and x y z by some point on it we get d.
Then we know that:
t = (d - O*n) / (D * n)
where t is the distance along the ray direction, O is the ray origin, D is the ray direction, n is the plane normal and d is the value we calculated above.

calculate distance: d = abs((vertex3 - rayOrigin) . normal); vertex3 is one of the 3 vertices on the plane

So, d should be either vertex3 * normal or -(vertex3 * normal) depending how you wrote the plane equation.

calculate V0: -(normal . rayOrigin + distance)

Again V0 should be either d - rayOrigin * normal or rayOrigin * normal - d.

Make sure you understand the equations and follow the calculation.


#4825851 Ray casting, triangle intersection

Posted by CableGuy on 21 June 2011 - 12:04 AM

Suspecting my last attempt was a fail, here is a new attempt that I think is correct:

void OpenGLControl::hitTest()
{

	float t;
	float a, b;
	vector3 b, pointOnPlane, tempPoint;
	float distance;


	for(int i = 0; i < hitTestPoints.size(); i++)
	{
    	for(int j = 0; j < model->triangles.size(); j++)
    	{
   		//N.D  normal . (0,1,0)
   		a = model->triangles[j].normal * rayOrientation;
   		//if plane is paralel to ray
   		if(a == 0)
   		{
   			continue;
   		}
        	//N.v3  normal . one point on plane (one of the vertices)
   		//ax + by + cz + d = 0 wich can be rewritten as N.v3 + d = 0 => d = -(N.v3)
   		distance = -(model->triangles[j].normal*model->triangles[j].v3);
   		//origin . normal + distance ( N.O + d )
   		b = hitTestPoints[i] * model->triangles[j].normal + distance;
   		t = (-b)/a;
   		//intersection is behind the ray
   		if(t < 0)
   		{
   			continue;
   		}
   		//calculate the point
   		tempPoint = rayOrientation*t;
   		pointOnPlane = hitTestPoints[i] + tempPoint;
    	}
	}
}


I've only glanced at the code but it seems correct, now all is left is just a 2d point in triangle test...


#4825165 when are genetic algorithms useful?

Posted by CableGuy on 19 June 2011 - 12:09 PM

I agree with alvaro. I've taken a class in GA at uni and can say that they aren't very useful(IMHO).
All the toy problems we have seen were solvable(sometimes barely) with a GA but I don't see a reason to use it an not a hand crafted algorithm.
They are easy to implement and most of the code is reusable ( you need to change only a few operators), and maybe for a simple problem they might be a good choice
if you've already got a framework running and don't have the time to invest in an ad hoc algorithm. Also fine-tuning all the parameters can take more time than actually writing the whole thing.
In general the idea is nice but I personally haven't come across a problem where GA was a good solution.


#4825132 Ray casting, triangle intersection

Posted by CableGuy on 19 June 2011 - 11:07 AM

Mostly correct.
You will first calculate the normal and plug it in the a,b,c parameters in the equation.
Then replace x,y,z by one of the points on the plane(one of the points of the triangle) and you have got d.
The reset is correct.
Two things to note:
1. if (D * n) = 0 it means that the ray and the plane are parallel hence no intersection.
2. The algorithm described in the linked paper performs ray/triangle intersection yet what I've described only performs ray.plane intersection.
Which means that after you calculated the intersection point of the ray and the plane you still have to check if it lies within the triangle.


#4825107 Ray casting, triangle intersection

Posted by CableGuy on 19 June 2011 - 10:20 AM

The plane defined by the three points of the triangle.


#4825087 Ray casting, triangle intersection

Posted by CableGuy on 19 June 2011 - 09:03 AM


You can first do a ray plane intersection.
The intersection test will tell you if they intersect and if so, return t.
From the plane equation you know that if p is on the plane then: p * n - d = 0
where n is the normal of the plane, d is it's distance from the origin and * is the dot product. Also as you described any point along the ray can be given using O + tD.
now it's is just a matter of checking whether there is a point that lies along ray and is on the plane.

Hope this helps.


Thank you for your answer! If I understand you correctly: I need to increment t for so long that I get p (on the triangle)? How big are the increments? 1px?


No.
All point on the ray satisfy p = O + tD.
All points on the plane satisfy p * n - d = 0.
Therefore lets say a point p' satisfies both then:
p' = O + tD
p' * n - d = 0
substituting p' in the second equation we get:
(O + tD) * n - d = 0.
O, D, n, d are all known what is left is to solve for t.


#4825053 Ray casting, triangle intersection

Posted by CableGuy on 19 June 2011 - 07:10 AM

You can first do a ray plane intersection.
The intersection test will tell you if they intersect and if so, return t.
From the plane equation you know that if p is on the plane then: p * n - d = 0
where n is the normal of the plane, d is it's distance from the origin and * is the dot product. Also as you described any point along the ray can be given using O + tD.
now it's is just a matter of checking whether there is a point that lies along ray and is on the plane.

Hope this helps.


#4793796 Deriving the facing vector from world transformation matrix using matrix inverse

Posted by CableGuy on 03 April 2011 - 05:49 AM

Not sure what you mean here exactly but my guess is to take the vector (0, 0, 1) and apply the transformation on it I think D3D has something like TransformNormal.

HTH.


#4757784 Looking for a music player liek WinAMP used to be

Posted by CableGuy on 12 January 2011 - 10:39 AM

Foobar2000 I've been using it for quite some time and I'm very pleased with it.
First and most important it is not a bloatware as Winamp became and also IMHO Songbird which was my previous music player.
It's not the most pretty one but it's fast and highly customizable.


PARTNERS