• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

C#. I need to flip the parallelogram vertically when 'R' is pressed. I'm told to use matrices but I have no idea how to do that. I don't know if I should expect anything from here because most of the questions I've seen are pretty basic, but who knows.
Well, I'm not sure about the matrix part, but you could try this:
If you were to flip a 2D shape on the plane over some vertical line that goes through it, you could find the center line between the leftmost and rightmost points of the shape, and then for each point add twice the difference between the center line's X coordinate and the point's X coordinate.

For example, using a shape with points (3, 4)(leftmost), (6, 3) and (7, 5)(rightmost):
-Center line -> x = 3 + ( (7 - 3) / 2) -> x = 5
-X coord of (3, 4) flipped over center -> 3 + ( (5 - 3) * 2) -> 7
-X coord of (6, 3) flipped over center -> 6 + ( (5 - 6) * 2) -> 4
-X coord of (7, 5) flipped over center -> 7 + ( (5 - 7) * 2) -> 3
And the new flipped points end up being (7, 4), (4, 3), and (3, 5).
 
Good lord, reading the crazy stuff you guys do...I'm just now teaching myself Java. Having fun with Karel the Robot using Stanford lectures that were put online for help. Having a blast.
 

Hypno Funk

Member
C#. I need to flip the parallelogram vertically when 'R' is pressed. I'm told to use matrices but I have no idea how to do that. I don't know if I should expect anything from here because most of the questions I've seen are pretty basic, but who knows.
http://pastebin.com/UawaHEGF

Matrices are simply mappings from euclidean space to euclidean space in special cases. This just means taking a set of vectors - I'm assuming the points which define your parrellogram and changing their positions.

You can use a rotation matrix on each of your points to rotate your shape:

http://en.wikipedia.org/wiki/Rotation_matrix

Or you'll want to use reflection matrices to reflect your shape over a given line as in your case:

http://en.wikipedia.org/wiki/Transformation_matrix#Reflection
 

squidyj

Member
Alright! Exams are over, nothing left to do but curl up into a ball and cry... and also teach myself to use directx and hlsl.
 
Well, I'm not sure about the matrix part, but you could try this:
If you were to flip a 2D shape on the plane over some vertical line that goes through it, you could find the center line between the leftmost and rightmost points of the shape, and then for each point add twice the difference between the center line's X coordinate and the point's X coordinate.

For example, using a shape with points (3, 4)(leftmost), (6, 3) and (7, 5)(rightmost):
-Center line -> x = 3 + ( (7 - 3) / 2) -> x = 5
-X coord of (3, 4) flipped over center -> 3 + ( (5 - 3) * 2) -> 7
-X coord of (6, 3) flipped over center -> 6 + ( (5 - 6) * 2) -> 4
-X coord of (7, 5) flipped over center -> 7 + ( (5 - 7) * 2) -> 3
And the new flipped points end up being (7, 4), (4, 3), and (3, 5).
The parallelogram can be moved by the user so I don't know how to get the coordinates. I have the last X and Y coordinates where the user let go of the mouse button to move the parallelogram.
 

squidyj

Member
The parallelogram can be moved by the user so I don't know how to get the coordinates. I have the last X and Y coordinates where the user let go of the mouse button to move the parallelogram.

yeah, so make a matrix that flips it vertically about the line described by that point. or rather make m such that it is that matrix.

I assume when you say vertically you mean around the horizontal axis? sounds like you just want to translate your x values to 0, flip your signs, and translate back to where you were all while leaving your y values alone.

so like....

1 0 -oldx
m = 0 1 0 * ? * ?
0 0 1

so you wind up with a final matrix m and if it's not clear how matrices work the top row gives the value of x when multiplied with a point. if the matrix is

a b c x x'
d e f * y = y'
0 0 1 1 1
then
x' = ax + by + c
y' = dx + ey + c
 
The parallelogram can be moved by the user so I don't know how to get the coordinates. I have the last X and Y coordinates where the user let go of the mouse button to move the parallelogram.

You need to know the coordinates of the polygon to do anything with it. You have OnMouseDown() there, so you can get the offset to a reference point from the mouse click and then capture the mouse release to work out the new points.

Although isn't the polygon being represented by a GraphicsPath object? If so, there is a PathPoints property that you can use to get the points. http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.graphicspath.aspx

Once you have those vertices just multiply them by the reflection matrix. The Matrix class in C# has everything you need I believe., including a CreateReflectionMatrix() function.
 

Osiris

I permanently banned my 6 year old daughter from using the PS4 for mistakenly sending grief reports as it's too hard to watch or talk to her
I have a final in processing and I am fuuuucked

can someone please explain using a for loop with an array

Iterating over an array in Processing is quite easy, as like Java it has a second format of for loop specifically for this use (Like a foreach loop in C#).

Here's the example from the Processing documentation:

Code:
int[] nums = { 5, 4, 3, 2, 1 };

for (int i : nums) {
  println(i); 
}

The first line simply declares and initializes an array of Integers.

The next line is the start of the loop, the 'int i' is the temporary variable that holds the value for the current element of the array, and 'nums' is the array the loop is going to iterate through.

This kind of loop, also known as a foreach loop will simply execute all the statements between the curly braces once for each element in the array, so unlike a normal loop you do not need to use a variable as an iterator to control the amount of times the loop runs.
 

squidyj

Member
You need to know the coordinates of the polygon to do anything with it. You have OnMouseDown() there, so you can get the offset to a reference point from the mouse click and then capture the mouse release to work out the new points.

Although isn't the polygon being represented by a GraphicsPath object? If so, there is a PathPoints property that you can use to get the points. http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.graphicspath.aspx

Once you have those vertices just multiply them by the reflection matrix. The Matrix class in C# has everything you need I believe., including a CreateReflectionMatrix() function.

I'm pretty sure you don't need to grab those points because all the GraphicsPath objects are used in making Region objects which have a transform method you just need to pass a matrix to. Which you can make to flip on the basis of your mouse click location can't you?
 

hateradio

The Most Dangerous Yes Man
I'm starting with PHP & Javascript, then I'll work my way up the ladder.
JavaScript is cool, I like it, though there are times where I'm like "WHY YOU DO THAT!" when it comes to objects/classes.

I guess PHP is a start, but don't get too attached. Python would be an easy language to learn, since the syntax is neat, clean, and consistent; plus, you'd get acquainted to OOP, since Python is itself object oriented.

However, I do feel like it's annoying that there are so many "active" versions in use: 2.5, 2.6, 2.7, and of 3.x.

(In any case, I'm trying to be more of a Ruby dev. ❤.❤)
 
I'm pretty sure you don't need to grab those points because all the GraphicsPath objects are used in making Region objects which have a transform method you just need to pass a matrix to. Which you can make to flip on the basis of your mouse click location can't you?

You're probably totally right, I don't work with C# at all so I don't know anything about the libs other than a 1 minute google blast.

I'm starting with PHP & Javascript, then I'll work my way up the ladder.

Disclaimer: I think PHP is the worst language ever created.

Unless your goal is very explicitly to learn PHP as opposed to just improve your programming in general, I would steer clear of PHP. It's got tons of stupid shit that makes it a bad habit generating machine and most of the discussion you can find online is from people who really have no idea what they're doing. I'd second richard1's suggestion to go with something like Python (or Ruby or whatever), and just focus on getting the fundamentals of good practice ingrained. Once you are a stronger programmer, you'll be much better equipped to filter the stupid out of PHP yourself and recognise bad advice when you see it.

Also, JavaScript has issues but it's a nice language with a very powerful feature set that is often chronically misunderstood, so no harm sticking with a bit of JS. It can also foster bad habits though, because the language is so forgiving.

I guess PHP is a start, but don't get too attached. Python would be an easy language to learn, since the syntax is neat, clean, and consistent; plus, you'd get acquainted to OOP, since Python is itself object oriented.

However, I do feel like it's annoying that there are so many "active" versions in use: 2.5, 2.6, 2.7, and of 3.x.

(In any case, I'm trying to be more of a Ruby dev. ❤.❤)

Usually with Python, if you stick to 2.7 you'll be 100% fine. If you need to learn details of 3 fully you can do it down the line when it comes up and the transition is quite simple if you are already familiar with the language.
 
I'm starting with PHP & Javascript, then I'll work my way up the ladder.

That's sounds like a good way to learn to write awful code that sort of works for the rest of your life :p

Nah, not really, but you gotta be really careful not learn some backwards ass things in a wrong way that will haunt you forever.


And PHP is literally the worst. But at the same time people use that everywhere so...
 

d[-_-]b

Banned
Lol so my sqlite db has grown to unacceptable size
3 Tables
Manga (_id (int), title (text))
Chapter (_id (string), manga_id (int), title (text)
Page (manga_id(int), chapter_id (text), link (text))

So as you can see redundancies to access each one
But for 1 Manga there X amount of chapters and Y amount of Pages, so the data grows at a very rapid pace :(.
Thinking about removing the page table throwing the links into a text field in the chapters table as just a comma delimited array.

I'd appreciate anyone's insight on saving more space.
 

Chris R

Member
First thing I see is that your chapter ID is a string? Why not keep it an int? And then the page doesn't need the magna ID since the chapter the page "belongs" to already has it.
 

d[-_-]b

Banned
First thing I see is that your chapter ID is a string? Why not keep it an int? And then the page doesn't need the manga ID since the chapter the page "belongs" to already has it.

The chapter ID could be like 001.0 or 01-001.0 and some of the chapter ids overlap.

01-001.0 | 3249
01-001.0 |5710
01-001.0 | 7069
001.0 |11752
001.0 |749
 

Zoe

Member
d[-_-]b;45615346 said:
The chapter ID could be like 001.0 or 01-001.0 and some of the chapter ids overlap.

01-001.0 | 3249
01-001.0 |5710
01-001.0 | 7069
001.0 |11752
001.0 |749

Why?
 

KorrZ

Member
I'm currently in the middle of trying to teach myself Java. I just started programming this year, I spent about 8 months on C++ previously but because of my limited amount of time to dedicate to programming (I can only spare an hour or so a day towards it, more on weekends) I decided that I should get into something a little bit easier. I've purchased Head First Java and am making my way though it, and also have a copy of Effective Java that I plan to go through next.

I think I have pretty decent coverage with the two books I've already purchased, but I would really like to find a book that's just full of exercises. Where you just get a text description of what the program should do and maybe a sample output and then let you code it yourself. If anyone has any recommendations I'd appreciate it :).
 

mannerbot

Member
I'm currently in the middle of trying to teach myself Java. I just started programming this year, I spent about 8 months on C++ previously but because of my limited amount of time to dedicate to programming (I can only spare an hour or so a day towards it, more on weekends) I decided that I should get into something a little bit easier. I've purchased Head First Java and am making my way though it, and also have a copy of Effective Java that I plan to go through next.

I think I have pretty decent coverage with the two books I've already purchased, but I would really like to find a book that's just full of exercises. Where you just get a text description of what the program should do and maybe a sample output and then let you code it yourself. If anyone has any recommendations I'd appreciate it :).

Not quite what you're after but I think this'll scratch the itch for you all the same:
https://www.coursera.org/course/algs4partI
 

Zoe

Member
d[-_-]b;45615587 said:
Lol I wish I knew wasn't of my choice.
After comparing values in the table for chapters, looks like Volume # - Chapter #?

If it isn't too much of an undertaking, I would rebuild that pages table using the proper chapter ID field (and remove the manga ID as said above). I don't like the idea of delimited fields in a table.
 

Vossler

Member
Complete noob jumping in here asking for advice. Been reading up and think I may learn C# first, then move to C++. Decent starting path?
 

Vossler

Member
so stick with C# then I take it? Was reading that it is an easier path into XNA, but I am also wondering if I shouldn't learn something like python beforehand.
 

CrankyJay

Banned
so stick with C# then I take it? Was reading that it is an easier path into XNA, but I am also wondering if I shouldn't learn something like python beforehand.

If you're going to be doing Windows platform stuff you might as well be doing C#.

Games that run on the framework can technically be written in any .NET-compliant language, but only C# in XNA Game Studio Express IDE and all versions of Visual Studio 2008 and 2010 (as of XNA 4.0) are officially supported.
 
Complete noob jumping in here asking for advice. Been reading up and think I may learn C# first, then move to C++. Decent starting path?

C# will be easier to get into, I think. C++ is very complex because it has all the stuff that C has (pointers, no garbage collection) but also a lot of advanced object oriented stuff. To be honest, it doesn't really matter which language you start programming in. The most important thing is that you have fun while programming or else you probably won't keep doing it. Also, it's smart to start with a popular language like C#, Python, Java or Javascript because there are a lot of resources out there for learning them and helping you out if you get stuck somewhere (which you will, sooner or later)

C# also has a fantastic IDE (Visual Studio) and the .Net framework is pretty awesome. Has lots of useful stuff.
 

msv

Member
Anyone here knowledgable on Java RMI?

I've got a headache on my case here - I didn't know much of RMI beforehand, so I took the project, issued remote interfaces for all the necessary classes and unicast them. Then the Client is given a stub of an object which containst all the necessary data - and the client can access all the data that that client can access by virtue of having that stub, plus a stub of the client's own user object stub.

On a LAN it works well enough. I realize that it's a pretty non-optimized solution, in fact even a shitty solution, but it works well on LAN. But when I run it on a server in the cloud, and try to connect to the server it lags like crazy, even though there's only 72ms of lag.

I think it's because exported RMI objects make the packets go back and forth, back and forth somehow. Seeing as how I've set the java.rmi.server.hostname of the server to it's wan-ip (behind a router) and my own on a wan-ip (behind a router) as well. This is causing timeouts and makes the project pretty much unusable.

I'm sorry for not being clear here. I'll explain the code a bit.

Server:
- the server sets the hostname to its WAN-ip
- server sets up the main object, which contains all other objects needed for operation, and exports it with unicast
- server creates a registry on port 1099
- server binds an object (which has a login and a register method) stub to a name

Client:
- client sets hostname to its WAN-ip (for the listeners)
- client locates the registry on port 1099 of the server's WAN ip
- client does a lookup for the object bound to the name set by the server
- client logs in and gets the stub for the main object, and through the interface has methods with which to execute commands on the server.

From there on it flows from one remote object to another, each exported on server side and sent via method of the previous object.

I think it's just looping on itself somehow. The datarate is really low, around 1 kb/s. But opon login, the client recieves an ILobby interface, a stub/proxy of the real lobby on the server side - but this takes almost 30s.

When the clients sends a message - the clients uses chat.sendmessage(IUser user, String message) - (the IUser is a stub of a user, originating from the server side).

The server makes a message out of it, and in the same method (sendmessage) sends a publish out to all the listeners. Each publish issued has its own thread, so the server doesn't hang here. But it still gets a timeout.

Can anyone explain to me what I'm doing that would cause this? Is RMI not made to be used in this way at all? Is RMI just not useable for connections between different networks? If any clarification is necessary let me know, kinda don't know where to start with explaining, since it's such a mess because of RMI.
 
Does anyone here own intelliJ IDEA? I want to buy both IDEA and Pycharm, but it appears IDEA already supports Python. Is it worth to get Pycharm by itself?
 
It appears that if you buy the main IDE, IDEA, then you get the functionality of all the other IDEs via plugins. Unless you are 100% certain you are only going to ever use a certain language, then you should get IDEA.
 

A Pretty Panda

fuckin' called it, man
Can someone help me with this project?

I have to create an array of 20, fill and sort it. I can fill it fine but I have no clue how to sort the 20 numbers in any sort of order.
 

Tomat

Wanna hear a good joke? Waste your time helping me! LOL!
Can someone help me with this project?

I have to create an array of 20, fill and sort it. I can fill it fine but I have no clue how to sort the 20 numbers in any sort of order.

Bubble sort is the best sort known to man. (It isn't, but it's the easiest to program)
 
Top Bottom