I need help with C# Tcp [url]http://facepunch.com/showthread.php?t=1402159&p=45127242[/url] :(
Really badly, I'm so lost :P
Hey guys, so not really sure if this belongs in the Web or the Programming, since it's kind of an intersection between the two.
Basically, though, I decided to build a little Java application using the Tumblr API, which allows a blog the client owns to serve as a sort of hub, where the program will reblog new posts from any blog that the hub follows.
The application works fine, but it is currently tied to my test blog.
How the hell would I work Tumblr's cryptic consumer_key / consumer_secret / oauth_key / oauth_secret to allow it so that [b]anyone[/b] could use the application?
Having each individual person register an application with Tumblr to get an oauth key, just so they can have the program reblog for them, seems a bit overly complex to me.
I am not at all satisfied with how poorly documented Tumblr's API is about this whole mess. Took me forever just to figure out how to get Jumblr working properly (and it technically still doesn't work quite correctly - it does its job, but it throws NullPointerExceptions that I have to catch and ignore for some reason :v:).
[editline]fish[/editline]
So I've figured most of it out.
Using Scribe and the Tumblr example it provides, it sends you to a website to verify the application using your log-in (which makes sense). From what I can gather, it is [b]supposed[/b] to then take you to a website that displays a "verification code", which you then paste into the program and it uses to generate your oauth token / secret. However, the URL that the example uses goes to a "page not found" - though the verifier can actually be found in the resulting URL, as "&verifier=blahblahblah".
Does anyone know how to make it not be retarded, and make it actually display that verifier properly? Or better yet, circumvent that entirely and just have the program automatically grab that verifier and then generate the oauth token, once the client has verified the application using your log-in? :v:
Hey guys I've been working on a simple game engine in C# for about a week and have been having no luck with skeletal animation.
I am currently loading the Source Engine's ".smd" file. Everything loads correctly as far as I know, the only problem I am having currently getting the matrix calculations for the final vertex.
I have been using this post to get the algorithm to calculate the final vertex matrix: [URL="http://stackoverflow.com/questions/10864453/importing-3d-skeletal-animations-from-smd-model"]http://stackoverflow.com/questions/10864453/importing-3d-skeletal-animations-from-smd-model[/URL]
My process is as follows:
I load the bones, triangles, etc.
Assign assign the bones parents and children:
[code]
...
for (int i = 0; i < skeleton.Length; i++)
{
Bone bone = skeleton[i];
if (bone.parentid != -1)
{
bone.parent = skeleton[skeleton[i].parentid];
bone.parent.children.Add(bone);
}
}
...
[/code]
Create the all bones initial at rest matrix using the bones position and rotation given in the ".smd."
[code]
...
for (int i = 0; i < skeleton.Length; i++)
{
Bone bone = skeleton[i];
bone.TransformAtRest = GetTransform(frames[0].bone_pos[i], frames[0].bone_rot[i]);
}
...
public Matrix4 GetTransform(Vector3 pos, Vector3 rot)
{
Matrix4 translation = Matrix4.CreateTranslation(pos);
Matrix4 rotx = Matrix4.CreateRotationX(rot.X);
Matrix4 roty = Matrix4.CreateRotationY(rot.Y);
Matrix4 rotz = Matrix4.CreateRotationZ(rot.Z);
return (rotx * roty * rotz) * translation;
}
[/code]
Calculate the bones world position by starting at the origin bone and iterating over the children.
[code]
...
//Inside model loader class.
skeleton[1].CalculateChildrenAtRestPositions();
...
//Inside bone class.
public void CalculateChildrenAtRestPositions()
{
foreach (Bone child in children)
{
child.TransformAtRest = child.TransformAtRest * TransformAtRest;
child.CalculateChildrenAtRestPositions();
}
}
[/code]
Invert the at rest matrices in all bones.
[code]
for (int i = 0; i < skeleton.Length; i++)
{
Bone bone = skeleton[i];
bone.TransformAtRest = Matrix4.Invert(bone.TransformAtRest);
}
[/code]
Then each frame per second I update all of the bones current positions.
[code]
float frame = 0;
//I understand some of this doesn't have to be caluclated every frame, but I'm currently just trying to get this working before I optimize anything.
public void CalculateBonePositions()
{
frame += 0.5f;
if (frame > 50)
{
frame -= 48;
}
for (int i = 0; i < skeleton.Length; i++)
{
Bone bone = skeleton[i];
bone.Transform = GetTransform(frames[(int)frame].bone_pos[i], frames[(int)frame].bone_rot[i]);
}
skeleton[1].CalculateChildrenPositions();
}
[/code]
Finally I render the mesh around the skeleton, or rather attempt too.
[code]
//I know using immediate mode is very bad performance wise, but as stated before I'm currently just trying to get this working for now.
for (int i = 0; i < triangles.Length; i++)
{
GL.Begin(PrimitiveType.Triangles);
Triangle triangle = triangles[i];
for (int j = 0; j < 3; j++)
{
Matrix4 transform = Matrix4.Zero;
Matrix4 pos = Matrix4.CreateTranslation(triangle.points[j]);
List<Weight> weights = triangle.weights[j];
foreach (Weight weight in weights)
{
transform += weight.bone.Transform * weight.bone.TransformAtRest * pos * weight.value;
}
GL.Color3(triangle.normals[j]);
GL.TexCoord2(triangle.uvs[j]);
GL.Vertex3(transform.ExtractTranslation());
}
GL.End();
}
[/code]
Unfortunately this is my output:
[IMG]http://i62.tinypic.com/2jg6m2g.jpg[/IMG]
From the work and testing I have done so far I am positive that vertex positions are loading correctly and that bones are loading and being calculated correctly.
I believe the problem has to do with how I am calculating the transform for the vertex position.
Any help on this matter would be greatly appreciated.
Side note, this is actually the first time in all my years of programming I have given in and posted somewhere asking for help. :v:
[QUOTE=Fergeh;45104568]I'm learning python and having a crack at the Euler problems:
For problem 3 where you have to find the prime factors of a number I've got this:
[CODE]def prime(x):
if x == 0 or x == 1:
return False
for i in range(x/2,1,-1):
if x % i == 0:
return False
return True
i = 131950000
prime_fact = []
for x in range (i/2,1,-1):
if i % x == 0 and prime(x):
prime_fact.append(x)
print prime_fact
[/CODE]
which works fine for small numbers, but I assume the sort of brute force iterating through every value method I'm using falls apart for bigger values like the one they want you to use.
When I tried to get the answer for 600851475143 my computer locked up. Any hints on what direction to go?[/QUOTE]
Well, first, you should probably count upwards rather than downwards. This is due to the fact that it is relatively easy to check if the prime factors you've found are all the prime factors of a number (and hence no factors remain). A good algorithm for factoring integers is to count upwards from 2. If you find a divisor, divide the number you have with the divisor and continue searching for prime factors in the result. When 1 remains, you've found all prime factors. Oh, and with this particular algorithm, all factors you find are automatically prime. The algorithm would look like this in Python:
[CODE]
i = 131950000
prime_fact = []
x = 2
while i != 1:
if i % x == 0:
prime_fact.append(x)
i /= x
else:
x += 1
print prime_fact
[/CODE]
The construction of the algorithm relies on some introductory number theory, though. I wouldn't say Project Euler is a terribly great way to learn a new language like Python (most likely, of course based on your intentions).
So I'm primarily a hardware person, but seem to have far more free time than money to spend on it lately. Looking to take a shot at programming for the first time in years. Can anyone suggest a language for me to start up in? Preferably something I can make some shit to help with general productivity or just generally useful(/less) programs with?
[QUOTE=Levelog;45139735]So I'm primarily a hardware person, but seem to have far more free time than money to spend on it lately. Looking to take a shot at programming for the first time in years. Can anyone suggest a language for me to start up in? Preferably something I can make some shit to help with general productivity or just generally useful(/less) programs with?[/QUOTE]
For general productivity? Try Python.
[QUOTE=ECrownofFire;45139746]For general productivity? Try Python.[/QUOTE]
That's what I was thinking. Although I admittedly am not terribly familiar with the primary application of a good amount of languages, so figured I'd post here.
I agree, Python is great for writing quick useful scripts.
For full featured applications with GUI I would go with a C-like language, C#, C++, C.. etc.
Alright, I'll have a go at Python then. Is it too early to be super cool and turn [URL="http://www.newegg.com/Product/Product.aspx?Item=N82E16824160162"]my monitor[/URL] vertically?
No, that's not cool. Cool is when you program with vim on a headless system via ssh over at least 6 different VPN's while using hardware from the 90's.
But in that case Python is not acceptable, pick one of [URL="http://en.wikipedia.org/wiki/Esoteric_programming_language"]these. [/URL]
[QUOTE=reevezy67;45139865]No, that's not cool. Cool is when you program with vim on a headless system via ssh over at least 6 different VPN's while using hardware from the 90's.
But in that case Python is not acceptable, pick one of [URL="http://en.wikipedia.org/wiki/Esoteric_programming_language"]these. [/URL][/QUOTE]
Oh god. That's great.
Is python lightweight?
Google isn't being helpful.
How do I convert a Char in a array of bits in Haskell?
For example: I want to enter "abc" and return, [[0,0,1,1,0,0,1,0],[0,0,1,0,0,1,0,0],[1,1,0,0,1,0,0,1]]
I tried to use Data.ByteString.Char8 and using pack on a string, do I need to convert to Int now?
I'm having trouble with Visual Studio. I'm trying to make a game in C++ using SDL and I ran into this warning when I tried to use a vector.
[code]1>MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library[/code]
It says the exe is built but it does not create the exe file. I only encounter this warning if I use push_back
Alright, I hit a wall again. So I've tried to draw a 3D cube via OpenGL, building on top of my previous code. The thing is the output is very weird.
[IMG]http://i.imgur.com/O24e9PU.png[/IMG]
Here's the new code:
[url]http://pastebin.com/Xvmffzyd[/url]
I have tried changing the angle at which the cube is rotated, doesn't work.
[QUOTE=Pat.Lithium;45142225]I'm having trouble with Visual Studio. I'm trying to make a game in C++ using SDL and I ran into this warning when I tried to use a vector.
[code]1>MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library[/code]
It says the exe is built but it does not create the exe file. I only encounter this warning if I use push_back[/QUOTE]
It likely means SDL is compiled with a static CRT which conflicts with your CRT (i.e. it's compiled with the /MT option).
The solution is to use dynamically linked CRTs for both, or compile both with the same CRT. You can choose the CRT linking in the project properties:
[img]http://i.imgur.com/eZeXWWY.png[/img]
Normally people use "multi-threaded DLL" for release and "multi-threaded Debug DLL" for debug builds - though it's okay to use "multi-threaded DLL" for everything.
SDL compiles cleanly and without hassle with Visual Studio (though IIRC it requires the DirectX devkit).
edit: The other solution to get rid of the warning is to do as the message suggests and use /NODEFAULTLIB (as described by [url]http://msdn.microsoft.com/en-us/library/6wtdswk0.aspx[/url] ), however I think it's better to compile SDL with a compatible CRT...
[QUOTE=ThePuska;45142290]It likely means SDL is compiled with a static CRT which conflicts with your CRT (i.e. it's compiled with the /MT option).
The solution is to use dynamically linked CRTs for both, or compile both with the same CRT. You can choose the CRT linking in the project properties:
Normally people use "multi-threaded DLL" for release and "multi-threaded Debug DLL" for debug builds - though it's okay to use "multi-threaded DLL" for everything.
[/QUOTE]
Thanks it's working now. I have a question for building release versions, it cannot find the header files for SDL when I try to build a release version what do I have to change?
[QUOTE=Pat.Lithium;45142334]Thanks it's working now. I have a question for building release versions, it cannot find the header files for SDL when I try to build a release version what do I have to change?[/QUOTE]
Do you have the SDL include directory included for both debug and release configurations?
[img]http://i.imgur.com/TRRXbKx.png[/img]
I don't know if any of you use plot.ly, but I've been having an issue where it forgets to put borders on a couple of my plots I've generated in MATLAB. They show up fine in MATLAB, but when exported to plot.ly the issue arises. Here is what I mean:
[url]https://www.dropbox.com/s/qoxarf01jqnbbpj/plotly_plot.pdf[/url]
I'm just not sure what is causing this, and am curious if anyone else has had a similar issue.
Why do division operations take much longer than addition, subtraction, or multiplication? (see [url=http://msdn.microsoft.com/en-us/library/ms973852.aspx]here[/url])
If I want to divide a number by 10, should I instead multiply by 0.1?
Is it possible to call an individual enum's function in java? For example,
[cpp]public enum test{
foo{
public void bar(){}
};
}[/cpp]
How can I call foo.bar()?
[QUOTE=WTF Nuke;45146836]Is it possible to call an individual enum's function in java? For example,
public enum test{ foo{ public void bar(){} }; }
How can I call foo.bar()?[/QUOTE]
Just define a method like normal in the enum class' body.
[code]
public enum MyEnum
{
FOO, BAR;
/**
* Some method
*/
public void someMethod()
{
System.out.println("someMethod called on " + this);
}
}
[/code]
To call it is trivial as well.
[code]
MyEnum.FOO.someMethod();
[/code]
No I mean enum specific methods, like the one I outlined.
[QUOTE=Pelf;45146786]Why do division operations take much longer than addition, subtraction, or multiplication? (see [url=http://msdn.microsoft.com/en-us/library/ms973852.aspx]here[/url])
If I want to divide a number by 10, should I instead multiply by 0.1?[/QUOTE]
I would've thought the operation being done in that case by the CPU is the same so no difference should occur.
Or at least, the compiler should optimise to make sure there is no difference.
[QUOTE=rookwood101;45147798]I would've thought the operation being done in that case by the CPU is the same so no difference should occur.
Or at least, the compiler should optimise to make sure there is no difference.[/QUOTE]
If you want to divide an integer by 10 and get an integer back, just divide it by 10. Multiplying it by 0.1 and casting to an integer is more expensive.
Like you said though, there's probably very little difference, and unless these operations are being done very very often (millions of times a second maybe) you won't notice it and it isn't important.
The speed of integer / floating point operations isn't something that a programmer should worry about unless they have optimized absolutely everything else and it still isn't good enough.
[QUOTE=KatNotDinner;45142272]Alright, I hit a wall again. So I've tried to draw a 3D cube via OpenGL, building on top of my previous code. The thing is the output is very weird.
[IMG]http://i.imgur.com/O24e9PU.png[/IMG]
Here's the new code:
[url]http://pastebin.com/Xvmffzyd[/url]
I have tried changing the angle at which the cube is rotated, doesn't work.[/QUOTE]
Sorry for the repost, my post remained on the last page.
[QUOTE=WTF Nuke;45147333]No I mean enum specific methods, like the one I outlined.[/QUOTE]
[url]http://stackoverflow.com/questions/14968075/enum-method-overriding[/url]
Literally the first Google result.
Short question, I am programming in c++ with QT. Since I am using a databank I am using QSqlQuery. Now the QSqlQuery has a prepare statement which can bind values into the sql statement.
The thing is why should I use this? I normaly just query.exec(sqlstatement) the query and it works just like a prepared statement.
[QUOTE=rookwood101;45147798]I would've thought the operation being done in that case by the CPU is the same so no difference should occur.
Or at least, the compiler should optimise to make sure there is no difference.[/QUOTE]
Multiplications are significantly faster to solve then Divisions are, multiplications can be solved implicitly, while division are solved iteratively
Compilers may replace division with multiplications (GCC sometimes does this), although most compilers stay away from it because due to the nature of floating points which causes (x/y != x*(1/y)).
From a practical POV's its only really interesting to optimize this inside algorithms or other things that run a million times.
[CODE]
public static void main(String[] args) {
String inputFile;
String outputFile;
Scanner input = new Scanner(System.in);
inputFile = "lab4Ex1.txt";
try {
Integer grid[][] = loadGrid(inputFile);
System.out.println("Before flood fill");
printGrid(grid);
floodFill(grid);
System.out.println("After flood fill");
printGrid(grid);
} catch (IOException e) {
System.err.println(e.getMessage());
}
}
public static Integer[][] loadGrid(String fileName) throws IOException {
FileInputStream fin;
fin = new FileInputStream(fileName);
Scanner input = new Scanner(fin);
int nRows = input.nextInt();
int nCols = input.nextInt();
Integer grid[][] = new Integer[nRows][nCols];
for (int r = 0; r < nRows; r++) {
for (int c = 0; c < nCols; c++) {
grid[r][c] = input.nextInt();
}
}
fin.close();
return grid;
}
private static void flood(Integer[][] grid, int row, int col) {
if (row > 0 && col < 9 && col > 0 && row < 9 && grid[row][col] == 0) {
grid[row][col] = 3;
} else {
flood(grid, row + 1, col);
flood(grid, row - 1, col);
flood(grid, row - 1, col - 1);
flood(grid, row, col - 1);
flood(grid, row, col + 1);
flood(grid, row + 1, col + 1);
flood(grid, row - 1, col - 1);
flood(grid, row, col);
}
}
public static void floodFill(Integer[][] grid) {
Scanner input = new Scanner(System.in);
int row = -1;
int col = -1;
do {
System.out.print("Enter a row number > 0 and <= " + grid.length + ": ");
row = input.nextInt();
} while (row < 0 && row >= grid.length);
do {
System.out.print("Enter a column number > 0 and <= " + grid[0].length + ": ");
col = input.nextInt();
} while (col < 0 && col >= grid.length);
// make sure the user enters a valid row and column
// start the flood fill from (row, col)
flood(grid, row, col);
}
public static void printGrid(Integer[][] grid) {
for (int r = 0; r < grid.length; r++) {
for (int c = 0; c < grid[0].length; c++) {
System.out.printf("%3d", grid[r][c]);
}
System.out.println();
}
}
}
[/CODE]
My recursive step: [CODE]private static void flood(Integer[][] grid, int row, int col) {
if (row > 0 && col < 9 && col > 0 && row < 9 && grid[row][col] != 1) {
grid[row][col] = 3;
} else {
flood(grid, row + 1, col);
flood(grid, row - 1, col);
flood(grid, row - 1, col - 1);
flood(grid, row, col - 1);
flood(grid, row, col + 1);
flood(grid, row + 1, col + 1);
flood(grid, row - 1, col - 1);
flood(grid, row, col);
}
}
[/CODE]
My input file: [CODE]
10 10
1 1 1 0 0 0 0 0 0 0
1 0 1 0 0 0 0 0 0 0
1 0 1 0 0 1 1 1 0 0
1 0 1 0 0 1 0 1 1 1
1 0 1 1 1 1 0 0 0 1
1 1 0 1 0 0 0 0 0 1
0 1 1 0 1 1 1 1 1 1
0 0 1 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0[/CODE]
So I'm trying to do a recursive flood fill algorithm, but I keep running into a stack overflow error and I don't know why that is.
0's are meant to be filled and 1's are the "walls".
Sorry, you need to Log In to post a reply to this thread.