Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 680 681 [682] 683 684 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 841009 times)

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10215 on: November 25, 2016, 08:04:08 pm »

In response to your problem with build.bat, how did you make build.bat? Because I think it is possible you saved it with a .txt extension (so build.bat.txt).
Logged

TheDarkStar

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10216 on: November 25, 2016, 08:13:16 pm »

I've been working on writing an implementation of matrix multiplication. It works in terms of taking two matrix classes and returning a third, but something's not quite right with the algorithm. Any suggestions? Also, what could I do to improve it in terms of readability?

(I implemented member access so that MatrixName[j] is valid and works as expected)
(Matrices have a row variable, a column variable, and an array holding whatever number are in the matrix)

Code: [Select]
//the *= operator:

Matrix& operator*=(const Matrix& rhs)
    {
        if (this->columns != rhs.rows)
            throw "Matrix Multiplication Dimension Mismatch";
        Matrix temp(this->rows, rhs.columns);
            for(int rhsColumn=0; rhsColumn<rhs.columns; rhsColumn++)
                for(int lhsRow=0; lhsRow<this->rows; lhsRow++)
                {
                    temp[lhsRow][rhsColumn]=0;
                    for(int rhsColumnEntry=0; rhsColumnEntry<rhs.rows;rhsColumnEntry++)
                        temp[lhsRow][rhsColumn]+=(this->Data[(lhsRow)*(this->columns)+rhsColumnEntry])*(rhs[rhsColumnEntry][rhsColumn]);
                }
        delete[] this->Data;
        this->Data = new double[rhs.rows*this->columns];
        this->columns = rhs.columns;
        for(int i=0;i<this->rows;i++)
            for(int j=0;j<rhs.columns;j++)
                this->Data[i*columns+j] = temp[i][j];
        return *this;
    }

//the actual * operator [note: outside the Matrix class]:

Matrix operator*(const Matrix& lhs, const Matrix& rhs) // matrix multiplication
    {
        Matrix temp1;
        temp1 = lhs;
        temp1*=(rhs);
        return temp1;
    }
Logged
Don't die; it's bad for your health!

it happened it happened it happen im so hyped to actually get attacked now

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10217 on: November 25, 2016, 08:34:36 pm »

Well, something that I noticed is that you have a temporary this->rows x rhs.columns matrix and you're copying it into an array of size rhs.rows*this->columns so maybe that is the problem (you didn't specify what was 'not quite right' with the algorithm)
Logged

TheDarkStar

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10218 on: November 25, 2016, 08:37:49 pm »

"*this" is a pointer to the current object (here, the left matrix for the *= operator), so it's always defined.

And sorry for not specifying the problem. I can get it to work without crashing, but it fails to properly multiply. The result of the function returns a matrix with the correct dimensions but does not properly compute the numerical multiplication.
« Last Edit: November 25, 2016, 08:39:20 pm by TheDarkStar »
Logged
Don't die; it's bad for your health!

it happened it happened it happen im so hyped to actually get attacked now

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10219 on: November 25, 2016, 08:43:35 pm »

Define a top of the line IDE then? From what I hear Visual Studio is good, but Visual Studio Professional and Visual Studio Enterprise cost money, Visual Studio Community will not actually finish the installing process on my computer, and Visual Studio Code appears to be shit.

Visual Studio Code isn't "shit" because it's not meant to be a compiler. It's a lightweight cross-platform code editor with syntax highlighting and a built-in store to download extensions. Someone could make a user-designed compiler extension for any particular language, but that would be a lot of work. If the extensions you're trying to add don't work then that's an issue with whoever wrote those extensions. It's as much VS-Code's fault as it is Google Play's fault if you download a buggy game using the service.

BTW, Another one you could try is Jetbrain's Rider IDE. Jetbrains make Resharper, which is one of the most popular extensions for Visual Studio, and are now working on their own standalone IDE:
https://www.jetbrains.com/rider/
« Last Edit: November 25, 2016, 08:53:49 pm by Reelya »
Logged

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10220 on: November 25, 2016, 09:12:58 pm »

JetBrains does make good stuff, I quite like their Python IDE PyCharm.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10221 on: November 25, 2016, 09:17:45 pm »

My suggestion is to just get an IDE that isn't that one.
So helpful. Thanks.

Why on earth would you not use a top of the line IDE that you have presumably just installed?
Define a top of the line IDE then? From what I hear Visual Studio is good, but Visual Studio Professional and Visual Studio Enterprise cost money, Visual Studio Community will not actually finish the installing process on my computer, and Visual Studio Code appears to be shit.

I've been using Code::Blocks but I tried Visual Studio Code based on a recommendation of what's "good to be familiar with" -in this case Visual Studio IDEs- if I want to be "competitive" in the job market for programming.
Well that's problematic.

I know I'm using VS Community.  I don't think VS Code is part of the same group of things.

Not being able to install VS Community looks like it's kinda a problem there.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10222 on: November 25, 2016, 09:27:35 pm »

"*this" is a pointer to the current object (here, the left matrix for the *= operator), so it's always defined.

And sorry for not specifying the problem. I can get it to work without crashing, but it fails to properly multiply. The result of the function returns a matrix with the correct dimensions but does not properly compute the numerical multiplication.
What I meant was that the dimensions of the new matrix were incorrect, but apparently that is not a problem. Could you give an example of the matrix multiplication not working?
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10223 on: November 25, 2016, 09:30:02 pm »

<snip>

Get rid of *= completely. That would immediately allow you to cut the number of functions you're needing to debug. *= is a composite that is equivalent to "a = a * b", so you can just daisy-chain *= to peform the multiplication and assignment operations once everything else is working. Basing * on *= is just an unnecessary complexification and a performance hit (since you're doing extra object creations and deletions now).

You can start by testing multiplication by an identity matrix for square matricies, identify any glaring bugs, multiply the identity on both left and right, then test for rectangular sizes.
« Last Edit: November 25, 2016, 09:47:46 pm by Reelya »
Logged

RoguelikeRazuka

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10224 on: November 26, 2016, 08:32:46 am »

Hello, I need some help from those who are confident in building GUI applications with Tkinter (Python). The thing is, I need to write a program featuring a GUI with two separate windows. The first one must contain something like a log-in form with OK and CANCEL buttons. If user enters a correct username and then presses the ok button, the log-in window closes and the other window is shown right after. On the second window, there must be a CANCEL button, which if pressed closes the second window, and then the first window is shown again. How could I implement this?

I suppose one solution would be making the log-in window the main or root window (Tk), then the second window must be a dialog window (TopLevel). Then if user presses the ok button on the first window, it gets hidden and the second window, the dialog one, pops up. If the cancel button on the dialog window is pressed, then it gets destroyed and the main window becomes visible again.

But is there a better option? 
« Last Edit: November 26, 2016, 08:37:08 am by RoguelikeRazuka »
Logged

TheDarkStar

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10225 on: November 26, 2016, 02:29:36 pm »

<snip>

Get rid of *= completely. That would immediately allow you to cut the number of functions you're needing to debug. *= is a composite that is equivalent to "a = a * b", so you can just daisy-chain *= to peform the multiplication and assignment operations once everything else is working. Basing * on *= is just an unnecessary complexification and a performance hit (since you're doing extra object creations and deletions now).

You can start by testing multiplication by an identity matrix for square matricies, identify any glaring bugs, multiply the identity on both left and right, then test for rectangular sizes.

Thanks for this, it was so much easier to implement it outside the class. And it worked the first time. :)
Logged
Don't die; it's bad for your health!

it happened it happened it happen im so hyped to actually get attacked now

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10226 on: November 27, 2016, 12:17:41 pm »

Hello, I need some help from those who are confident in building GUI applications with Tkinter (Python). The thing is, I need to write a program featuring a GUI with two separate windows. The first one must contain something like a log-in form with OK and CANCEL buttons. If user enters a correct username and then presses the ok button, the log-in window closes and the other window is shown right after. On the second window, there must be a CANCEL button, which if pressed closes the second window, and then the first window is shown again. How could I implement this?

I suppose one solution would be making the log-in window the main or root window (Tk), then the second window must be a dialog window (TopLevel). Then if user presses the ok button on the first window, it gets hidden and the second window, the dialog one, pops up. If the cancel button on the dialog window is pressed, then it gets destroyed and the main window becomes visible again.

But is there a better option?
Well, you could switch them around, so the login is the modal dialog and the main window spawns logins.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

RoguelikeRazuka

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10227 on: November 29, 2016, 09:59:20 am »

Hey could someone help me fix my opengl program, please? I'm not sure which mistakes I could have made across it in general (please point out if you notice any), but it is lighting that concerns me most, for I don't know why when my positional light source moves closer and closer to the plane (see the code snippet below) it grows darker, should it really be so?

Here's  some pieces of the code:

http://pastebin.com/iN6ABLp6

And these are some pictures of the scene:
Spoiler (click to show/hide)

Spoiler (click to show/hide)

(I'm using the "old" opengl, don't ask why)
« Last Edit: November 29, 2016, 10:01:24 am by RoguelikeRazuka »
Logged

nogoodnames

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10228 on: November 29, 2016, 10:10:36 am »

I've never messed with opengl, but it looks like it's working how it's supposed to. As the light source approaches the horizon of the plane, the light rays begin moving parallel to it and fewer hit the surface. Notice that the mace thingy in the centre is just as, if not more illuminated because it is perpendicular to the light rays.

Although, it is odd that the mace's far side stays illuminated when it should be in shadow.
« Last Edit: November 29, 2016, 10:15:03 am by nogoodnames »
Logged
Life is, in a word, volcanoes.
                        - Random human lord

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10229 on: November 29, 2016, 01:09:12 pm »

OpenGL's built in immediate mode lighting system is very basic and doesn't do shadowing at all, nor does it do things like per-pixel lighting for spot lights or anything like that.  If I remember right, it calculates lighting as a pure function of the triangle's surface normal and the light position, and performs per-triangle (maybe it was per-vertex) lighting that way.  I can't remember for sure if it even does distance based falloff for light intensity, but it's been many years.

So, my guess at least is that by moving the light source down, you're increasing the angle from the light source to each vertex's normal vector and thus decreasing the illumination at each vertex.  If you try breaking your square up into multiple triangles you'd probably see something more realistic and closer to what you'd expect.

This is kind of an aside, but if you're new to OpenGL then it's easy to learn the immediate mode way of doing basic rendering and lighting, but it's all very, very old and deprecated.  Using vertex and fragment shaders alongside display lists, vertex buffers and frame buffers will give you access to the modern API, which is much faster and gives you the ability to do things like per-pixel lighting.  Admittedly, it is more complicated and I never did find any particularly good tutorials on how to do it, which is why I've never learned it myself.
Logged
Through pain, I find wisdom.
Pages: 1 ... 680 681 [682] 683 684 ... 796