Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 09 Apr 2011
Offline Last Active Today, 06:38 PM

Topics I've Started

How can i fit a bounding box in the frustum

Today, 05:34 AM

hello there


To describe clearly that problem i need an image:





As you can see there a 9 tiles (hieghtmaps) lets focus on that one in the center.

Those tile are actualy separated 3d meshes/ (lets focus on that in the center)


I want to make shadowmapping, however to properly set light perspective i need to position the light itself not too far [and not too close) from the center of the mesh lets say the center point of a mesh is called CM.


so what i need to find is LightPosition = CM - LightDirection*distance <- yep i need the distance 



there would be no problem if the light was placed on one of the axes, but however my light can be anywhere

so i drew an img showing what my problem is:P




So i can get the bounding box of the mesh but i have no idea how to project it to fit to the frustum 


function that returns class template

26 October 2014 - 08:13 AM

hello, i have a class template

template <class _cType> class t3dpoint {
_cType x;
_cType y;
_cType z;

now when it was just simple struct i could do 

t3dpoint __fastcall vectorAB(t3dpoint A,t3dpoint B)
t3dpoint result;
result.x = B.x-A.x;
result.y = B.y-A.y;
result.z = B.z-A.z;
return result;

i came out with that thing i have no idea what should i write:

template <class type> t3dpoint<type> vectorAB(type A, type B)
t3dpoint<type>  result;
result.x = B.x-A.x;
result.y = B.y-A.y;
result.z = B.z-A.z;
return result;

so how should i deal with this






soo how to deal with multiple collision (sphere collides with more than 1 poly)

24 October 2014 - 04:04 PM

I search for any information that could help me with this issue, whenever i get multiple collision it only acts on one poly.



Sphere moves from point A to B.


What i have for now:

function that returns whatever i collided with a poly (when yes it returns additionally: new_position of a sphere (after collision with that polygon,

collision normal (the direction from collision point to new sphere pos), collision vector vector from collision point to new sphere pos)



after that it adds this data to the stack (actualy its an array of results)


Function finds all polygons that sphere must collide with.




then i sort the data with forumla

get distance from (new_position and A)



so the smallest distance is first and greatest is last



then i set sphere pos to the first new_position, after that i add all collision vectors from other polygons (btw this is one of my last inventions)


sphere acts like its only the first collision and no others.



Force to slide on collision between sphere and poly side

20 October 2014 - 02:06 PM

Hi, i am working on collision response, so far when my sphere reachec polygon side it stops and doesn't slide i have no idea how to deal this:


this are my calculations:



Sphere is moving from A to B i make a ray and check for distances between that movement ray segment and all sides of polygon, then i check for the closest one and calculate the closest points on each segments (movement ray and polygon side)



then  i just use formula of c^2 = a^2 + b^2 and calculate the distance between closest point on movement ray segment and collided sphere pos

after that i make a normalized vector BA and multiple it by this distance, adding closest point on ray segment i get new sphere position



HOWEVER: it doesnt slide it just stalls the camera like on this video (there is also shown sliding on the poly itself)




so how shouldi change that formula to achieve a sliding effect?

Ray plane intersection problem (need verification to the code)

19 October 2014 - 04:46 AM

maybe the code itself will say more than 1000 words ill coment everything.

int index = model->VBO_BE[faceindex].INDEX_START; //first face vertex index in VBO
t3dpoint pop = model->VBO_V[index]; //point on checked plane

t3dpoint A = vectorAB(model->VBO_V[index],model->VBO_V[index+1]);  //vector from first vertex to second vertex of the plane (face)
t3dpoint B = vectorAB(model->VBO_V[index],model->VBO_V[index - model->VBO_BE[faceindex].length - 1]); //since its a quad this is a vector from first vertex to last vertex
t3dpoint n = Normalize(A * B); //calculate plane normal and normalize it

t3dpoint Ap = ProjectPointOntoPlane(n,pop, rA); //project ray start onto plane
t3dpoint Bp = ProjectPointOntoPlane(n,pop, rB);//ray end point on plane
t3dpoint AB = vectorAB(Ap,Bp); //make a vector on plane

float dstA = float(n3dPoint_plane_distance(rA, model->MATH_FACE_NORMALS[faceindex], model->MATH_FACE_DISTANCES[faceindex])); //oh yes since plane equations are Ax+By+Cz+D=0 i made helper arrays with these values (A,B,C,D)

float dstAB = n3ddistance(rA, rB);

float perDST = dstA / dstAB; //get perccentage of the distances of ray start from plane / distance between start and end of ray

t3dpoint PointOnPlane = Ap + AB*perDST; //since Ap should be on plane it should return actual intersection point
res = PointOnPlane;

helper functions

long double n3dPoint_plane_distance(t3dpoint p, t3dpoint vnormalnover, float D)
long double d = -1.0f;
long double num =  p.x * vnormalnover.x + p.y * vnormalnover.y+ p.z * vnormalnover.z +     D;
num = abs( num );
long double denom = vnormalnover.x*vnormalnover.x + vnormalnover.y*vnormalnover.y+vnormalnover.z*vnormalnover.z;
denom = sqrtl(denom);
if (denom == 0.0f) return -1;
return num / denom;

t3dpoint __fastcall ProjectPointOntoPlane(t3dpoint normal, t3dpoint pointonplane, t3dpoint projected_point)
t3dpoint v = vectorAB(pointonplane,projected_point);

float dist = Dot(v,normal);

return projected_point - (normal*dist);