Jump to content

  • Log In with Google      Sign In   
  • Create Account

SpectreNectar

Member Since 19 Sep 2009
Offline Last Active Oct 16 2012 06:47 AM

Posts I've Made

In Topic: Separating geometry based on closest points?

12 October 2012 - 02:40 PM

Yes that was quite vague, I wasn't sure what I was asking at the time.

I've been looking into the GJK algorithm, but I have some trouble implementing it. Here's what I've tried for the 2D case (GML):

co_gjk()
{
    // Arguments for first OBB
    var a_cx, a_cy, a_ax1, a_ay1, a_ax2, a_ay2, a_sx, a_sy;
	    a_cx  = argument0;
	    a_cy  = argument1;
	    a_ax1 = argument2;
	    a_ay1 = argument3;
	    a_ax2 = argument4;
	    a_ay2 = argument5;
	    a_sx  = argument6;
	    a_sy  = argument7;
   
    // Arguments for second OBB
    var b_cx, b_cy, b_ax1, b_ay1, b_ax2, b_ay2, b_sx, b_sy;
	    b_cx  = argument8;
	    b_cy  = argument9;
	    b_ax1 = argument10;
	    b_ay1 = argument11;
	    b_ax2 = argument12;
	    b_ay2 = argument13;
	    b_sx  = argument14;
	    b_sy  = argument15;
   
    // Vectors
    co_gjk_direction_vector_x = -1;
    co_gjk_direction_vector_y = -1;
	   
    var posx, posy, negx, negy;
	    posx = co_obb_furthest_point_along_vector_x(a_cx, a_cy, a_ax1, a_ay1, a_ax2, a_ay2, a_sx, a_sy);
	    posy = co_obb_furthest_point_along_vector_y(a_cx, a_cy, a_ax1, a_ay1, a_ax2, a_ay2, a_sx, a_sy);
	    negx = co_obb_furthest_point_along_vector_x(b_cx, b_cy, b_ax1, b_ay1, b_ax2, b_ay2, b_sx, b_sy);
	    negy = co_obb_furthest_point_along_vector_y(b_cx, b_cy, b_ax1, b_ay1, b_ax2, b_ay2, b_sx, b_sy);
	   
    var ax, ay;
	    ax = (posx-negx);
	    ay = (posy-negy);
   
    co_gjk_direction_vector_x = -ax;
    co_gjk_direction_vector_y = -ay;
   
    co_gjk_point_list_x[0] = ax;
    co_gjk_point_list_x[0] = ay;
    var n;
	    n = 1;
    do {
	   
	    // Along direction vector
	    posx = co_obb_furthest_point_along_vector_x(a_cx, a_cy, a_ax1, a_ay1, a_ax2, a_ay2, a_sx, a_sy);
	    posy = co_obb_furthest_point_along_vector_y(a_cx, a_cy, a_ax1, a_ay1, a_ax2, a_ay2, a_sx, a_sy);
	    negx = co_obb_furthest_point_along_vector_x(b_cx, b_cy, b_ax1, b_ay1, b_ax2, b_ay2, b_sx, b_sy);
	    negy = co_obb_furthest_point_along_vector_y(b_cx, b_cy, b_ax1, b_ay1, b_ax2, b_ay2, b_sx, b_sy);
	   
	    ax = (posx-negx);
	    ay = (posy-negy);
	   
	    if(ax*co_gjk_direction_vector_x+ay*co_gjk_direction_vector_y < 0) return false;
	   
	    co_gjk_point_list_x[n] = ax;
	    co_gjk_point_list_y[n] = ay;
	   
	    if(n+1==2) n = co_gjk_line(co_gjk_point_list_x[0], co_gjk_point_list_y[0], co_gjk_point_list_x[1], co_gjk_point_list_y[1]);
	    else	   n = co_gjk_triangle(co_gjk_point_list_x[0], co_gjk_point_list_y[0], co_gjk_point_list_x[1], co_gjk_point_list_y[1], co_gjk_point_list_x[2], co_gjk_point_list_y[2]);
	   
    } until(n>=3);
   
return true;
}

co_gjk_line()

{
         var ax, ay, bx, by;
	    ax = argument2; //A is last!
	    ay = argument3;
	    bx = argument0;
	    by = argument1;
    var aox, aoy, abx, aby;
	    aox = -ax;
	    aoy = -ay
	    abx = bx-ax;
	    aby = by-ay;
   
	   
    co_gjk_direction_vector_x = -aby;
    co_gjk_direction_vector_y = abx;
    // Not towards origin?
    if(co_gjk_direction_vector_x*aox+co_gjk_direction_vector_y*aoy<0) {
	    co_gjk_direction_vector_x = -co_gjk_direction_vector_x;
	    co_gjk_direction_vector_y = -co_gjk_direction_vector_y;
    }
    return 2;
}

co_gjk_triangle()
{
    var ax, ay, bx, by, cx, cy;
	    ax = argument4; //A is last!
	    ay = argument5;
	    bx = argument2;
	    by = argument3;
	    cx = argument0;
	    cy = argument1;
    var aox, aoy, abx, aby, acx, acy;
	    aox = -ax;
	    aoy = -ay
	    abx = bx-ax;
	    aby = by-ay;
	    acx = cx-ax;
	    acy = cy-ay;
   
	   
    co_gjk_direction_vector_x = -aby;
    co_gjk_direction_vector_y = abx;
    // "2D cross product"
    if(abx*acy-aby*acx>0.0) {
	    co_gjk_direction_vector_x = -co_gjk_direction_vector_x;
	    co_gjk_direction_vector_y = -co_gjk_direction_vector_y;
    }
   
    // Towards origin?
    if(co_gjk_direction_vector_x*aox+co_gjk_direction_vector_y*aoy>0.0) {
	    // Remove C from simplex
	    co_gjk_point_list_x[0] = ax;
	    co_gjk_point_list_x[0] = ay;
	    return 2;
    }
   
   
    co_gjk_direction_vector_x = -acy;
    co_gjk_direction_vector_y = acx;
    // "2D cross product"
    if(acx*aby-acy*abx>0.0) {
	    co_gjk_direction_vector_x = -co_gjk_direction_vector_x;
	    co_gjk_direction_vector_y = -co_gjk_direction_vector_y;
    }
   
    // Towards origin?
    if(co_gjk_direction_vector_x*aox+co_gjk_direction_vector_y*aoy<0) {
	    // Remove B from simplex
	    co_gjk_point_list_x[1] = ax;
	    co_gjk_point_list_x[1] = ay;
	    return 2;
    }
   
    // Done
    return 3;
}

co_obb_furthest_point_along_vector_x()
{
    var cx, cy, ax1, ay1, ax2, ay2, sx, sy;
	    cx  = argument0;
	    cy  = argument1;
	    ax1 = argument2;
	    ay1 = argument3;
	    ax2 = argument4;
	    ay2 = argument5;
	    sx  = argument6;
	    sy  = argument7;
   
   return sx*abs(co_gjk_direction_vector_x*ax1+co_gjk_direction_vector_y*ay1);
}

It's supposed to return true if the OBBs intersect but nothing happens.

In Topic: RPG Making Competition at 64digits.com

23 April 2012 - 01:07 PM

This is going to be awesome.

In Topic: Help me using buffer objects

05 March 2012 - 11:20 AM

Thanks, I now have visual output!
It covers the whole screen in an orange color though. Could have something to do with my camera matrix. In pursuit of my goal of having the shader make things isometric, I set it up with the GLM math library ( http://glm.g-truc.net/ ) to look at the screen like this:

glm::vec3 eye = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 center = glm::vec3(0.0f, 0.0f, 1.0f);
glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);
glm::mat4 viewMatrix = glm::lookAt(eye, center, up);
glUniformMatrix4fv(glGetUniformLocation(p, "vMatrix"), 1, GL_FALSE, glm::value_ptr(viewMatrix));

So I have a few more questions before I can draw things properly.
When you create an orthographic projection, any non zero Z value isn't drawn as it is outside znear/zfar range. So if you don't want perspective yet want to have your geometry stored with all three axis, any z coordinate must be set to zero eg. inside a vertex shader. Is this a correct assumption?
What range are coordinates inside a vertex shader in? 0.0-1.0?
In the following shader, what function do I need in order to set "vertex" to the same value as that inside "t->vertices"? (so I don't need ftransform())

#version 330
in vec4 vertex;
uniform float ox;
uniform float oy;
uniform mat4 vMatrix;
uniform mat4 mMatrix;
out float odepth;
void main()
{
vec4 vert = ftransform() * vMatrix;
  
float sqrX = vert.x;
    float sqrY = 1.0-vert.y;
    float sqrZ = vert.z;

vert.x = ox + sqrX-sqrY;
vert.y = oy + (sqrY+sqrX)/2.0 - sqrZ;
vert.z = 0.0;
  
odepth = sqrZ;
	 
gl_Position = vert;
}

Again, thanks very much.

In Topic: Which BASIC should I use?

02 January 2010 - 03:36 PM

Quote:
Original post by ferdekk
you tried purebasic?
http://purebasic.com/


No, I haven't
It looks very promising!
Thanks, I believe this is more than I had hoped for.

PARTNERS