Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - PhysicsManUK

Pages: [1]
1
DotNet / Re: Help Setting Up SFML.NET with Visual Studio 2013 C#
« on: March 06, 2014, 01:33:16 pm »
Oh dear, how embarrassing, I should've noticed that.

Anyway, thank you for the help, much appreciated  :)

2
DotNet / Help Setting Up SFML.NET with Visual Studio 2013 C#
« on: March 05, 2014, 11:02:47 pm »
Hi, at the moment I am looking at making the transition from C++ to C# for my particle simulation programs as I will be able to use the .NET Framework using Windows Forms Applications and such. So currently I am just trying to get SFML working in VS 2013 in C#.

I have created an empty project (SFMLTest) just to see how I can use SFML in VC# and I am following the advice given in this thread:

http://en.sfml-dev.org/forums/index.php?topic=7674.0

Thus far I have added the relevant resources; sfmlnet-audio.dll, sfmlnet-graphics.dll and sfmlnet-window.dll from SFML’s lib folder. However when I try to use "Add Existing Item" from project directory in Solution Explorer and add the CSFML dlls, the extlibs folder has no matching items so I can't progress from there.

Any help is very much appreciated, thanks.

P.S: I assume the procedure for allowing your C# project to utilise SFML is the same when you create a Windows Forms Application or a WPF project?

3
Graphics / Re: Creating Multiple Shapes
« on: December 11, 2013, 04:19:08 pm »
You should look at the Vertex array tutorial. It seems to solve your problem perfectly.

Thanks for the tip, that tutorial will help me out with this program a lot!

4
Graphics / Re: Creating Multiple Shapes
« on: December 09, 2013, 06:04:49 pm »
To create a frame you must use Window.clear once, then use Window.draw however many times you want and then use Window.display once. What you're doing is making two frames where each odd one is a shape and each even one is FPS so it looks like it's blinking.
Also don't just dump code you wrote for others to debug, I knew what to look for (double display) so it took me few seconds in text editor find function but it's bad practice to dump all your code and ask others to look through all of it when 90% is not relevant to problem.

P.S.
This is oversimplification, only display is necessary since you can render(and clear) with OpenGL and if you set all pixels to something yourself each frame you don't need clear at all but don't worry about that for now.

I see, that makes sense. Thank you, problem fixed now.

Also, I'll edit out the unnecessary code segments if I get the chance but I'm quite busy at the moment so it may be left as it is for a while.

5
Graphics / Re: Creating Multiple Shapes
« on: December 09, 2013, 12:37:32 am »
I see, thanks for the information - I will take a look at that book list and see if I can find some good ones to buy.

Also, instead of creating a new thread, I might as well ask here about a problem I am having with a blinking window. Here is my (far from complete) code:

// Brownian_Motion_Test.cpp
// Program to simulate Brownian motion of particles in 2d
// Rendered using SFML Graphics ®

// Preprocessor directives (include headers) for program

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <string>

// Namespaces to be used by program

using namespace std;    // standard namespace (std)
using namespace sf;             // Simple and Fast Multimedia Library namespace (sf)

// Global Declaration of Mathematical/Physical Constants

const double pi = 4*atan(1);            // Value of pi
const double k_B = 1.38E-23;            // Boltzmann Constant

// Global Declaration of Rendered Window Sizes

unsigned int width = 800;               // width of rendered 2d window (in px)
unsigned int height = 600;              // height of rendered 2d window (in px)

// Global Declaration of Particle Properties

const float r = 5.0F;           // radius of particle (in px)
const int NParticles= 3;                // number of particles to be produced in simulation

// Declare time value and utility class to measure elapsed time

Time thetime;
Clock elapsedtime;

// Function to return string from integer type

string IntToString(int d) {

   stringstream ss;
   ss << d;
   return ss.str();

}

// Function to calculate frame rate (fps)

std::string getFrameRate() {
       
        static int frameCounter = 0;    // (re-)Initialise frame counter variable
        static int fps = 0;             // (re-)Initialise frames per second variables
        frameCounter++;         // Increment frameCounter by 1 for each call to function GetFrameRate
        thetime = elapsedtime.getElapsedTime();         // Returns the elapsed time since the last call to .restart()

        // if-statement to process code if thetime reaches 1 second (or greater)

        if(thetime.asMilliseconds() > 999) {
     
                fps = frameCounter;             // assign frameCounter to fps if thetime > 999ms
        frameCounter = 0;       // reinitialise frame counter to 0
        elapsedtime.restart();          // reinitialise the clock back to zero time

        }

        return IntToString(fps);                // Returns string for fps value

}

// Function to render animation sequences for each particle

void animationSequence ( RenderWindow& window, CircleShape& circle, float x, float y ) {

        window.clear(Color(255,255,255,255));           // Fill the window with even white colour
        circle.setPosition(x, y);               // Update position of circle in window
        window.draw(circle);            // Draw circle in rendered window
        window.display();                       // Display on screeen what has been rendered to the window so far

}

void displayFrameRate ( RenderWindow& window, Text& FPS ) {

        window.clear(Color(255,255,255,255));           // Fill the window with even white colour
        FPS.setString(getFrameRate());                          // Set FPS to string returned by call to GetFrameRate function
        window.draw(FPS);                                       // Draw FPS text to screen
        window.display();                       // Display on screen what has been rendered to window so far

}

int main(void) {

        RenderWindow window(VideoMode(width, height), "Brownian Motion Animation");             // Render 2d Window for Animation; width x height px

        vector<CircleShape> particle(NParticles);                       // Create a vector of circles called particle() of size NParticles

        float RandomNumberWidth[100] = {0};                             // RNG Variables for...
        float RandomNumberHeight[100] = {0};                    //... X and Y positions

        const unsigned IM = 1664525;                                    // Integer constants
        const unsigned IC = 1013904223;                                 //... for the RNG algorithm

        const float scale = 1.0/0xFFFFFFFF;                     //Scaling factor for random double between 0 and 1
        unsigned iran = time(0);                                                //Seeds the random-number generator from the system time

        const int MAX(100);             // RNG for loop maximum limit

        for ( int i = 0 ; i < MAX ; i++ ) {

                RandomNumberWidth[i] = width * scale * float ( iran = IM * iran + IC );                 // Random Number Generator for X position
                RandomNumberHeight[i] =  height * scale * float ( iran = IM * iran + IC );              // Random Number Generator for Y position

                //cout << RandomNumberWidth[i] << endl;                                 // UNCOMMENT TO PRINT RANDOM NUMBERS FOR TESTING
                //cout << RandomNumberHeight[i] << endl << endl;

        }

        Font font;              // Load character font

        if (!font.loadFromFile("arial.ttf")) {          // If the font arial.ttf cannot be loaded, print error message to console
   
                // error...

        }

        Text FPS("0", font, 25);        // text variable to store Frame Rate, initialise to 0...
                                                                //... set Font type to font, set character size to 25
       
        FPS.setOrigin(-10,-10);         // set original position of FPS text in 2d window

        FPS.setColor(Color::Red);       // set colour of FPS text

        for ( int i = 0 ; i < NParticles ; i++ ) {
               
                particle[i].setRadius(r);               // Set radius of particle[i] to r
                particle[i].setFillColor(Color::Blue);          // Set fill colour of particle[i] to blue
                particle[i].setOrigin(-RandomNumberWidth[i],-RandomNumberHeight[i]);    // Set origin position of particle[i] to random position

        }

        float x[NParticles] = {0};                                              // horizontal displacement of particles
        float y[NParticles] = {0};                                              // vertical displacement of particles

        int k = 0;                      // animation loop iterator

        while (window.isOpen()) {

                if ( k >= NParticles )                  // reset k to 0 when it reaches NParticles value
                        k = 0;

                x[k] = float(pow(-1,k)) * (10 * scale * float ( iran = IM * iran + IC ));               //Update X position of particle[k] - THIS IS TEST EXPRESSION, NOT PHYSICALLY ACCURATE
                y[k] = float(pow(-1,k)) * (10 * scale * float ( iran = IM * iran + IC ));               //Update Y position of particle[k] - THIS IS TEST EXPRESSION, NOT PHYSICALLY ACCURATE

                Event event;            // Defines a system event and its parameters

                while (window.pollEvent(event)) {
       
                        if (event.type == Event::Closed)        // close the window and destroy all attached resources if user quits animation window
                                window.close();
       
                }
               
                animationSequence(window, particle[k], x[k], y[k]);             // call to function animationSequence() to simulate particles
                displayFrameRate (window, FPS);                         // call to function displayFrameRate() to print fps to window
               
                k++;    // increment k for each while loop iteration

        }

        return 0;

}       // end of main()

/*

YET TO UPDATE:

- **PRIORITY** SOLVE GRAPHICAL GLITCH PROBLEM OF EACH PARTICLE AND FRAME RATE TEXT FLASHING RAPIDLY **PRIORITY**
- DEVISE SIMPLE COLLISION DETECTION ALGORITHM (CDA) FOR PARTICLE COLLISIONS
- INVESTIGATE USE OF .SETPOSITION FOR USE IN CDA
- LINES 162,163: REPLACE COEFFICIENT OF SCALE WITH ENERGY DISTRIBUTIONS OF PARTICLES - i.e. E[k], where E[] is random distribution array/vector

*/


As far as I can tell, I have utilised the principle of events -> draw -> display outlined in the tutorials and I cannot find the source of the rapid blinking (of the circles and the text in the window) in my code.

I would be very much appreciate if somebody could point out the problem and also explain how and why what I have done is incorrect or bad practice.

Thanks.

6
Graphics / Re: Creating Multiple Shapes
« on: December 07, 2013, 12:33:47 am »
Understood. Do you have any suggestions on some books that would be good for me to read up on the STL and a C++ in general? As I said, I have "Beginning Visual C++ 2012" by Ivor Horton which is a very good book, from my experience, but in order to go into more detail with the Standard Library (algorithms, vectors etc) then I'd need a more specific book.

I should note that at the moment I am in my 2nd year of my Physics degree and next (academic) year I shall be taking an "Intercalated Year in Computer Science" (so basically a year in computer science instead of physics), so I expect that I shall be learning about a fair amount of this material there.

7
Graphics / Re: Creating Multiple Shapes
« on: December 06, 2013, 06:55:04 pm »
I see, that makes sense. At the moment I have the simulation working using an array of fixed size, but I shall explore the use of vectors instead given those points.

Thanks.  :)

8
Graphics / Re: Creating Multiple Shapes
« on: December 05, 2013, 11:56:23 pm »
Indeed, I have a book called "Beginning Visual C++ 2012" by Ivor Horton; I'm not sure it covers vectors but it's good anyhow. I do, however, have some experience with using vectors in C++, but not an awful lot. I shall have a play around with my code and see if I can store the shapes I need in a vector - can the same not be achieved with an array, by the way?

9
Graphics / Creating Multiple Shapes
« on: December 05, 2013, 10:35:48 pm »
Hello there, I am fairly new to SFML (and C++ as a whole really) and I was wondering if there is a way to render multiple shapes (in my case, circles) to a window without physically declaring each circle once at a time.

I want to create several hundred circles to represent particles in order to carry out a Brownian Motion animation in 2d; and of course I don't really want to declare each circle, so it would be great if someone could tell me of a way to collectively declare all these circles (same radius, fill colour, but their origin positions will be set my an RNG) in a single body of code.

Thanks.

Pages: [1]