diff --git a/enjacl/enja.cpp b/enjacl/enja.cpp index a1c26ff4..9e8e50e7 100644 --- a/enjacl/enja.cpp +++ b/enjacl/enja.cpp @@ -229,6 +229,7 @@ EnjaParticles::~EnjaParticles() if(ckKernel)clReleaseKernel(ckKernel); if(cpProgram)clReleaseProgram(cpProgram); if(cqCommandQueue)clReleaseCommandQueue(cqCommandQueue); + if(v_vbo) { glBindBuffer(1, v_vbo); @@ -248,18 +249,25 @@ EnjaParticles::~EnjaParticles() i_vbo = 0; } - //if(vbo_cl)clReleaseMemObject(vbo_cl); + printf("seg fault 1?\n"); if(cl_vbos[0])clReleaseMemObject(cl_vbos[0]); if(cl_vbos[1])clReleaseMemObject(cl_vbos[1]); if(cl_vbos[2])clReleaseMemObject(cl_vbos[2]); + printf("seg fault 1.5?\n"); + //why are these arrays segfaulting when released? if(cl_vert_gen)clReleaseMemObject(cl_vert_gen); if(cl_velo_gen)clReleaseMemObject(cl_velo_gen); if(cl_velocities)clReleaseMemObject(cl_velocities); + printf("seg fault 1.6?\n"); + if(cl_indices)clReleaseMemObject(cl_indices); + printf("seg fault 1.7?\n"); //if(cl_life)clReleaseMemObject(cl_life); if(cxGPUContext)clReleaseContext(cxGPUContext); + printf("seg fault 1.8?\n"); if(cdDevices)delete(cdDevices); + printf("seg fault 2?\n"); } diff --git a/enjacl/main.cpp b/enjacl/main.cpp index aa3a08e6..3d9393c0 100644 --- a/enjacl/main.cpp +++ b/enjacl/main.cpp @@ -184,6 +184,7 @@ void appDestroy() delete enjas; if(glutWindowHandle)glutDestroyWindow(glutWindowHandle); + printf("about to exit!\n"); exit(0); } diff --git a/enjacl/opencl.cpp b/enjacl/opencl.cpp index a41ef7d8..3b6b2326 100644 --- a/enjacl/opencl.cpp +++ b/enjacl/opencl.cpp @@ -119,8 +119,8 @@ void EnjaParticles::popCorn() //support arrays for the particle system cl_vert_gen = clCreateBuffer(cxGPUContext, CL_MEM_WRITE_ONLY, vbo_size, NULL, &ciErrNum); cl_velo_gen = clCreateBuffer(cxGPUContext, CL_MEM_WRITE_ONLY, vbo_size, NULL, &ciErrNum); - cl_velo_gen= clCreateBuffer(cxGPUContext, CL_MEM_WRITE_ONLY, vbo_size, NULL, &ciErrNum); - //cl_life = clCreateBuffer(cxGPUContext, CL_MEM_WRITE_ONLY, sizeof(float) * num, NULL, &ciErrNum); + cl_velo_gen = clCreateBuffer(cxGPUContext, CL_MEM_WRITE_ONLY, vbo_size, NULL, &ciErrNum); + cl_indices = clCreateBuffer(cxGPUContext, CL_MEM_WRITE_ONLY, sizeof(int) * num, NULL, &ciErrNum); ciErrNum = clEnqueueWriteBuffer(cqCommandQueue, cl_vert_gen, CL_TRUE, 0, vbo_size, &vert_gen[0], 0, NULL, &evt); clReleaseEvent(evt); @@ -128,8 +128,8 @@ void EnjaParticles::popCorn() clReleaseEvent(evt); ciErrNum = clEnqueueWriteBuffer(cqCommandQueue, cl_velo_gen, CL_TRUE, 0, vbo_size, &velo_gen[0], 0, NULL, &evt); clReleaseEvent(evt); - //ciErrNum = clEnqueueWriteBuffer(cqCommandQueue, cl_life, CL_TRUE, 0, sizeof(float) * num, life, 0, NULL, &evt); - //clReleaseEvent(evt); + ciErrNum = clEnqueueWriteBuffer(cqCommandQueue, cl_indices, CL_TRUE, 0, sizeof(int) * num, &indices[0], 0, NULL, &evt); + clReleaseEvent(evt); clFinish(cqCommandQueue); diff --git a/enjacl/physics/collision.cl b/enjacl/physics/collision.cl index 4e00799f..3024736a 100644 --- a/enjacl/physics/collision.cl +++ b/enjacl/physics/collision.cl @@ -4,6 +4,47 @@ float4 cross_product(float4 a, float4 b) return (float4)(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x, 0); } +//Moller and Trumbore +bool intersect_triangle(float4 pos, float4 vel, float4 tri[3], float4 triN, float dist) +{ + //take in the particle position and velocity (treated as a Ray) + //also the triangle vertices for the ray intersection + //we take in the precalculated triangle's normal to first test for distance + //dist is the threshold to determine if we are close enough to the triangle + //to even check for distance + float4 edge1, edge2, tvec, pvec, qvec; + float det, inv_det, u, v; + float eps = .000001; + + //check distance + tvec = pos - tri[0]; + float distance = -dot(tvec, triN) / dot(vel, triN); + if (distance > dist) + return false; + + + edge1 = tri[1] - tri[0]; + edge2 = tri[2] - tri[0]; + + pvec = cross(vel, edge2); + det = dot(edge1, pvec); + //culling branch + //if(det > -eps && det < eps) + if(det < eps) + return false; + + u = dot(tvec, pvec); + if (u < 0.0 || u > det)//1.0) + return false; + + qvec = cross(tvec, edge1); + v = dot(vel, qvec); + if (v < 0.0 || u + v > det)//1.0f) + return false; + + return true; +} + //update the particle position and color @@ -12,8 +53,8 @@ __kernel void enja(__global float4* vertices, __global float4* colors, __global unsigned int i = get_global_id(0); float life = velocities[i].w; - life -= h; //should probably depend on time somehow - h = h*10; + life -= h/10; //should probably depend on time somehow + //h = h*10; if(life <= 0.) { //reset this particle @@ -26,125 +67,64 @@ __kernel void enja(__global float4* vertices, __global float4* colors, __global velocities[i].z = velo_gen[i].z; life = 1.; } - float xn = vertices[i].x; - float yn = vertices[i].y; - float zn = vertices[i].z; - - - float vxn = velocities[i].x; - float vyn = velocities[i].y; - float vzn = velocities[i].z; - velocities[i].x = vxn; - velocities[i].y = vyn - h*9.8; - velocities[i].z = vzn;// - h*9.8; - - xn += h*velocities[i].x; - yn += h*velocities[i].y; - zn += h*velocities[i].z; + float4 pos = vertices[i]; + float4 vel = velocities[i]; + + float xn = pos.x; + float yn = pos.y; + float zn = pos.z; + + float vxn = vel.x; + float vyn = vel.y; + float vzn = vel.z; + vel.x = vxn; + vel.y = vyn - h*9.8; + vel.z = vzn;// - h*9.8; + + xn += h*vel.x; + yn += h*vel.y; + zn += h*vel.z; //set up test plane float4 plane[4]; - plane[0] = (float4)(0,-1,0,0); - plane[1] = (float4)(0,-1,2,0); + plane[0] = (float4)(-2,-1,-2,0); + plane[1] = (float4)(-2,-1,2,0); plane[2] = (float4)(2,-1,2,0); - plane[3] = (float4)(2,-1,0,0); + plane[3] = (float4)(2,-1,-2,0); //triangle fan from plane (for handling faces) - float4 tri1[3]; - tri1[0] = plane[0]; - tri1[1] = plane[1]; - tri1[2] = plane[2]; - - /* do 1 triangle first - float4 tri2[3]; - tr2[0] = plane[0]; - tr2[1] = plane[2]; - tr2[2] = plane[3]; - */ + float4 tri[3]; + tri[0] = plane[0]; + tri[1] = plane[1]; + tri[2] = plane[2]; //calculate the normal of the triangle //might not need to do this if we just have plane's normal - float4 A = tri1[0]; - float4 B = tri1[1]; - float4 C = tri1[2]; + float4 A = tri[0]; + float4 B = tri[1]; + float4 C = tri[2]; - //float4 tri1N = cross_product(B - A, C - A); - float4 tri1N = (float4)(0.0, 1.0, 0.0, 0.0); - //calculate the distnace of pos from triangle - float distance = -dot(vertices[i] - A, tri1N) / dot(velocities[i], tri1N); - float4 P = vertices[i] + distance*velocities[i]; - if (distance <= 0.0f) - { - //particle is past the plane so don't do anything - } - else + float4 triN = normalize(cross_product(B - A, C - A)); + //float4 tri1N = (float4)(0.0, 1.0, 0.0, 0.0); + + if(intersect_triangle(pos, vel, tri, triN, h)) { - int x = 0; - int y = 2; - //these should be projections... - //or at least calculated from the dominant axis of the normal - float2 Ap = (float2)(A.x, A.z); - float2 Bp = (float2)(A.x, A.z); - float2 Cp = (float2)(A.x, A.z); - float2 Pp = (float2)(A.x, A.z); - - float2 b = (Bp - Ap); - float2 c = (Cp - Ap); - float2 p = (Pp - Ap); - - float u = (p.y*c.x - p.x*c.y)/(b.y*c.x - b.x*c.y); - float v = (p.y*b.x - p.x*b.y)/(c.y*b.x - c.x*b.y); - - if(u >= 0 and v >= 0 and u+v <= 1) - { - - //particle and triangle collision - //if (yn < -1.0f) - - float4 posA = vertices[i]; - float radiusA = 5.0f; - float4 posB = vertices[i] + radiusA/2.0f; - float4 relPos = (float4)(posB.x - posA.x, posB.y - posA.y, posB.z - posA.z, 0); - float dist = sqrt(relPos.x * relPos.x + relPos.y * relPos.y + relPos.z * relPos.z); - float collideDist = radiusA + 0.0;//radiusB; - - - //float4 norm = (-0.707106, 0.707106, 0.0, 0.0); //this is actually a unit vector - float4 norm = (float4)(0.0, 1.0, 0.0, 0.0); - norm = normalize(norm); - float4 velA = velocities[i]; //velocity of particle - float4 velB = (float4)(0,0,0,0); //velocity of object - float4 relVel = (float4)(velB.x - velA.x, velB.y - velA.y, velB.z - velA.z, 0); - - float relVelDotNorm = relVel.x * norm.x + relVel.y * norm.y + relVel.z * norm.z; - float4 tanVel = (float4)(relVel.x - relVelDotNorm * norm.x, relVel.y - relVelDotNorm * norm.y, relVel.z - relVelDotNorm * norm.z, 0); - float4 force = (float4)(0,0,0,0); - float springFactor = -.5;//-spring * (collideDist - dist); - float damping = 1.0f; - float shear = 1.0f; - float attraction = 1.0f; - force = (float4)( - springFactor * norm.x + damping * relVel.x + shear * tanVel.x + attraction * relPos.x, - springFactor * norm.y + damping * relVel.y + shear * tanVel.y + attraction * relPos.y, - springFactor * norm.z + damping * relVel.z + shear * tanVel.z + attraction * relPos.z, - 0 - ); - - //float mag = sqrt(vel.x*vel.x + vel.y*vel.y + vel.z*vel.z); //store the magnitude of the velocity - //vel /= mag; - //vel = 2.f*(dot(normal, vel))*normal - vel; - ////vel *= mag; //we know the direction lets go the right speed - - velA += force; - - xn = vertices[i].x + h*velA.x; - yn = vertices[i].y + h*velA.y; - zn = vertices[i].z + h*velA.z; - velocities[i] = velA; - } - } + //lets do some specular reflection + float mag = sqrt(vel.x*vel.x + vel.y*vel.y + vel.z*vel.z); //store the magnitude of the velocity + float4 nvel = normalize(vel); + float s = 2.0f*(dot(triN, nvel)); + float4 dir = s * triN - nvel; //new direction + float damping = .5f; + mag *= damping; + vel = -mag * dir; + + xn = pos.x + h*vel.x; + yn = pos.y + h*vel.y; + zn = pos.z + h*vel.z; + } + vertices[i].x = xn; vertices[i].y = yn; vertices[i].z = zn; @@ -156,6 +136,7 @@ __kernel void enja(__global float4* vertices, __global float4* colors, __global //colors[i].w = 1-life; colors[i].w = 1; + velocities[i] = vel; //save the life! velocities[i].w = life; } diff --git a/enjacl/physics/collision.cpp b/enjacl/physics/collision.cpp index a8a56b53..ea139f75 100644 --- a/enjacl/physics/collision.cpp +++ b/enjacl/physics/collision.cpp @@ -35,11 +35,63 @@ Vec4 normalize(Vec4 a) return Vec4(a.x/mag, a.y/mag, a.z/mag, a.w); } -Vec4 cross_product(Vec4 a, Vec4 b) +Vec4 cross(Vec4 a, Vec4 b) { return Vec4(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x, 0); } +Vec4 sub(Vec4 a, Vec4 b) +{ + return Vec4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); +} + +Vec4 scala(float s, Vec4 a) +{ + return Vec4(s*a.x, s*a.y, s*a.z, s*a.w); +} + +//Moller and Trumbore +bool intersect_triangle(Vec4 pos, Vec4 vel, Vec4 tri[3], Vec4 triN, float dist) +{ + //take in the particle position and velocity (treated as a Ray) + //also the triangle vertices for the ray intersection + //we take in the precalculated triangle's normal to first test for distance + //dist is the threshold to determine if we are close enough to the triangle + //to even check for distance + Vec4 edge1, edge2, tvec, pvec, qvec; + float det, inv_det, u, v; + float eps = .000001; + + //check distance + tvec = sub(pos, tri[0]); + float distance = -dot(tvec, triN) / dot(vel, triN); + if (distance > dist) + return false; + + + edge1 = sub(tri[1], tri[0]); + edge2 = sub(tri[2], tri[0]); + + pvec = cross(vel, edge2); + det = dot(edge1, pvec); + //culling branch + //if(det > -eps && det < eps) + if(det < eps) + return false; + + u = dot(tvec, pvec); + if (u < 0.0 || u > det)//1.0) + return false; + + qvec = cross(tvec, edge1); + v = dot(vel, qvec); + if (v < 0.0 || u + v > det)//1.0f) + return false; + + return true; +} + + int EnjaParticles::cpu_update() { printf("in cpu_update\n"); @@ -58,14 +110,14 @@ int EnjaParticles::cpu_update() Vec4 plane[4]; plane[0] = Vec4(-2,-1,-2,0); plane[1] = Vec4(-2,-1,2,0); - plane[2] = Vec4(2,-1,2,0); + plane[2] = Vec4(2,-2,2,0); plane[3] = Vec4(2,-1,-2,0); //triangle fan from plane (for handling faces) - Vec4 tri1[3]; - tri1[0] = plane[0]; - tri1[1] = plane[1]; - tri1[2] = plane[2]; + Vec4 tri[3]; + tri[0] = plane[0]; + tri[1] = plane[1]; + tri[2] = plane[2]; // do 1 triangle first //Vec4 tri2[3]; @@ -73,15 +125,16 @@ int EnjaParticles::cpu_update() //tr2[1] = plane[2]; //tr2[2] = plane[3]; // - Vec4 A = tri1[0]; - Vec4 B = tri1[1]; - Vec4 C = tri1[2]; + Vec4 A = tri[0]; + Vec4 B = tri[1]; + Vec4 C = tri[2]; Vec4 bma = Vec4(B.x - A.x, B.y - A.y, B.z - A.z, 0); Vec4 cma = Vec4(C.x - A.x, C.y - A.y, C.z - A.z, 0); - Vec4 tri1N = normalize(cross_product(bma, cma)); - printf("tri1N.x: %f tri1N.y %f tri1N.z %f\n", tri1N.x, tri1N.y, tri1N.z); - //Vec4 tri1N = cross_product(B - A, C - A); - //Vec4 tri1N = Vec4(0.0, 1.0, 0.0, 0.0); + //triangle normal should come from blender + Vec4 triN = normalize(cross(bma, cma)); + printf("triN.x: %f triN.y %f triN.z %f\n", triN.x, triN.y, triN.z); + //Vec4 triN = cross_product(B - A, C - A); + //Vec4 triN = Vec4(0.0, 1.0, 0.0, 0.0); //COLLISION STUFF @@ -93,7 +146,7 @@ int EnjaParticles::cpu_update() for(int i = 0; i < num; i++) { float life = velocities[i].w; - life -= h; //should probably depend on time somehow + life -= h/10; //should probably depend on time somehow if(life <= 0.) { //reset this particle @@ -106,121 +159,107 @@ int EnjaParticles::cpu_update() velocities[i].z = velo_gen[i].z; life = 1.; } - float xn = vertices[i].x; - float yn = vertices[i].y; - float zn = vertices[i].z; - - float vxn = velocities[i].x; - float vyn = velocities[i].y; - float vzn = velocities[i].z; - velocities[i].x = vxn; - velocities[i].y = vyn - h*9.8; - velocities[i].z = vzn;// - h*9.8; - - xn += h*velocities[i].x; - yn += h*velocities[i].y; - zn += h*velocities[i].z; - - - //calculate the normal of the triangle - //might not need to do this if we just have plane's normal - // Vec4 pos = vertices[i]; Vec4 vel = velocities[i]; + float xn = pos.x; + float yn = pos.y; + float zn = pos.z; - //calculate the distnace of pos from triangle - Vec4 tmp = Vec4(pos.x - A.x, pos.y - A.y, pos.z - A.z, pos.w); - float distance = -dot(tmp, tri1N) / dot(velocities[i], tri1N); - Vec4 P = Vec4(pos.x + distance*vel.x, pos.y + distance*vel.y, pos.z + distance*vel.z, 0); - if (distance <= 0.0f) - { - //particle is past the plane so don't do anything - printf("i:%d", i); - } - else + + float vxn = vel.x; + float vyn = vel.y; + float vzn = vel.z; + vel.x = vxn; + vel.y = vyn - h*9.8; + vel.z = vzn;// - h*9.8; + + xn += h*vel.x; + yn += h*vel.y; + zn += h*vel.z; + + if(intersect_triangle(pos, vel, tri, triN, h)) { - //these should be projections... - //or at least calculated from the dominant axis of the normal - //also these are supposed to be float2 but oh well - Vec4 Ap = Vec4(A.x, A.z, 0, 0); - Vec4 Bp = Vec4(B.x, B.z, 0, 0); - Vec4 Cp = Vec4(C.x, C.z, 0, 0); - Vec4 Pp = Vec4(P.x, P.z, 0, 0); - - Vec4 b = Vec4(Bp.x - Ap.x, Bp.y - Ap.y, 0, 0); - Vec4 c = Vec4(Cp.x - Ap.x, Cp.y - Ap.y, 0, 0); - Vec4 p = Vec4(Pp.x - Ap.x, Pp.y - Ap.y, 0, 0); + //particle and triangle collision + //if (yn < -1.0f) + + //lets do some specular reflection + float mag = sqrt(vel.x*vel.x + vel.y*vel.y + vel.z*vel.z); //store the magnitude of the velocity + Vec4 nvel = normalize(vel); + float s = 2.0f*(dot(triN, nvel)); + Vec4 dir = scala(s, triN); + dir = sub(dir, nvel); + float damping = .5f; + mag *= damping; + printf("orig vel: %f %f %f\n", vel.x, vel.y, vel.z); + vel = scala(-mag, dir); + printf("new vel: %f %f %f\n", vel.x, vel.y, vel.z); + + xn = pos.x + h*vel.x; + yn = pos.y + h*vel.y; + zn = pos.z + h*vel.z; + + + + /* + //based on nvidia particle example, sphere-sphere collision + Vec4 posA = vertices[i]; + float radiusA = 5.0f; + Vec4 posB; + posB.x = vertices[i].x + radiusA/2.0f; + posB.y = vertices[i].y + radiusA/2.0f; + posB.z = vertices[i].z + radiusA/2.0f; + posB.w = vertices[i].w; + + Vec4 relPos = Vec4(posB.x - posA.x, posB.y - posA.y, posB.z - posA.z, 0); + float dist = sqrt(relPos.x * relPos.x + relPos.y * relPos.y + relPos.z * relPos.z); + float collideDist = radiusA + 0.0;//radiusB; + + + //Vec4 norm = (-0.707106, 0.707106, 0.0, 0.0); //this is actually a unit vector + Vec4 norm = Vec4(0.0, 1.0, 0.0, 0.0); + norm = normalize(norm); + Vec4 velA = velocities[i]; //velocity of particle + Vec4 velB = Vec4(0,0,0,0); //velocity of object + Vec4 relVel = Vec4(velB.x - velA.x, velB.y - velA.y, velB.z - velA.z, 0); + + float relVelDotNorm = relVel.x * norm.x + relVel.y * norm.y + relVel.z * norm.z; + Vec4 tanVel = Vec4(relVel.x - relVelDotNorm * norm.x, relVel.y - relVelDotNorm * norm.y, relVel.z - relVelDotNorm * norm.z, 0); + Vec4 force = Vec4(0,0,0,0); + float springFactor = -.5;//-spring * (collideDist - dist); + float damping = 1.0f; + float shear = 1.0f; + float attraction = 1.0f; + force = Vec4( + springFactor * norm.x + damping * relVel.x + shear * tanVel.x + attraction * relPos.x, + springFactor * norm.y + damping * relVel.y + shear * tanVel.y + attraction * relPos.y, + springFactor * norm.z + damping * relVel.z + shear * tanVel.z + attraction * relPos.z, + 0 + ); + + //float mag = sqrt(vel.x*vel.x + vel.y*vel.y + vel.z*vel.z); //store the magnitude of the velocity + //vel /= mag; + //vel = 2.f*(dot(normal, vel))*normal - vel; + ////vel *= mag; //we know the direction lets go the right speed - float u = (p.y*c.x - p.x*c.y)/(b.y*c.x - b.x*c.y); - float v = (p.y*b.x - p.x*b.y)/(c.y*b.x - c.x*b.y); - printf("distance: %f\n", distance); - if(pos.y < -.9 and pos.y > -1.1) - { - printf("i: %d, u: %f, v: %f, u+v: %f\n", i, u, v, u+v); - //printf("b.x: %f b.y: %f c.x: %f c.y: %f\n", b.x, b.y, c.x, c.y); - } - if(u >= 0 and v >= 0 and u+v <= 1) - { - - //particle and triangle collision - //if (yn < -1.0f) - - Vec4 posA = vertices[i]; - float radiusA = 5.0f; - Vec4 posB; - posB.x = vertices[i].x + radiusA/2.0f; - posB.y = vertices[i].y + radiusA/2.0f; - posB.z = vertices[i].z + radiusA/2.0f; - posB.w = vertices[i].w; - - Vec4 relPos = Vec4(posB.x - posA.x, posB.y - posA.y, posB.z - posA.z, 0); - float dist = sqrt(relPos.x * relPos.x + relPos.y * relPos.y + relPos.z * relPos.z); - float collideDist = radiusA + 0.0;//radiusB; - - - //Vec4 norm = (-0.707106, 0.707106, 0.0, 0.0); //this is actually a unit vector - Vec4 norm = Vec4(0.0, 1.0, 0.0, 0.0); - norm = normalize(norm); - Vec4 velA = velocities[i]; //velocity of particle - Vec4 velB = Vec4(0,0,0,0); //velocity of object - Vec4 relVel = Vec4(velB.x - velA.x, velB.y - velA.y, velB.z - velA.z, 0); - - float relVelDotNorm = relVel.x * norm.x + relVel.y * norm.y + relVel.z * norm.z; - Vec4 tanVel = Vec4(relVel.x - relVelDotNorm * norm.x, relVel.y - relVelDotNorm * norm.y, relVel.z - relVelDotNorm * norm.z, 0); - Vec4 force = Vec4(0,0,0,0); - float springFactor = -.5;//-spring * (collideDist - dist); - float damping = 1.0f; - float shear = 1.0f; - float attraction = 1.0f; - force = Vec4( - springFactor * norm.x + damping * relVel.x + shear * tanVel.x + attraction * relPos.x, - springFactor * norm.y + damping * relVel.y + shear * tanVel.y + attraction * relPos.y, - springFactor * norm.z + damping * relVel.z + shear * tanVel.z + attraction * relPos.z, - 0 - ); - - //float mag = sqrt(vel.x*vel.x + vel.y*vel.y + vel.z*vel.z); //store the magnitude of the velocity - //vel /= mag; - //vel = 2.f*(dot(normal, vel))*normal - vel; - ////vel *= mag; //we know the direction lets go the right speed - - velA.x += force.x; - velA.y += force.y; - velA.z += force.z; - - xn = vertices[i].x + h*velA.x; - yn = vertices[i].y + h*velA.y; - zn = vertices[i].z + h*velA.z; - velocities[i] = velA; - } + velA.x += force.x; + velA.y += force.y; + velA.z += force.z; + + xn = pos.x + h*velA.x; + yn = pos.y + h*velA.y; + zn = pos.z + h*velA.z; + velocities[i] = velA; + */ } + //} vertices[i].x = xn; vertices[i].y = yn; vertices[i].z = zn; + /* colors[i].x = 1.f; @@ -229,6 +268,7 @@ int EnjaParticles::cpu_update() //colors[i].w = 1-life; colors[i].w = 1; */ + velocities[i] = vel; //save the life! velocities[i].w = life; //((Vec4*)vertices_p)[i] = vertices[i]; @@ -239,9 +279,9 @@ int EnjaParticles::cpu_update() glFinish(); glBegin(GL_TRIANGLES); - glVertex3f(tri1[0].x, tri1[0].y, tri1[0].z); - glVertex3f(tri1[1].x, tri1[1].y, tri1[1].z); - glVertex3f(tri1[2].x, tri1[2].y, tri1[2].z); + glVertex3f(tri[0].x, tri[0].y, tri[0].z); + glVertex3f(tri[1].x, tri[1].y, tri[1].z); + glVertex3f(tri[2].x, tri[2].y, tri[2].z); glEnd(); diff --git a/enjacl/render.cpp b/enjacl/render.cpp index ca12f7e9..b25df523 100644 --- a/enjacl/render.cpp +++ b/enjacl/render.cpp @@ -65,7 +65,8 @@ int EnjaParticles::render() for(int i = 0; i < updates; i++) { - cpu_update(); //call the particle update function (executes the opencl) + update(); //call the particle update function (executes the opencl) + //cpu_update(); } ts[0]->stop();