Hi guys,
Here is my end-objective: I have a very large terrain array of Vector3s (~2 million) and what I want to do is find the transformation matrix that would result in the smallest total lengths of all of these vectors relative to the origin (aka distance from vector to the origin). Yup, simply adding them all together.
I can perform this in a brute-force way in C#. but it takes minutes! What I do here is take each element of the matrix that represents translation (no rotation allowed in this application) and slowly increment them from, say, -5.0 to 5.0 individually (with some delta like 0.01) so that all combinations have been tested and I store the total lengths of the vertices after transforming them by this matrix.
The pseudo-code approach looks something like this:
float total = 0
float delta = 0.01
for(matrix_translate_x -5.0 -> 5.0)
for(matrix_translate_y -5.0 -> 5.0)
for(matrix_translate_z -5.0 -> 5.0)
for each vector
transform vector by matrix
add length to total
I'm wondering if there is a way to perform this lightning fast using HLSL. I understand how to do calculations with float3s and float4x4s in the language, but what I don't know how to do store the results of each iteration so a final solution can be determined after the GPU process all of the vertices. So far I have these vertices in a heightmap which I render to a rendertarget to analyze the results.
Is using HLSL for this application feasible? Ideally this would take one render since -5 to 5 on 3 axis is 100,000 combinations using 0.01 as a delta! I'm also open to other suggestions not using HLSL.
Thanks!
EDIT: I didn't anticipate there would be an easy math answer so I kind of simplified my question for brevity! See reply #1.
This "terrain" I spoke of exists as a cloud of 3D points scattered in a tube fashion along the X axis. I can independently move both ends of this tube (like holding onto both ends of a broomhandle and moving your arms) in the Y and Z direction to try to find the smallest total length as I wrote above. So there would actually be two vectors, one at X=0 and one at X=max_x. All points in between 0 and max_x will be interpolated between the two solution vectors. So in truth we kind of can "rotate" here. Does that make sense at all?
I assumed if I could figure out the principles in HLSL I could apply it to my problem completely. Sorry to confuse.
[By the way, I also posted this question (copy/paste) on the XNA community forums. Is that bad forum etiquette? I'm new to this sort of thing...]