Still having trouble with that rotation...
[CODE]
public void draw(float x, float y, float rx, float ry){
tex.bind();
glPushMatrix();
glTranslatef(0,0,0); // translate to screen origin
glRotatef(rx, ry, 0.0f, 1.0f); // rotate quad
glTranslatef(x,y,0); // translate back to it's position
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(0, tex.getHeight());
glVertex2f(0, height);
glTexCoord2f(tex.getWidth(), tex.getHeight());
glVertex2f(width, height);
glTexCoord2f(tex.getWidth(), 0);
glVertex2f(width, 0);
glEnd();
glPopMatrix();
}
[/CODE]
Now it just rotates around 0,0 at a distance. I am trying to get it to rotate on it's center. I am using the modelview matrix, and calling LoadIdentity before all of this does nothing.
[QUOTE=Duskling;38760400]Still having trouble with that rotation...
[CODE]
public void draw(float x, float y, float rx, float ry){
tex.bind();
glPushMatrix();
glTranslatef(0,0,0); // translate to screen origin
glRotatef(rx, ry, 0.0f, 1.0f); // rotate quad
glTranslatef(x,y,0); // translate back to it's position
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(0, tex.getHeight());
glVertex2f(0, height);
glTexCoord2f(tex.getWidth(), tex.getHeight());
glVertex2f(width, height);
glTexCoord2f(tex.getWidth(), 0);
glVertex2f(width, 0);
glEnd();
glPopMatrix();
}
[/CODE]
Now it just rotates around 0,0 at a distance. I am trying to get it to rotate on it's center. I am using the modelview matrix, and calling LoadIdentity before all of this does nothing.[/QUOTE]
Call LoadIdentity in between glPushMatrix and glTranslatef. glTranslatef isn't doing what you think it's doing. The fixed-function transformation methods generate a new matrix based off your parameters and multiply them into the currently loaded matrix.
To put it more simply, transformations are additive. That is, if you call glTranslatef(0, 1, 0) followed by glTranslatef(1, 0, 0), you'll end up with a translation of (1, 1, 0). When you glPushMatrix, it takes the current matrix and pushes a copy of it on the matrix stack. The matrix itself stays the same.
robmaister12 is right.
especially this lines comment is wrong:
glTranslatef(0,0,0); // translate to screen origin
What it really means you're doing there is: don't translate the current matrix at all.
Do this:
tex.Bind();
// if you know you're working on the right matrix (model) then do nothing,
// oterwise call glMatrixMode() with model.
glPushMatrix();
glLoadIdentity();
glTranslatef(-modelWidth, -modelHeight, -modelDepth);
glRotate(rx, ry, 0);
glTranslatef(modelWidth, modelHeight, modelDepth);
glTranslatef(modelPositionX, modelPositionY, modelPositionZ);
// Draw
glPopMatrix();
Be aware that the last two translates can be combined into one (obviously :P)
remember: translate, rotate and scale transform the current matrix, they don't replace them.
the only way to replace the current matrix is: loadMatrix, popMatrix, loadIdentity + transformation
Am I going about this the wrong way;
I've been searching around for good programming tutorials in the sense that they aren't the 'basics' like, 'Hey, this is an integer, this is an array' but also are not overly technical. I haven't found one that is as 'fun' as the Head First Python book. That book is great, is there anything like that, say, a list of a bunch of cool, fun, productive projects with a step-by-step guide?
I've run out of ideas and want to expand.
I'm taking a VB class and I'm having trouble with an assignment, I was hoping you guys could help me out. It's been super easy up until now, I don't know why I'm having so much trouble writing to text files...
Anyways, I keep getting a null error from my save() sub procedure and I'm fairly sure it's something incredibly stupid that I'm overlooking so any help from a different perspective would be appreciated.
[code]
Private Sub Save()
Dim intIndexSave As Integer
Dim objStreamWriter As StreamWriter
objStreamwriter = New IO.StreamWriter(strOutputfile)
Do Until intIndexSave = intFirstavailable
objStreamwriter.WriteLine(intCounter(intIndexSave).ToString & "," & strFirstname(intIndexSave) & "," _
& strLastname(intIndexSave) & "," & strNickname(intIndexSave) & "," _
& strPhonenumber(intIndexSave) & "," & strEmailaddress(intIndexSave))
intIndexSave += 1
Loop
blnNeed2save = False
objStreamwriter.Close()
MsgBox("Your Friendslist has been saved.")
End Sub[/code]
Thanks again you guys
With C#'s XmlNode, how can i retrieve the values of "type" and "position" thingies in the following?
[code]
<Entity type="tree" position="10;10"></Entity>
[/code]
[editline]asd[/editline]
Got it! XmlNode.Attributes contain all the thingies of the node.
[QUOTE=Felheart;38761263]robmaister12 is right.
especially this lines comment is wrong:
glTranslatef(0,0,0); // translate to screen origin
What it really means you're doing there is: don't translate the current matrix at all.
Do this:
tex.Bind();
// if you know you're working on the right matrix (model) then do nothing,
// oterwise call glMatrixMode() with model.
glPushMatrix();
glLoadIdentity();
glTranslatef(-modelWidth, -modelHeight, -modelDepth);
glRotate(rx, ry, 0);
glTranslatef(modelWidth, modelHeight, modelDepth);
glTranslatef(modelPositionX, modelPositionY, modelPositionZ);
// Draw
glPopMatrix();
Be aware that the last two translates can be combined into one (obviously :P)
remember: translate, rotate and scale transform the current matrix, they don't replace them.
the only way to replace the current matrix is: loadMatrix, popMatrix, loadIdentity + transformation[/QUOTE]
[QUOTE=robmaister12;38760769]Call LoadIdentity in between glPushMatrix and glTranslatef. glTranslatef isn't doing what you think it's doing. The fixed-function transformation methods generate a new matrix based off your parameters and multiply them into the currently loaded matrix.
To put it more simply, transformations are additive. That is, if you call glTranslatef(0, 1, 0) followed by glTranslatef(1, 0, 0), you'll end up with a translation of (1, 1, 0). When you glPushMatrix, it takes the current matrix and pushes a copy of it on the matrix stack. The matrix itself stays the same.[/QUOTE]
Thanks for the help guys, this is awesome. I will get to testing this out later.
Thanks again :)
EDIT:
Don't know what I am doing wrong. I am positive I understand how to do this, but it just refuses to rotate around the center of the object. It only wants to rotate around 0,0 on the screen.
[CODE]
public void draw(float x, float y, float rx, float ry){
tex.bind();
glPushMatrix();
glLoadIdentity();
glTranslatef(-width,-height,0);
glRotatef(rx, ry, 0.0f, 1.0f);
glTranslatef(width,height,0);
glTranslatef(x,y,0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(0, tex.getHeight());
glVertex2f(0, height);
glTexCoord2f(tex.getWidth(), tex.getHeight());
glVertex2f(width, height);
glTexCoord2f(tex.getWidth(), 0);
glVertex2f(width, 0);
glEnd();
glPopMatrix();
}
[/CODE]
[QUOTE=Tovip;38746523]Alright so I'm working in c# and I have a list of classes named listProjects
anyone know how I would go about checking to see if the string ( Course == "Hello" ) in any of the classes in that list?[/QUOTE]
Use foreach (or a for loop) and an if check inside the loop. There might also be predicates you can use directly on the list, but I don't know how good you are at C# and I'm not sure I understand your question (it's missing a word).
[cpp]
unsigned char x = 50;
char y = 50;
[/cpp]
Would the bit/byte representations of x and y be the same in C?
i.e. x = 00110010 would y = 00110010 also?
[QUOTE=jaooe;38768798][cpp]
unsigned char x = 50;
char y = 50;
[/cpp]
Would the bit/byte representations of x and y be the same in C?
i.e. x = 00110010 would y = 00110010 also?[/QUOTE]
Depends on your platform, since I think C doesn't guarantee anything about the underlying integer format specifics, but presumably yes.
[editline]10th December 2012[/editline]
Especially considering most implementations of signed integers require the first bit to be flipped for the number to be negative (sign-and-magnitude, ones' complement and twos' complement all require this)
[editline]10th December 2012[/editline]
This is also very easily confirmed by checking whether x == (unsigned char) y
[QUOTE=esalaka;38768924]
This is also very easily confirmed by checking whether x == (unsigned char) y[/QUOTE]
I'm not 100% sure, so correct me if I'm wrong:
If you write this in C(++) code then the compiler will convert the numbers since you do a explicit cast!
So the compiler will convert the number to its unsigned / signed equivalent (depending on how you cast).
So for x = y = 50, where x is unsigned char and y is char, it will always return true. [I]Even if the underlying bit-representation is different.[/I]
So you will have to compare x against "reinterpret_cast<unsigned char>(y)".
Or am I wrong?
Edit: I'm not sure about that reinterpret_cast syntax, my c++ is really rusty :v:
But if I remember correctly it will override any checks and just take the memory at that address and treat it as a <Type> you're casting to without any kind of conversion.
[QUOTE=Felheart;38769068]I'm not 100% sure, so correct me if I'm wrong:
If you write this in C(++) code then the compiler will convert the numbers since you do a explicit cast!
So the compiler will convert the number to its unsigned / signed equivalent (depending on how you cast).
So for x = y = 50, where x is unsigned char and y is char, it will always return true. [I]Even if the underlying bit-representation is different.[/I]
So you will have to compare x against "reinterpret_cast<unsigned char>(y)".
Or am I wrong?
Edit: I'm not sure about that reinterpret_cast syntax, my c++ is really rusty :v:
But if I remember correctly it will override any checks and just take the memory at that address and treat it as a <Type> you're casting to without any kind of conversion.[/QUOTE]
Oh, damn, I obviously meant x == *((unsigned char *)&y)
Thanks for noticing
Any reason why this wouldnt work?
[cpp]
float Student::getMark(const string &module) const throw (NoMarkException)
{
if(marks.count(module) == 1)
{
return marks[module];
}
throw NoMarkException();
}[/cpp]
marks is a private [cpp]std::map<std::string, float>[/cpp]
[editline]9th December 2012[/editline]
the error is:
[quote]
Student.cpp: In member function ‘float Student::getMark(const string&) const’:
Student.cpp:23:28: error: passing ‘const std::map<std::basic_string<char>, float>’ as ‘this’ argument of ‘std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::basic_string<char>; _Tp = float; _Compare = std::less<std::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::basic_string<char>, float> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = float; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::basic_string<char>]’ discards qualifiers [-fpermissive]
[/quote]
I need a good tutorial on C# databases. I know how databases work as I have lots of experience in PHP.
I build the database, make the tables, get connected and can't do anything. :|
Anyone know any c# databases tutorial that can help me out?
"databases" is a pretty broad term :v:
What kind of database are you connecting to?
Do you have a local DB? Or do you connect to a SQL db over the internet or what ?
If you have a desktop app you should definitly use SQLite.net, it's fast and super easy to use and there are many good tuts for it on the internet.
Sorry, I should have been more specific.
For testing purposes (until I get the hang of it), I'm going to use a local DB. Also, it will be for a form app.
I am trying to get FOV for an isometric game working, however I've run into a problem. Currently, the way that map data is stored similarly to a normal 2d map, except that every odd tile will be shifted half a space when drawn. So the tile [0][1] has the tiles [0][0], [1][0], [0][2], and [1][2] beside it. I am trying to generate a circle for the FOV, however the algorithm generates circles in normal fashion, aka if the map was not isometric. I am not sure how to convert that data into isometric data. Any ideas? Here's a picture for help
[img]http://i.imgur.com/LxFKq.png[/img]
Top is the way that the algorithm generates circle, bottom is the way I need the circle. The numbers represent the X and Y coords.
Simple, just apply the same transformation to the points of the circle.
In your pic you apply "rotate 45°, then scale Y by 0.5".
Do the same with your points. (Remember to use the correct center for the rotation. Maybe you have to subtract the centerpoint first, rotate, then add it again to get a correct "rotate around center" rotation)
edit: I hope I got what you meant. :tinfoil:
[QUOTE=Felheart;38772352]Simple, just apply the same transformation to the points of the circle.
In your pic you apply "rotate 45°, then scale Y by 0.5".
Do the same with your points. (Remember to use the correct center for the rotation. Maybe you have to subtract the centerpoint first, rotate, then add it again to get a correct "rotate around center" rotation)
edit: I hope I got what you meant. :tinfoil:[/QUOTE]
I do understand, however I'm not sure how to rotate it.
Oh ok, I can help with that.
You can either read this: [url]http://en.wikipedia.org/wiki/Rotation_matrix[/url]
Or you just use the formula directly:
float rotatedX = x * cos(angle) - y * sin(angle);
float rotatedY = x * sin(angle) + y * cos(angle);
angle is the counter-clockwise rotation in RADIANS (not degrees)
[QUOTE=Felheart;38772529]Oh ok, I can help with that.
You can either read this: [url]http://en.wikipedia.org/wiki/Rotation_matrix[/url]
Or you just use the formula directly:
float rotatedX = x * cos(angle) - y * sin(angle);
float rotatedY = x * sin(angle) + y * cos(angle);
angle is the counter-clockwise rotation in RADIANS (not degrees)[/QUOTE]
And then just round the number, and divide y by 2? I'll try.
Is the center of your circle at 0,0 ?
Remember that scaling also scales "around" the origin. That means if your coordinates are not centered at 0,0 then your results might be off.
@ThePuska: Why the disagree rating? Can you explain why you think I'm wrong?
Edit: ok after reading his question again, I think I know why. I thought he was refering to drawing the tiles. But he actually wants to convert the coordinates. Well, I don't think that my proposal will work then, sorry.
[QUOTE=Felheart;38772782]Is the center of your circle at 0,0 ?
Remember that scaling also scales "around" the origin. That means if your coordinates are not centered at 0,0 then your results might be off.
@ThePuska: Why the disagree rating? Can you explain why you think I'm wrong?
Edit: ok after reading his question again, I think I know why. I thought he was refering to drawing the tiles. But he actually wants to convert the coordinates. Well, I don't think that my proposal will work then, sorry.[/QUOTE]
Yeah, I'm trying to convert the coords not the pics.
You need a metric which can deal with your modified coordinates.
Your transformation:
x' = x - ((y % 2) * 0.5)
y' = y / 2
Your world's axes:
u = (1, 1)
v = (1, -1)
Project your transformed coordinates onto these axes:
u' = (u * (x', y'))
v' = (v * (x', y'))
Calculate distances in this system:
du' = u1' - u0'
dv' = v1' - v0'
Here's a sample C code for integer coordinates:
[cpp]void isometric(int x, int y, int *u, int *v)
{
// Scale coordinates by two to enable offset by half a tile with integers:
int xt = 2 * x - ((y % 2 == 1) ? 1 : 0);
int yt = y;
int ux = 1;
int uy = ux;
int vx = ux;
int vy = -uy;
int dotu = ux * xt + uy * yt;
int dotv = vx * xt + vy * yt;
*u = dotu;
*v = dotv;
}
void isometricDist(int x0, int y0, int x1, int y1, int *du, int *dv)
{
int u0, v0, u1, v1;
isometric(x0, y0, &u0, &v0);
isometric(x1, y1, &u1, &v1);
// Divide by two because isometric transformation scaled by two:
*du = (u1 - u0) / 2;
*dv = (v1 - v0) / 2;
}
int main(int argc, char *argv[])
{
int u, v;
// Calculate distance between (2, 1) and (3, 7)
isometricDist(
2, 1,
3, 7,
&u, &v);
}[/cpp]
Then you can just use the normal circle attributes with the modified coordinates: a point is inside the circle if du^2 + dv^2 < r^2.
Well besides being scaled by two compared to the original integers the world axes may be different from what you're using so you shouldn't expect them to match. The distance function should work regardless.
edit: No it doesn't actually work, sorry about that. But the idea is solid:
Using your transformation, convert the grid coordinates to basically screen coordinates. Then project the coordinates onto the world axes, and calculate the distance along those axes
[QUOTE=Duskling;38763801]
Don't know what I am doing wrong. I am positive I understand how to do this, but it just refuses to rotate around the center of the object. It only wants to rotate around 0,0 on the screen.
[CODE]
public void draw(float x, float y, float rx, float ry){
tex.bind();
glPushMatrix();
glLoadIdentity();
glTranslatef(-width,-height,0);
glRotatef(rx, ry, 0.0f, 1.0f);
glTranslatef(width,height,0);
glTranslatef(x,y,0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0);
glTexCoord2f(0, tex.getHeight());
glVertex2f(0, height);
glTexCoord2f(tex.getWidth(), tex.getHeight());
glVertex2f(width, height);
glTexCoord2f(tex.getWidth(), 0);
glVertex2f(width, 0);
glEnd();
glPopMatrix();
}
[/CODE][/QUOTE]
I saw you replied to my advice but you still aren't using it.
[CODE]
glTranslatef(-position.x,-position.y,0);
//Rotation stuff
glTranslatef(position.x,position.y,0);
[/CODE]
Hey, I am trying to create an array which gets used to retrieve some basic data about the selected element of the periodic table.
The array gets declared in the InitializeComponent(); stage, but when I try to retrieve the array in a new private void segment of a button it doesn't seem to recognize the array. It will recognize the array when it's called within the InitializeComponent(); segment though. The only thing I can think of is to declare the same array every button press, but it seems quite inefficient to create the same array 118 times. Here's the code:
[CODE]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Periodic_System
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//Information Arrays
string[] symbol = new string[7] { "H", "Li", "Na", "K", "Rb", "Cs", "Fr" }; //118 elements in total
}
public void H_Click(object sender, EventArgs e)
{
labelSymbol.Text = symbol[0];
}
}
}[/CODE]
[QUOTE=martijnp3000;38777911]Hey, I am trying to create an array which gets used to retrieve some basic data about the selected element of the periodic table.
The array gets declared in the InitializeComponent(); stage, but when I try to retrieve the array in a new private void segment of a button it doesn't seem to recognize the array. It will recognize the array when it's called within the InitializeComponent(); segment though. The only thing I can think of is to declare the same array every button press, but it seems quite inefficient to create the same array 118 times. Here's the code:
[CODE]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Periodic_System
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//Information Arrays
string[] symbol = new string[7] { "H", "Li", "Na", "K", "Rb", "Cs", "Fr" }; //118 elements in total
}
public void H_Click(object sender, EventArgs e)
{
labelSymbol.Text = symbol[0];
}
}
}[/CODE][/QUOTE]
You need to declare the array outside the "Initialisecomponent stage" as such:
[CODE]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Periodic_System
{
public partial class Form1 : Form
{
//Create array
string[] symbol;
public Form1()
{
InitializeComponent();
//Information Arrays
symbol = new string[7] { "H", "Li", "Na", "K", "Rb", "Cs", "Fr" }; //118 elements in total
}
public void H_Click(object sender, EventArgs e)
{
labelSymbol.Text = symbol[0];
}
}
}
[/CODE]
Figured it out
Sorry, you need to Log In to post a reply to this thread.