Yo guys, having a little trouble with getting GLFW working nicely; any windows I create just hang and show the waiting circle cursor - I can't even move them or interact with the top bar at all. Here's my code:
[code]
/*
MainSource.cpp
Main Source file for OpenGL Project
*/
#include <stdlib.h>
#include <iostream>
#include <GLFW/glfw3.h>
void exitError( int status, const char *description )
{
std::cout << "Error [" << status << "] " << description
<< "\nPress ENTER to exit." << std::endl;
glfwTerminate();
while( !std::cin.get() );
exit( EXIT_FAILURE );
}
void keyCallback( GLFWwindow *window, int key, int scancode, int action, int mods )
{
if( key == GLFW_KEY_ESCAPE && action == GLFW_PRESS )
glfwSetWindowShouldClose( window, GL_TRUE );
}
int main()
{
glfwSetErrorCallback( exitError );
glfwInit();
GLFWwindow *gameWindow = glfwCreateWindow( 640, 480, "Oh, pen-gull!", NULL, NULL );
if( !gameWindow )
{
glfwTerminate();
exitError( 1, "Failed to create window" );
}
glfwMakeContextCurrent( gameWindow );
glfwSetKeyCallback( gameWindow, keyCallback );
do
{
glfwSwapBuffers( gameWindow );
}
while( !glfwWindowShouldClose( gameWindow ) );
glfwTerminate();
return 0;
}
[/code]
Anyone know why this is? I thought my problem was I wasn't swapping the buffers but even now I added that it still does it.. any advice would be appreciated, I couldn't find any other people asking about similar problems online, the only other relevant question is a guy on stackoverflow who was having trouble with threading, but I'm not using any threading here. I'm using GLFW 3.0.1 if that's any help
[b]Edit:[/b]
Ahh! Never mind! Found the problem, I'm not polling for events in my do while loop. Calling glfwPollEvents() before glfwSwapBuffers() worked perfectly :)
[QUOTE=buster925;43051935]In Visual Studio 2013 the cursor sometimes becomes big and grey and types over the text where the cursor is located:
[IMG]http://i.imgur.com/4NrS35N.png[/IMG]
How would I get the normal text input cursor?[/QUOTE]
Could be worse. Eclipse (I believe due to my theme) likes to randomly highlight large chunks of code when I try to select something specific and other weird and really obnoxious stuff that involves me deleting everything and having to ctrl+Zzzzzzzzzzzzzzzzzzzzzzzzz (oh yeah, and my z key sticks which makes it more of a challenge).
[QUOTE=Tamschi;43050968]If the effect is very slow it may be floating point loss.[/quote]
Oh that'd make sense. I have no idea how I could go about fixing it, though.
Assuming that is the problem, by "slow" I mean like 30 frames, which is nowhere near acceptable.
[QUOTE=chaz13;43057991]Oh that'd make sense. I have no idea how I could go about fixing it, though.
Assuming that is the problem, by "slow" I mean like 30 frames, which is nowhere near acceptable.[/QUOTE]
No, that's fast :v:
I admit I didn't really look at your algorithm before, averaging fields like that doesn't conserve the amount of fluid at all at the borders.
Especially the corner values, their influence is 1/3 + 2 * 1/4 so 1/6th of their content evaporates.
For border tiles you have 3/4 + 1/5 = 19/20, so 1/20th is lost.
Tiles one step from the border actually increase the amount of fluid, their weight is 4/5 + 1/4 = 21/20.
Only the content of tiles at least two cells from each edge is conserved roughly into the next round.
If you can't solve it by properly solving the equations (a bit messy, you need special treatment for the outer two rows or unusual influences I think), you can do this much more concisely by calculating flow between two tiles based on their difference and adding that to the current cell's value.
That's also a much more realistic model (for a viscous fluid, the one you have right now is pretty strange and doesn't model any real phenomenon afaik).
[code]for(ix=0; ix<gs; ix+=1){
for(iy=0; iy<gs; iy+=1){
last_density[ix,iy] = density[ix,iy]
}
}[/code]
Replace that part with switching the arrays, if you can't change the pointers at least use a Buffer- or memcopy if you have enough space to allocate a third one.
[QUOTE=Tamschi;43058307]No, that's fast :v:
I admit I didn't really look at your algorithm before, averaging fields like that doesn't conserve the amount of fluid at all at the borders.
Especially the corner values, their influence is 1/3 + 2 * 1/4 so 1/6th of their content evaporates.
For border tiles you have 3/4 + 1/5 = 19/20, so 1/20th is lost.
Tiles one step from the border actually increase the amount of fluid, their weight is 4/5 + 1/4 = 21/20.
Only the content of tiles at least two cells from each edge is conserved roughly into the next round.
If you can't solve it by properly solving the equations (a bit messy, you need special treatment for the outer two rows or unusual influences I think), you can do this much more concisely by calculating flow between two tiles based on their difference and adding that to the current cell's value.
That's also a much more realistic model (for a viscous fluid, the one you have right now is pretty strange and doesn't model any real phenomenon afaik).
[code]for(ix=0; ix<gs; ix+=1){
for(iy=0; iy<gs; iy+=1){
last_density[ix,iy] = density[ix,iy]
}
}[/code]
Replace that part with switching the arrays, if you can't change the pointers at least use a Buffer- or memcopy if you have enough space to allocate a third one.[/QUOTE]
Ahh, thank you for spotting that. That would definitely be an issue! I'll fix that up and see how it works.
Yeah, I first tried implementing jos stam's fluid dynamics paper but there were a few parts I found just slightly too vague to do so, mostly the boundary conditions. Then considered using a solution to a variation of the heat equation, but for the time being I've put that on the back burner and wanted to get some basic form of diffusion working to mess about with.
When you say calculating the difference between two cells and adding that to the current cell, could you go into a little more detail? I think I get the gist and I'm going to give it a go, but going from the last value to the new values is where I often get a little confused.
[QUOTE=chaz13;43060666]Ahh, thank you for spotting that. That would definitely be an issue! I'll fix that up and see how it works.
Yeah, I first tried implementing jos stam's fluid dynamics paper but there were a few parts I found just slightly too vague to do so, mostly the boundary conditions. Then considered using a solution to a variation of the heat equation, but for the time being I've put that on the back burner and wanted to get some basic form of diffusion working to mess about with.
When you say calculating the difference between two cells and adding that to the current cell, could you go into a little more detail? I think I get the gist and I'm going to give it a go, but going from the last value to the new values is where I often get a little confused.[/QUOTE]
Think of it as a difference in water levels in different columns, as pressure increases linearly with depth you build up a bit on the difference in height (it's infinitesimally small for infinitesimally thin columns) that is then constant along the contact surface.
As the pressure difference is proportional to the density, the acceleration due to it inversely so and the fluid incompressible, you end up with acceleration that is (if I'm not mistaken) proportional to the height difference (please look up that last part, I'm absolutely not sure about this).
Normally this would be a second order differential (you'd need a planar velocity vector layer in addition to the one storing local fluid levels), but if the fluid is viscous like old honey or dense mud the friction and acceleration equalise so quickly that conservation of momentum becomes negligible.
[editline]4th December 2013[/editline]
The paper describes free flowing fluids though, which have three degrees of freedom (two velocities and one density or equivalent values) in two dimensions.
For gases you can scale it to 3D, but a liquid behaves very differently. A liquid pool has about one dimension less than the environment it exists in, so you can (afaik) model a puddle as 2D gas and use column height in place of density.
[editline]4th December 2013[/editline]
That was probably not what you asked about :v:
Multiply the difference (current - remote) by some factor smaller than or equal to 1/4 and add the results to the level of the cell you're in.
[editline]edit[/editline]
For viscous fluid that is, water doesn't work that way and nor does gas.
Has anyone had much experience with writing 3D collision detection and response? For an assignment I have to create a 3D world to drive around in, I currently have a working implementation of GJK for collision detection (it's pretty simple to understand now :v: yay?), but responding to a found collision is driving me insane.
My current implementation returns the resulting simplex from the GJK detection, it's always a 4 point convex shape. I've come across a few ways of getting a vector to stop the collision, one being the EPA algorithm, but there is so little online for 3D implementation (shit, even the maths that I'm no good at anyway), so I think I might give up on that. Someone suggested finding the closest point in the resulting simplex and using that, but that would provide some strange results too when I thought about it.
So does anyone have any good resources for this kind of stuff? Or any tips for alternate ways of responding to collisions?
Annnnnnnnnd, i'm back.
Hey guys, so i'm wondering if you have any advice for this. I'm creating a program that takes the sum of the first three squares of the number 333.
I've got this
[code]
//Aaron White
//*increaser*
//*increases*
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
void Pause ()
{//freezes screen
char junk;
cout <<endl << endl << "Press some keys followed by the Enter key to continue...";
cin.ignore();
cin.get(junk);
//end pause
}
int main()
{ //MAIN BODY
/*char x;
char y ;
cout << "Enter a character to represent 'x'\n";
cin >> x;
cout << "Enter a character to represent 'y'\n";
cin >> y;
*/
int x = 333;
int y = 0;
while( x > 0 ){
int z = 0;
if( x % 2 != 0){
z = x*x;
y = y + z;
}
x--;
}
cout << y;
Pause();
return(0);
}
[/code]
It should be taking X when X is greater than 0, and then checking to see if it's even or odd, then if it's odd, it takes it, multiplies it by itself, then adds it.
Since i need the first 3, i'm thinking i need to add a count to it, and maybe nest the whole thing inside of a loop that runs it until "count == 3"?
Any ideas/advice?
snip
Hi. I'm searching for a good Python implementation for Windows 8.
Mainly I need the scientific packages(NumPy,ObsPy).
Does anyone know some?
Can'tyou just use python for windows?
What's the best way to use Java and Excel together?
I'm attempting reading and writing from Java to Excel and vice versa.
[QUOTE=blacksam;43066161]What's the best way to use Java and Excel together?
I'm attempting reading and writing from Java to Excel and vice versa.[/QUOTE]
Write to and from a csv I think.
so i'm teaching myself c++ and i'm trying to get a feel for when it's better to use exceptions or return codes, and most of the discussions i found online were about using "catch (...)"
e.g.
[code]
int main() {
...
if (!SetupServerSocket()
|| RunSelectLoop()) {
StopSocketLayer();
return 1;
}
...
}
bool RunSelectLoop() {
...
if ((status = select(top_descr, input, output, NULL, timeout))) {
printf("select() failed: WinSock error %i\n", WSAGetLastError());
return false;
}
...
}
[/code]
and I do this sort of thing when creating, binding or accepting sockets as well -- should I be using something like "throw SocketSelectException()" instead?
[QUOTE=Luni;43066686]so i'm teaching myself c++ and i'm trying to get a feel for when it's better to use exceptions or return codes, and most of the discussions i found online were about using "catch (...)"
e.g.
[code]
int main() {
...
if (!SetupServerSocket()
|| RunSelectLoop()) {
StopSocketLayer();
return 1;
}
...
}
bool RunSelectLoop() {
...
if ((status = select(top_descr, input, output, NULL, timeout))) {
printf("select() failed: WinSock error %i\n", WSAGetLastError());
return false;
}
...
}
[/code]
and I do this sort of thing when creating, binding or accepting sockets as well -- should I be using something like "throw SocketSelectException()" instead?[/QUOTE]
Throwing exceptions is always a good idea when something that absolutely shouldn't happen happens, they are far easier to debug than return codes.
The problem comes in when you have some library you can't use RAII for because you leak memory when unrolling the stack over plain pointers.
If you always use the alternative structs that shouldn't be an issue though.
You really should avoid using globals or instance fields instead of returning the expected result too, either use the return value or mutable reference parameters.
Using globals means you can very easily run into trouble with exceptions because they too aren't automatically destroyed. Your code becomes virtually unreusable too.
I may be mistaken about you doing that though, posting a more complete snippet would help a lot.
[editline]4th December 2013[/editline]
I think part of the issue is that unique_ptr, shared_ptr and so on (the names may be slightly different, I don't use C++) are not used everywhere.
Throwing exceptions instead of returning error codes can be a bad idea if you have plain * pointers, and unfortunately a lot of low level libraries are not modern enough to offer safe interfaces.
[editline]4th December 2013[/editline]
This may be a bit too much generalising, but if I'm not mistaken you can write your programs now completely without using * pointers and if you never use them you can use exceptions everywhere because everything will self-destroy once the last reference is deleted.
* pointers are usually called raw pointers.
And yes, you can normally completely wrap raw pointers in smart pointers (if you also include boost::intrusive_ptr and use a raw pointer as a non-owning pointer (which might also come as a "real" smart pointer in C++14 as std::exempt_ptr)).
And by wrap I mean you can usually wrap existing APIs with a small shim (or just directly where you interface with it) to use smart pointers. I've done it easily with SDL, Ogre3D and OMNeT++ (although it was a little more work there because of less cleanly defined ownership rules).
An alternative to return-codes and exceptions is an error-code parameter. I've seen some used in Boost.
Or in an object you can also track the error-state within the class and provide methods to check for errors, like std::*stream does (e.g. std::ostream::fail()).
[editline]4th December 2013[/editline]
[QUOTE=JohnStamosFan;43062468]Annnnnnnnnd, i'm back.
Hey guys, so i'm wondering if you have any advice for this. I'm creating a program that takes the sum of the first three squares of the number 333.
I've got this
[code]//code snip[/code]
It should be taking X when X is greater than 0, and then checking to see if it's even or odd, then if it's odd, it takes it, multiplies it by itself, then adds it.
Since i need the first 3, i'm thinking i need to add a count to it, and maybe nest the whole thing inside of a loop that runs it until "count == 3"?
Any ideas/advice?[/QUOTE]
After reading in the value of x, just check directly if it's odd and if so subtract one. This will make it even.
Then you can just do y += x * x; three times, or until x < 0, and subtract 2 from x every iteration (just skipping the odd numbers); you can express this in a for-loop:
[code]for(size_t i = 0; (i < 3) && !(x < 0); ++i, x -= 2)[/code]
The parenthesis around the i < 3 is not strictly necessary, but I think it looks more uniform this way. Of course you can also flip the !(x < 0) to x >= 0.
To all android devs!
So I'm creating an android app that's used to gather data, like a digital questionnaire. The questionnaires need to be dynamically created at my website to be accessible in the app for download on login.
My website & app share the same user login table.
I'm thinking something like this within the app:
-Temp folder (name=currently logged in user)
--questionnaire1.?
--questionnaire2.?
The questionnaires are then uploaded on completion to the webserver which reads the data and inputs into the mySQL database.
When the files have been uploaded the temporary folder and everything in it is deleted.
How do I manage these kinds of things on the android OS and in the app?
What would be the most efficient method to store the questionnaire in the app .XML / .txt or other alternatives? It needs to be something that i can read into mySQL.
Any help thinking this through is appreciated.
[QUOTE=Bloodsh0t;43067974]To all android devs!
So I'm creating an android app that's used to gather data, like a digital questionnaire. The questionnaires need to be dynamically created at my website to be accessible in the app for download on login.
My website & app share the same user login table.
I'm thinking something like this within the app:
-Temp folder (name=currently logged in user)
--questionnaire1.?
--questionnaire2.?
The questionnaires are then uploaded on completion to the webserver which reads the data and inputs into the mySQL database.
When the files have been uploaded the temporary folder and everything in it is deleted.
How do I manage these kinds of things on the android OS and in the app?
What would be the most efficient method to store the questionnaire in the app .XML / .txt or other alternatives? It needs to be something that i can read into mySQL.
Any help thinking this through is appreciated.[/QUOTE]
SqLite?
C# question:
Anyone know exactly how to check what cell the user has selected in a datagridview?
I need a method that checks every time the user changes what cell he's selecting, but I don't know exactly what the eventhandler/event is called.
[QUOTE=war_man333;43071645]C# question:
Anyone know exactly how to check what cell the user has selected in a datagridview?
I need a method that checks every time the user changes what cell he's selecting, but I don't know exactly what the eventhandler/event is called.[/QUOTE]
[URL="http://msdn.microsoft.com/de-de/library/system.windows.forms.datagridview.onselectionchanged%28v=vs.110%29.aspx"]http://msdn.microsoft.com/de-de/library/system.windows.forms.datagridview.onselectionchanged%28v=vs.110%29.aspx[/URL] and [URL="http://msdn.microsoft.com/de-de/library/system.windows.forms.datagridview.selectedcells%28v=vs.110%29.aspx"]http://msdn.microsoft.com/de-de/library/system.windows.forms.datagridview.selectedcells%28v=vs.110%29.aspx[/URL], if the first one doesn't already have the info in a ...EventArgs member.
Uh, my distance numbers seem to always be returning roughly the same number no matter where this thing is!
[code] local fpos = phys:GetPos()
local fang = phys:GetAngles():Forward()
local ftd = {}
local lpos = phys:GetPos()
local lang = phys:GetAngles():Right() * -1
-- lang = lang:RotateAroundAxis( phys:GetAngles():Up(), 180 ) -- Rotate around the axis that goes up/down.
local ltd = {}
local rpos = phys:GetPos()
local rang = phys:GetAngles():Right()
local rtd = {}
-- 32768 is the distance from the farthest possible left point of the level to the farthest possible right point of the level! Doubling that should guarantee always getting infinite trace.
ftd.start = fpos
ftd.endpos = fpos+(fang*65536)
ftd.filter = self.Owner
local Ftr = util.TraceLine(ftd)
ltd.start = lpos
ltd.endpos = lpos+(lang*65536)
ltd.filter = self.Owner
local Ltr = util.TraceLine(ftd)
rtd.start = rpos
rtd.endpos = rpos+(rang*65536)
rtd.filter = self.Owner
local Rtr = util.TraceLine(ftd)
local FDist = ( Ftr.HitPos - Ftr.StartPos ):Length(); print( "Front: "..FDist )
local LDist = ( Ltr.HitPos - Ltr.StartPos ):Length(); print( "Left: "..LDist )
local RDist = ( Rtr.HitPos - Rtr.StartPos ):Length(); print( "Right: "..RDist )[/code]
[editline]4th December 2013[/editline]
it had something almost directly to its left, maybe 2 yards in its front, and likely 30 yards to its left, but this is what I got:
[code]Front: 378.20914158315
Left: 378.20914158315
Right: 378.20914158315[/code]
[editline]4th December 2013[/editline]
I'm sure you can figure what I'm trying to do?
I want three infinite traces, Forward; Left; Right
I want to know how far away each trace hits, in a floating point form.
Well, for that matter... when this thing bounces it rotates like a crazy son of a... so how could I fix that? I'm using vPhysics to just get perfect bounces and I've tried thousands of methods to correct that spinning problem.
Well, also on that note, I've tried a lot of methods to get this trace distance data to work!
I need to make a file tree walk in Java for a lab, but im having trouble with one thing...
I need to indent correctly on what level of the tree i'm in.
Here is my code so far:
[code]
private static void recurseDirectoryHelper(File rootDirectory) {
File[] list = rootDirectory.listFiles();
String indent = " ";
for(File file: list){
if(file.isFile()){
System.out.println(indent + file.getName());
}
}
for(File file: list){ ;
if(file.isDirectory()){
System.out.println("subdir " + file.getName() + ":");
recurseDirectoryHelper(file);
}
}
}
[/code]
and this is how I have my output:
[code]
/testroot/
.DS_Store
testfile1
testfile2
subdir testdir:
testfilesub1
subdir testdir2:
Untitled Document
Untitled Document 2
subdir untitled folder:
[/code]
That last untitled folder is actually in testdir2, but the way i have my output formatted, it doesn't indent it so it shows its farther "to the right" in the file system.
Anybody know a way I can indent it so it formats it nicely? The logic has been bugging me.
[QUOTE=brianosaur;43074600]I need to make a file tree walk in Java for a lab, but im having trouble with one thing...
I need to indent correctly on what level of the tree i'm in.
[/QUOTE]
[code]
private static void recurseDirectoryHelper(File rootDirectory, int depth) {
...
recurseDirectoryHelper(file, depth + 1)
...
}
private static void recurseDirectoryHelper(file rootDirectory) {
recurseDirectoryHelper(rootDirectory, 0)
}
[/code]
I don't think Java has easy string repetition like Python's str*n or Lua's string.rep(), though, but a StringBuilder would probably work for a string of tabs/spaces. It might be more efficient to pass /that/ between functions, even, and just add or remove characters each time it calls itself or exits.
I feel interrupted lol
Three traces based on a vPhysics Move/Solid entity's position: Straight Left;Right;Forward
They always have to be from the entity. They need to be infinite distance traces. I need to know the different float differences for the left, right, and forward traces each.
[editline]4th December 2013[/editline]
On another note the model itself rotates like a crazy bastard when it bounces off of something. I need to prevent that!
[QUOTE=Luni;43074633][code]
private static void recurseDirectoryHelper(File rootDirectory, int depth) {
...
recurseDirectoryHelper(file, depth + 1)
...
}
private static void recurseDirectoryHelper(file rootDirectory) {
recurseDirectoryHelper(rootDirectory, 0)
}
[/code]
I don't think Java has easy string repetition like Python's str*n or Lua's string.rep(), though, but a StringBuilder would probably work for a string of tabs/spaces. It might be more efficient to pass /that/ between functions, even, and just add or remove characters each time it calls itself or exits.[/QUOTE]
I know hah, I've been toying with a depth parameter, but couldn't find out where to increment it and all that. I think I got it where I need to increment it before I do the recursive call, and decrement it after i passed it again. gonna check it and post results
C#
If I have a form, and this form starts an instance of a class called Logic.cs, what's the best way to update the form through Logic.cs? I'm running a timer on the Logic.cs which should update the form every 5 seconds.
[QUOTE=war_man333;43076778]C#
If I have a form, and this form starts an instance of a class called Logic.cs, what's the best way to update the form through Logic.cs? I'm running a timer on the Logic.cs which should update the form every 5 seconds.[/QUOTE]
Use events and wire them up when you create the instance in the form.
[QUOTE=Tamschi;43076983]Use events and wire them up when you create the instance in the form.[/QUOTE]
If you could come with an example, that'd be awesome.
-snip-
[QUOTE=war_man333;43077094]If you could come with an example, that'd be awesome.[/QUOTE]
In the Logic class you could do [code]public event Action Updated;
protected void OnUpdated()
{
if (Updated != null) Updated();
}[/code]
Then you can use it like this in the form:
[code]_logic = new Logic();
_logic.Updated += Update; // Update is a void() method accessing _logic.[/code]
You could also use lambda or delegate syntax:[code]_logic.Updated += () => { /* update */ }[/code]
With multiple events and delegate types other than Action you could also change the system to only process the results that changed, which is a good idea if that's only a small portion.
You can make custom delegate types quickly with [code]delegate ReturnType DelegateTypeName(ParameterType1 parameterName1[, ...]);[/code] which can appear anywhere class definitions are valid.
Note that this isn't entirely matching the usual .NET event patterns, they usually use a delegate of the form [code]void Name(object sender, ...EventArgs e)[/code], but that's partially a holdover from not having generics and lambdas up to a certain point.
I think using a correctly typed sender parameter instead is a good idea, making an EventArgs class is mostly useful for ensuring forward-compatibility of the consumer side and a bit more work than just a plain delegate.
[editline]6th December 2013[/editline]
The event is syntactic sugar for a private delegate field and public add- and remove-methods that call += and -= on it.
They have special names so like with properties you're calling methods with assignment syntax and can't do it explicitly. Events don't expose any get or set methods, so only += and -= work.
Sorry, you need to Log In to post a reply to this thread.