
Advertisement
Premandrake
Member
Content Count
330 
Joined

Last visited
Community Reputation
175 NeutralAbout Premandrake

Rank
Member
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.

[.net] Silverlight XAML resource management
Premandrake replied to CyberSlag5k's topic in General and Gameplay Programming
Well, if this were WPF, you could just have a ResourceDictionary and include it in the MergedDictionaries, but alas :). In Silverlight, it's a bit trickier. Your best option to have shared styles across DLL's is to have a common DLL that has your App.xaml in it. Silverlight supports resolving App.xaml resources with {StaticResource}. 
[.net] Build problem vs2008
Premandrake replied to coolblue's topic in General and Gameplay Programming
Try this thread. 
It sounds like you are trying to find the great circle distance between the two points. Simplest solution is to use the formula given in the link above (remembering to convert your latitude/longitude to radians), and that will give you the distance. The "bearing" doesn't really have a meaning in spherical coordinates. Perhaps you are trying to interpolate between the two points? If so, you should use quaternions, as spherical linear interpolation follows the greatcircle arc at a constant speed. See here for a good background.

Quote:Original post by tKircher All i'm doing is taking the dot product of the two points (taking the x, y, z of each point as vectors and dotting those), then using sin, cos, and tan on the dot to get the three values i'm after. I figured an implicit magnitude of 1 would simplify the equation (divide by 1 is sorta redundant) Well, there are a few problems here :). First, the formula does not generalize to plug in sin/cos/tan/asin/atan, it only works with acos. Second, unless you are using normalized vectors, dividing by the magnitude is actually very important. The most serious problem, is I misread your question (went off the title of the post, not the content ;)). The formula I gave you will certainly compute the angle between two vectors. However, that's all it will do. jyk's post has some good ideas on how to accomplish this.

You are correct, a little trig. will do wonders here :). You are basically applying a rotation about the first edge to the mesh (since the rotation is in this plane, you can just use any point on the edge). See here for a good background of doing this. Or, if you already have a decent matrix/quaternion library, it should support building this matrix for you. First, you calculate the basis vectors for your rotation space. Your x basis is your "fixed" edge. The z basis is the vector between an endpoint on the first edge, and the adjacent vertex. The y basis is the perpendicular vector to these two (caclulate using the cross product). Basis vector explanation. Then transform an x rotation (with the angle of the slope) by your basis matrix, and convert it to rotate around the point. The apply that matrix to all the points to get the "top" face of the object.

a dot b = abcos(theta), where theta is the angle between the two vectors. So, to compute theta we need (forgive the bad ascii art): ( a dot b ) theta = acos() ( ab ) a dot b is just the 3d dot product, nice and efficient :). a is the magnitude of the vector a.

Woohoo! Another thread about topcoder :). I compete as gladius over there. I recommend trying a few of the practice problems out if you haven't tried something like it before.

float RandomToScaled(double r, double maximum) { return (r  0.5) * 2 * maximum; } Random random = new Random(); // This will return a number between 5000 and 5000. RandomToScaled(random.NextDouble(), 5000);

CatmullRom splines only need the two points surrounding the points you are interpolating between. Check out this page http://www.cubic.org/docs/hermite.htm for a nice overview of using splines for interpolation.

finding the number of SET bits in one line of code
Premandrake replied to GekkoCube's topic in General and Gameplay Programming
Or this one: int countBits(int num) { return num ? countBits(num & (num  1)) + 1 : 0; } Which if optimized for character count is pretty darn short: int c(int x){return x?c(x&x1)+1:0;} So, here is a new challenge, can anyone come up with a method that uses less characters? 
Finding Prime Numbers
Premandrake replied to Servant of the Lord's topic in General and Gameplay Programming
While we're at it, I figured I'd throw in my two cents :). Here is a sieve implementation I wrote a while back that is pretty fast, it calculates all the primes up to 10 million in less than a second on my machine. This code is not big endian safe. #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> const int MAXNUM=10000000; unsigned int sieve[MAXNUM/64 + 2]; void calcSieve() { for (int i=0; i<sizeof(sieve)>>2; i+=3) { sieve = 0x6DB6DB6D; sieve[i+1] = 0xDB6DB6DB; sieve[i+2] = 0xB6DB6DB6; } sieve[0] = 6; for (int i=2; 4*(i*i+i)+1<=MAXNUM; i++) { if (sieve[i>>5]&(1<<(i&31))) { int factor = (i<<1)+1; for (int j=factor+i; j<(MAXNUM/2)+1; j+=factor) { sieve[j>>5] &= ~(1<<(j&31)); } } } } bool isPrime(int num) { if (!(num&1) && num!=2) return false; num >>= 1; if (sieve[num>>5]&(1<<(num&31))) return true; return false; } bool isPrimeSlow(int num) { for (int i = 2; i*i <= num; i++) if (num % i == 0) return false; return true; } int main() { calcSieve(); //printf("Incorrect results:\n"); //for (int i = 1; i <= MAXNUM; i++) // if (isPrime(i) != isPrimeSlow(i)) printf("%d, ", i); //printf("\n"); printf("Primes less than 100:\n"); for (int i = 1; i <= 100; i++) if (isPrime(i)) printf("%d, ",i); printf("\n"); } 
finding the number of SET bits in one line of code
Premandrake replied to GekkoCube's topic in General and Gameplay Programming
int countBits(int num) { return num ? countBits(num>>1) + (num&1) : 0; } Does that count? ;) 
how to get doc or view object ?
Premandrake replied to derek7's topic in General and Gameplay Programming
You want to use your MainFrame class (CMDIFrameWnd or CSDIFrameWnd) to issue the ShowWindow() call. You can do something like the following: #include "mainfrm.h" CMainFrame *mainFrm = (CMainFrame*)AfxGetMainWnd(); pMainFrame>ShowWindow(SW_HIDE); 
Fonts, Localization , and the 360
Premandrake replied to tgraupmann's topic in Graphics and GPU Programming
I'd imagine the developer support at Microsoft might be able to better handle this type of question :). 
[.net] MDX 2.0 DirectSound PrimaryBuffer
Premandrake replied to Ampaze's topic in General and Gameplay Programming
It does look like there is a bug in the Buffer code (but I'm not sure of the intent). In the ctor(Device, Buffer) it does the following: // Oops, accessing .Value without having checked .HasValue first ref void modopt(IsExplicitlyDereferenced) pinned local1 = &description.WaveFormat.Value; if (description.WaveFormat.HasValue) { *((int*) (_dsbufferdescPtr1 + 0x10)) = local1; } int num1 = **(((int*) device.pComPtr))[12](device.pComPtr, _dsbufferdescPtr1, local2, 0); if (description.WaveFormat.HasValue) { memcpy(local1, *((void modopt(IsConst)**) (_dsbufferdescPtr1 + 0x10)), 0x12); } A related note, Reflector has saved my bacon many times in the past. That's how I got the information above.

Advertisement