Jump to content

  • Log In with Google      Sign In   
  • Create Account

WiredCat

Member Since 09 Apr 2011
Offline Last Active Today, 06:18 AM

Topics I've Started

function that returns class template

26 October 2014 - 08:13 AM

hello, i have a class template

template <class _cType> class t3dpoint {
	public:
_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:

Untitled.png

 

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);

}

Texturing problem - weird swap

16 October 2014 - 10:08 AM

mek.jpg

Image shows 9 slices of mesh when i try to texture each segment and i hit the boundary (x = dimension) or y = dimension

i get somehow a swap, you can clearly see this on the top right slice when at the bottom of it you see blue line of water (between land)

 

 

heres a sample of a texture (its not a texture form the image) but this faulty texturing occurs on every mesh (whatever texture i use) (i just cant remember where i was to obtain the texture in topright segment-)

SECTOR_0-21.jpg

 

 

as you can see theres no blue line at the bottom (dont mind for left right sides line its the same algorithm for that)

 

 

now the texture has a dimension 2x larger than a mesh (mesh has 120x120 pixels, texture has 240x240)

 

no when i create a mesh i do something like this:

 

for y to 120

for x to 120

{

create_4_vertices_from_the_mesh_heightmap (each (x y) (x+1,y), (x+1 y+1), (x, y+1) )

} so i basically make 4 verts out of every pixel

 

then i texture it by 







float fdim = 120.0f;
float fpy;
float fpx;
for (y=0; y < 120; y++)
for (x=0; x < 120; x++)
{

fpx = float(x);
fpy = float(y);

totalindex = totalindex + 1;
hmodel->VBO_T[totalindex] = float2textpoint(fpx/fdim,              (fdim-fpy) / fdim);

totalindex = totalindex + 1;
hmodel->VBO_T[totalindex] = float2textpoint((fpx+1.0f) / fdim,     (fdim-fpy) / fdim);

totalindex = totalindex + 1;
hmodel->VBO_T[totalindex] = float2textpoint((fpx+1.0f) / fdim,     (fdim-(fpy+1.0f)) / fdim);

totalindex = totalindex + 1;
hmodel->VBO_T[totalindex] = float2textpoint(fpx / fdim,            (fdim-(fpy+1.0f)) / fdim);
}

please help ;]


PARTNERS