[QUOTE=ZeekyHBomb;25218806][CODE]
//minimum int might not be able to hold the number, long will though
long encrypt(unsigned char n)
{
long binary = 0, i = 1e7l;
for(uint8_t mask = 1 << 7; mask != 0; mask >>= 1, i /= 10)
{
if((n & mask) != 0) //mask out a single bit
{
binary += i;
n &= ~mask; //remove the bit by using and on the inversed mask
}
}
return binary;
}[/CODE][/QUOTE]
That gives me 12 errors and 1 warning, and I also have no idea what your doing there.
I'm currently working on some interpolation method to simulate connected cables. Cubic interpolation yields the following results:
[img_thumb]http://dl.dropbox.com/u/2399384/interp.png[/img_thumb]
However, as you see, the cable isn't perpendicular to the sockets at the end points. This is my interpolation function:
[lua]local function cubicInterpolate( x1, y1, x2, y2, x3, y3, x4, y4, resolution )
local points = {}
local a0, a1, a2, a3, mu2
for mu = 0, 1, resolution do
mu2 = mu * mu
a0 = y4 - y3 - y1 + y2
a1 = y1 - y2 - a0
a2 = y3 - y1
a3 = y2
table.insert( points, Vector( ( x3 - x2 ) * mu + x2, a0 * mu * mu2 + a1 * mu2 + a2 * mu + a3 ) )
end
return points
end[/lua]
For ( x2, y2 ) I use the point where the cable leaves the first socket and for ( x3, y3 ) I use the point where the cable enters the second socket. ( x1, y1 ) are the coordinates of the other side of socket #1 and ( x4, y4 ) the coordinates of the other side of socket #2. So:
[img]http://dl.dropbox.com/u/2399384/interp2.png[/img]
What should I do to get the two end points perpendicular?
Is there a way to invoke a method on every element of the List in C#?
Something like foreach but not using a static method and the element being passed as a parameter but a method that belongs to the type the List holds.
For example if I had a Mesh class that has a Render method and a list of meshes, I want to call Render() on all of them.
Of course I know how to do it manually but I somehow think it would be in .NET's style to include something that does that with one function call and probably more efficient internally.
[QUOTE=Darwin226;25224345]Is there a way to invoke a method on every element of the List in C#?
Something like foreach but not using a static method and the element being passed as a parameter but a method that belongs to the type the List holds.
For example if I had a Mesh class that has a Render method and a list of meshes, I want to call Render() on all of them.
Of course I know how to do it manually but I somehow think it would be in .NET's style to include something that does that with one function call and probably more efficient internally.[/QUOTE]
No, there aren't any more efficient method than foreach. Most extension methods to list use deferred execution anyway, meaning they aren't evaluated until you iterate over them.
Yea... turns out the iteration wasn't the bottleneck. For some reason it takes OpenGL 0.03 ms to render 2 triangles. That seems way too long.
[QUOTE=Overv;25223725]I'm currently working on some interpolation method to simulate connected cables. Cubic interpolation yields the following results:
[img_thumb]http://dl.dropbox.com/u/2399384/interp.png[/img_thumb]
However, as you see, the cable isn't perpendicular to the sockets at the end points. This is my interpolation function:
[lua]local function cubicInterpolate( x1, y1, x2, y2, x3, y3, x4, y4, resolution )
local points = {}
local a0, a1, a2, a3, mu2
for mu = 0, 1, resolution do
mu2 = mu * mu
a0 = y4 - y3 - y1 + y2
a1 = y1 - y2 - a0
a2 = y3 - y1
a3 = y2
table.insert( points, Vector( ( x3 - x2 ) * mu + x2, a0 * mu * mu2 + a1 * mu2 + a2 * mu + a3 ) )
end
return points
end[/lua]
For ( x2, y2 ) I use the point where the cable leaves the first socket and for ( x3, y3 ) I use the point where the cable enters the second socket. ( x1, y1 ) are the coordinates of the other side of socket #1 and ( x4, y4 ) the coordinates of the other side of socket #2. So:
[img]http://dl.dropbox.com/u/2399384/interp2.png[/img]
What should I do to get the two end points perpendicular?[/QUOTE]
Is that meant to be a Cubic Bézier curve or something else ? If so then surly you just need to space the control points further out. (I.e. Move P1 and P2 away from the edge in this image: [url]http://upload.wikimedia.org/wikipedia/commons/d/d0/Bezier_curve.svg[/url])
You aren't actually using X1 or X4 in your algorithm which leads me to believe that it would behave differently on edges aligned with the X axis and than it would with edges aligned with the Y axis.
[QUOTE=TBleader;25223675]That gives me 12 errors and 1 warning, and I also have no idea what your doing there.[/QUOTE]
Forgot to change the uint8_t in the for-loop back to unsigned char.
[cpp]//minimum int might not be able to hold the number, long will though
long encrypt(unsigned char n)
{
long binary = 0, i = 1e7l; //1e7l -> 1e7 means a 1 with 7 zeros appended (1 * 10^7), l is the suffix for longs
for(unsigned char mask = 1 << 7; mask != 0; mask >>= 1, i /= 10) //set mask to 0b10000000 (ob -> binary representation) by taking 1 and shifting the bits 7 times to the left
//the loop will execute as long as mask != 0 and for each iteration shift the mask-bits one step to the right and divide i by 10 (e.g. removing a zero)
{
if((n & mask) != 0) //mask out a single bit
{
binary += i;
n &= ~mask; //remove the bit by using and on the inversed mask
}
}
return binary;
}[/cpp]
If you have further questions how the algorithm works, do ask.
[editline]07:25PM[/editline]
[QUOTE=Darwin226;25225268]Yea... turns out the iteration wasn't the bottleneck. For some reason it takes OpenGL 0.03 ms to render 2 triangles. That seems way too long.[/QUOTE]
Well, the API call is 0.03ms. The rendering should be offloaded to your hardware - if you have hardware accelerated OpenGL rendering available on your machine.
This can very well mean that upon adding further triangles that it can stay at 0.03ms for the API call (if you already have uploaded the vertex data).
Yeah, that's what I figured.
Still, 0.03ms for a few function calls?
[QUOTE=ZeekyHBomb;25225846]Forgot to change the uint8_t in the for-loop back to unsigned char.
[CODE]//minimum int might not be able to hold the number, long will though
long encrypt(unsigned char n)
{
long binary = 0, i = 1e7l; //1e7l -> 1e7 means a 1 with 7 zeros appended (1 * 10^7), l is the suffix for longs
for(unsigned char mask = 1 << 7; mask != 0; mask >>= 1, i /= 10) //set mask to 0b10000000 (ob -> binary representation) by taking 1 and shifting the bits 7 times to the left
//the loop will execute as long as mask != 0 and for each iteration shift the mask-bits one step to the right and divide i by 10 (e.g. removing a zero)
{
if((n & mask) != 0) //mask out a single bit
{
binary += i;
n &= ~mask; //remove the bit by using and on the inversed mask
}
}
return binary;
}[/CODE][/QUOTE]
Using that, how would you convert it back into the number? I have it set up to read the file and store each line as a var, then to decrypt it.
I'm having some trouble with SFML .Net bindings. Does someone have a tutorial, or at least a working documentation ?
[QUOTE=TBleader;25226986]Using that, how would you convert it back into the number? I have it set up to read the file and store each line as a var, then to decrypt it.[/QUOTE]
You would divide by 10 and check the remainder, e.g. modulus operator (%), and add to the char accordingly with a similar loop.
It helps to put the numbers on paper and try to work out how you would do it and then simply translate the algorithm into C++/programming language of your choice.
As you read and write files, strings will probably make the solution easier.
[editline]08:30PM[/editline]
[QUOTE=pikzen;25227175]I'm having some trouble with SFML .Net bindings. Does someone have a tutorial, or at least a working documentation ?[/QUOTE]
I would imagine that the C++ interface is not that much different from the .NET port of SFML. Could be wrong though; did you try the official C++ tutorial?
Also, for C++ the code is commented using Doxygen comments, so creating a documentation would simply require invoking doxygen. Is this not the case for the .NET port? Or yet again, maybe the C++ documentation suffices.
[QUOTE=ZeekyHBomb;25227273]You would divide by 10 and check the remainder, e.g. modulus operator (%), and add to the char accordingly with a similar loop.
It helps to put the numbers on paper and try to work out how you would do it and then simply translate the algorithm into C++/programming language of your choice.
As you read and write files, strings will probably make the solution easier.
[/QUOTE]
Putting it on paper isn't helping, as when I divide by ten, the remainder is whatever the digit was. And I do not get how to put it into a similar formula like you did. Also what do you mean strings will make it easier? The only way i can do it on paper is to multiply.
Like take the number 1011 1111, I would do (1 * 128) + (0 * 64) + (1 * 32) + (1 * 16) + (1 * 8) + (1 * 4) + (1 * 2) + (1 * 1) and get 128 + 32 + 16 + 8 + 4 + 2 + 1 = 191.
[QUOTE=yngndrw;25225562]If so then surly you just need to space the control points further out.[/QUOTE]
Thanks, that worked.
[QUOTE=TBleader;25227427]Putting it on paper isn't helping, as when I divide by ten, the remainder is whatever the digit was. And I do not get how to put it into a similar formula like you did. Also what do you mean strings will make it easier? The only way i can do it on paper is to multiply.
Like take the number 1011 1111, I would do (1 * 128) + (0 * 64) + (1 * 32) + (1 * 16) + (1 * 8) + (1 * 4) + (1 * 2) + (1 * 1) and get 128 + 32 + 16 + 8 + 4 + 2 + 1 = 191.[/QUOTE]
How my solution works:
[code]n = 0b10111111
mask = 0b10000000
i = 10000000
binary = 0
first iteration:
n & mask:
0b10111111 &
0b10000000
=
0b10000000 != 0
-> binary += i: binary = 10000000
-> n &= ~mask:
~mask: ~0b10000000 = 0b01111111
0b10111111 &
0b01111111
=
0b00111111
mask >>= 1: mask = 0b01000000
i /= 10: i = 1000000
second iteration:
0b00111111 &
0b01000000
=
0b00000000
mask >>= 1: mask = 0b00100000
i /= 10: i = 100000
third iteration:
0b00111111 &
0b00100000
=
0b00100000 != 0
-> binary += i: binary = 10100000
-> n &= ~mask:
~mask: ~0b00100000 = 0b11011111
0b00111111 &
0b11011111
=
0b00011111
mask >>= 1: mask = 0b00010000
i /= 10: i = 10000
ect.[/code]
& is bitwise and, ~ is bitwise negation in case you did not know.
<< and >> simply shift the bits in the direction those angle brackets are pointing (leftshift and rightshift).
What you need to do now is using the modulus operator to find out the remainder of a result.
e.g.
[code](three bit value for easy)
precondition:
mask = 0b001
n = 100
looping:
n % 10 = 0
divide n by 10 -> n = 10
left-shift mask -> mask = 0b010
n % 10 = 0
divide n by 10 -> n = 1
left-shift mask -> mask = 0b100
1 % 10 = 1 -> oh look, a 1 -> add mask to solution[/code]
% is the modulus operator.
[QUOTE=Darwin226;25226141]Yeah, that's what I figured.
Still, 0.03ms for a few function calls?[/QUOTE]
Yeah, that's fairly quick.
That's somewhere around 30,000 calls per second.
[QUOTE=turb__;25238995]Yeah, that's fairly quick.
That's somewhere around 30,000 calls per second.[/QUOTE]
Don't you mean 3300?
[QUOTE=esalaka;25239610]Don't you mean 3300?[/QUOTE]
Nope, 1000ms / 0.03ms = 33,333 1/3
[QUOTE=turb__;25239652]Nope, 1000ms / 0.03ms = 33,333 1/3[/QUOTE]
Oh.
Oh, I missed a zero. Nevermind.
I need a simple way to use the vibration motors on a game controller. Mostly wondering if it can be done with PyGame. If not PyGame, SDL in general.
[QUOTE=pkt;25240025]I need a simple way to use the vibration motors[/QUOTE]
:q:
Just starting to learn java, how do I make it so the user can input a variable?
For example, if i wanted to ask "What is your favorite number?" the user can put their favorite number in and it's stored as what was a variable.
Actually Turb I need to use the analog output that the vibration motors from a PS2 controller interfaced with a pc use to interface with other types of hardware. I can technically use em with the drivers with the hardware but that's not programmable.
[QUOTE=GunsNRoses;25240281]Just starting to learn java, how do I make it so the user can input a variable?
For example, if i wanted to ask "What is your favorite number?" the user can put their favorite number in and it's stored as what was a variable.[/QUOTE]
[url]http://www.google.com/search?q=java+user+input[/url]
Was it really that hard?
With iPhone developing, when a method finishes, are all variables and other memory-using resources automatically cleared?
[QUOTE=pkt;25240685]Actually Turb I need to use the analog output that the vibration motors from a PS2 controller interfaced with a pc use to interface with other types of hardware. I can technically use em with the drivers with the hardware but that's not programmable.[/QUOTE]
You should form it into a long cylindrical shape and have fun with it.
[editline]07:44PM[/editline]
and by that i mean stick it up your pooper
Anyone have any links to good OpenGL tutorials? I heard NeHe uses outdated methods or something.
I want to add C# scripting to my game that would work kinda like shaders do. A few input variables and a few output variables. The script would take the input, run the code and return the output.
How would I do that?
Googling "c# runtime compilation" and "c# scripting" didn't really show me anything useful. At least I didn't think it was.
[QUOTE=BlkDucky;25245343]Anyone have any links to good OpenGL tutorials? I heard NeHe uses outdated methods or something.[/QUOTE]
They don't exist, sadly.
You kind of have to google around for each thing individually, using the OGL3/4 reference as a guide.
The general process goes something like this:
[list=1]
[*]Create an OpenGL context (SDL can do this for you)
[*]Create a default shader program. The most basic vertex shader takes a vertex position and multiplies it by the model/view/projection matrices. The most basic fragment shader outputs a constant color. (The [url=http://en.wikipedia.org/wiki/GLSL]wikipedia article on GLSL[/url] actually lists examples of these "trivial" shaders)
[*]Create a projection matrix (and model/view if you use them). In OpenGL 2.x, built-in matrix functions are still available. In >=3.0, you need to write your own matrix routines or use external math libraries. (This sounds stupid, but it actually simplifies the API greatly and makes things a lot more flexible. You'll learn to like it.)
[*]Load vertex data with glVertexPointer.
[*]Enable vertex arrays with glEnableClientState.
[*]Render directly:
[list=a]
[*]Execute glDrawArrays.
[/list]
or by index:
[list=a]
[*]Load vertex indices with glIndexPointer
[*]Execute glDrawElements
[/list]
[/list]
There are more advanced topics, such as texture mapping, VBO/FBOs, blending, etc., but the basic outline listed above applies to [i]everything[/i].
[QUOTE=ROBO_DONUT;25245567][list=1]
[*]Create an OpenGL context (SDL can do this for you)[/LIST][/QUOTE]
Only the latest versions. If done by yourself, at least on Windows it involves creating an old-style context, creating a new-style context and then removing the old-style context.
[QUOTE=esalaka;25245684]Only the latest versions.[/QUOTE]
If by "latest" you mean "for the last ten years".
Sorry, you need to Log In to post a reply to this thread.