By Sceada
on Wed, 06/20/2012 - 17:11
Hi Qulacomm community!
I worked a little bit on my AR-App for my Bachelor Thesis.
I tried several things, with mixed results.
First I calculated a natural cubic spline for some nice looking movements. Theoretical a nice idea, practical a absolute distaster :).
Then I wanted to improve my Tap-Event with a ray picking solution.
I Managed to get a BoundingBox from an Object at runtime:
[CODE]void
calculateBoundingBox()
{
int i = 0;
float MaxX = uSchiffOneTextureVerts[i] , MinX = uSchiffOneTextureVerts[i] , MaxY = uSchiffOneTextureVerts[i+1] , MinY = uSchiffOneTextureVerts[i+1] , MaxZ = uSchiffOneTextureVerts[i+2] , MinZ = uSchiffOneTextureVerts[i+2];
for (i = 0; i < (uSchiffOneTextureNumVerts); i+=3)
{
//Min/Max Berechnung für die X Werte innerhalb des Float Arrays
if (uSchiffOneTextureVerts[i] <= MinX)
{
MinX = uSchiffOneTextureVerts[i];
} else if (uSchiffOneTextureVerts[i] > MaxX)
{
MaxX = uSchiffOneTextureVerts[i];
}
//Min/Max Berechnung für die Y Werte innerhalb des Float Arrays
if (uSchiffOneTextureVerts[i+1] <= MinY)
{
MinY = uSchiffOneTextureVerts[i+1];
} else if (uSchiffOneTextureVerts[i+1] > MaxY)
{
MaxY = uSchiffOneTextureVerts[i+1];
}
//Min/Max Berechnung für die Z Werte innerhalb des Float Arrays
if (uSchiffOneTextureVerts[i+2] <= MinZ)
{
MinZ = uSchiffOneTextureVerts[i+2];
} else if (uSchiffOneTextureVerts[i+2] > MaxZ)
{
MaxZ = uSchiffOneTextureVerts[i+2];
}
}
LOG("MinX: %f, MaxX: %f, MinY: %f, MaxY: %f, MinZ: %f, MaxZ: %f",MinX, MaxX, MinY, MaxY, MinZ, MaxZ);
float BB[] = {
//front
MaxX, MaxY, MaxZ, //P7
MaxX, MinY, MaxZ, //P3
MinX, MaxY, MaxZ, //P1
MinX, MinY, MaxZ, //P5
MinX, MaxY, MaxZ, //P1
MaxX, MinY, MaxZ, //P3
//back
MaxX, MaxY, MinZ, //P8
MaxX, MinY, MinZ, //P4
MinX, MaxY, MinZ, //P2
MinX, MinY, MinZ, //P6
MinX, MaxY, MinZ, //P2
MaxX, MinY, MinZ, //P4
//top
MaxX, MaxY, MaxZ, //P7
MinX, MaxY, MaxZ, //P1
MinX, MaxY, MinZ, //P2
MaxX, MaxY, MinZ, //P8
MaxX, MaxY, MaxZ, //P7
MinX, MaxY, MinZ, //P2
//bottom
MaxX, MinY, MaxZ, //P3
MinX, MinY, MaxZ, //P5
MinX, MinY, MinZ, //P6
MaxX, MinY, MinZ, //P4
MaxX, MinY, MaxZ, //P3
MinX, MinY, MinZ, //P6
//right
MaxX, MaxY, MaxZ, //P7
MaxX, MinY, MaxZ, //P3
MaxX, MinY, MinZ, //P4
MaxX, MaxY, MinZ, //P8
MaxX, MinY, MinZ, //P4
MaxX, MaxY, MaxZ, //P7
//left
MaxX, MaxY, MaxZ, //P1
MaxX, MinY, MaxZ, //P5
MaxX, MinY, MinZ, //P6
MaxX, MaxY, MinZ, //P2
MaxX, MinY, MinZ, //P6
MaxX, MaxY, MaxZ //P1
};
int size = sizeof(BB) / sizeof(float);
LOG("Size: %i",size);
for(int count=0; count < size ; count++)
{
LOG("Size: %i",count);
BBUebergabe[count] = BB[count];
};
}[/CODE]
Any Improvements are welcome!
With the gathered vertices i tried to draw colored triangles:
[IMG]http://sceada.bplaced.net/vuforia/ShipInABox.png[/IMG]
My actual purpose is to implement a ray-box-intersection. In fact that the 2D solution makes a lot of problems, if the 3D-Object is watched from the side.
I copied two methods from the domino example
[LIST]
[*]projectScreenPointToPlane
[*]linePlaneIntersection
[/LIST]
I solved the actual Tap-Event a little bit different than in the domino example, anywhere.
I implemented a lot of Log messages for some tests .
[QUOTE]04-14 12:23:16.070: I/IMAGE_TARGETS(944): MinX: -0.072848, MaxX: 0.069527, MinY: -0.175295, MaxY: 0.082582, MinZ: -0.258850, MaxZ: 0.222944
04-14 12:23:16.070: I/IMAGE_TARGETS(944): Size: 108
04-14 12:23:17.200: I/IMAGE_TARGETS(944): Configure Video Background : Video (640,480), Screen (480,800), mSize (600,800)
04-14 12:23:17.430: I/IMAGE_TARGETS(944): getFocalLength(): 617.117981, 618.848022
04-14 12:23:17.430: I/IMAGE_TARGETS(944): getPrincipalPoint(): 320.000000, 240.000000
04-14 12:23:17.430: I/IMAGE_TARGETS(944): getDistortionParameters(): 0.154197, -0.377212, -0.001747, -0.000489
04-14 12:23:19.960: I/IMAGE_TARGETS(944): tapx: 169.857819, tapy: 366.257507
04-14 12:23:19.960: I/IMAGE_TARGETS(944): halfScreenWidth: 240.000000
04-14 12:23:19.960: I/IMAGE_TARGETS(944): halfScreenHeight: 400.000000
04-14 12:23:19.960: I/IMAGE_TARGETS(944): halfViewportWidth: 300.000000
04-14 12:23:19.960: I/IMAGE_TARGETS(944): halfViewportHeight: 400.000000
04-14 12:23:19.960: I/IMAGE_TARGETS(944): x: -0.233807
04-14 12:23:19.960: I/IMAGE_TARGETS(944): y: 0.084356
04-14 12:23:19.960: I/IMAGE_TARGETS(944): lineStart.data[0]: -0.361336, lineStart.data[1]: 0.717794, lineStart.data[2]: 0.337030
04-14 12:23:19.960: I/IMAGE_TARGETS(944): lineEnd.data[0]: 3.171073, lineEnd.data[1]: -7.679066, lineEnd.data[2]: -3.885688
04-14 12:23:19.960: I/IMAGE_TARGETS(944): intersection.data[0]: -0.079402, intersection.data[1]: 0.047611, intersection.data[2]: 0.000000
//2D Solution.
04-14 12:23:19.960: I/ImageTargets(944): ToucEvent X: 169.85782| Detect X: 229.65517
04-14 12:23:19.960: I/ImageTargets(944): ToucEvent Y: 366.2575| Detect Y: 450.0[/QUOTE]
Looks something wrong for you guys?
How can I imagine the lineEnd, lineSTart and intersection vector? Why is everything normalized to -1 and 1?
How can i do a ray cast with these values, anyone an idea?
To my actual thread title.
I want to display my BoundingBox without any filling.
I tried the following shading:
[QUOTE]static const char* PointVertexShader = " \
\
attribute vec4 PointvertexPosition; \
uniform mat4 modelViewProjectionMatrix; \
\
void main() \
{ \
gl_Position = modelViewProjectionMatrix * PointvertexPosition; \
} \
";
static const char* PointFragmentShader = " \
\
precision mediump float; \
void main() \
{ \
gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); \
} \
";[/QUOTE]
And
[QUOTE]/*for(int i = 0; i < 12; i++)
glDrawArrays(GL_TRIANGLE_STRIP, i*3, 4);*/[/QUOTE]
But nothing is drawn at runtime.
I Know it is saturday and I have a lot of questions, hopefully I get all of them answered :p.
- Robert
Re: Rendering Lines