I've decided to just use GLEW, thanks for the advice though!
I'm trying to program a roguelike using c++ and pdcurses.
I have a Square class which represents a square on the map.
In the Map class I have a Square*** squares 3d array using pointers.
What I want to do in the player class is having a pointer to the players current square and being able to check adjacent squares when moving.
I'm thinking of having a pointer to the whole Square*** squares 3d array but how do I do that?
Doing Square**** doesn't work.
Why a 3D array? Floor grids are generally 2-dimensional.
Anyway, Square*** is already a pointer to your square data, so you don't need to introduce a fourth level of pointer-ness. You [i]could[/i] just pass the Square*** to whatever function wants to examine the grid.
Note that a Square*** is not actually a 3D array, it's an array of pointers to arrays of pointers to squares. That lets you use syntax like squares[x][y][z] to access individual squares, but it also makes allocation and deallocation tricky. you have to individually "new" and "delete[]" all those sub-arrays. The only real "benefit" it provides is the ability to have different sub-arrays be different sizes, which you don't actually need or want, so I'd recommend just using a single 1D array instead. You can translate a 3D (x,y,z) triplet into a 1D array index with a little arithmetic, something like x+y*(width)+z*(width*height)
I assume he's using a 3D array for "depth" on each tile, either so you can go up/down stairs, or so you can have multiple tiles on each grid space.
There are better ways of doing both of those though, I'd say.
Cross post from the WAYWO thread:
It looks like everyone has no problems with collision at all, while my implementations are aweful.
I use a grid as spatial hashing method and the FPS are good.
So collision [B][U]detection[/U][/B] is no problem at all.
The core of the problem is how to get the collision [B]resolved [/B]nicely ??
With a AABB system I run into the same problems as SupahVee.
And there seems no good solution for those bugs.
For example: Jumping while steering moving the character into a wall to the right, (same problem as vee had) will result in the player being moved up/down instead of just out of the wall (to the left in that case).
edit:
In the other thread ralle105 said:
"Move it towards the side which has the least penetration."
I could do that, but there are a few things that make it buggy.
[img]http://i.imgur.com/vAgZ6.png[/img]
I'm assuming i process the colliding tiles in the order A,B,C. (Player is P)
The collision engine is going to move the player down, because the player has the least penetration on the vertical axis (with tile A).
But thats obviously wrong.
Any help?
In x86 assemablly what is the best way to learn the drive that you are booting from. For example if the pc I am booting from has a different os on it's main HDD and mine is on a USB stick, how do I find what drive number I am so I can use int13h commands.
I'm not against repetitive programming or anything. But say I am making a converter for length. Instead of making 40 if statements, is there another way to take in the input, figure out what needs to be converted, do the math, the return the result?
Example, I'm trying to avoid doing this again. I'm sure there is a better way.
[code]#include <iostream>
using namespace std;
char whatIsConvert; //variables
char convertTo;
long double cel;
long double fer;
long double convertPt1;
long double convertedNum;
long double kel;
//function definitions
void cToF()
{
convertPt1 = cel * (9.0f/5.0f);
fer = convertPt1 + 32;
}
void cToK()
{
convertPt1 = cel + 273;
kel = convertPt1;
}
void fToC()
{
convertPt1 = fer - 32;
cel = convertPt1 * (5.0f/9.0f);
}
void fToK()
{
convertPt1 = fer - 32;
cel = convertPt1 * (5.0f/9.0f);
kel = cel + 273;
}
void kToC()
{
convertPt1 = kel - 273;
cel = convertPt1;
}
void kToF()
{
kToC();
cToF();
}
int main()
{
cout << "Welcome to a converter program.\nYou can convert Celsius(c) to Fahrenheit(f), or Kelvin(k)\n";
cout << "Step one: Pick what what you want to convert. ";
cin >> whatIsConvert;
cout << "Step two: Convert to?(c, f or k)";
cin >> convertTo;
if (whatIsConvert == 'c' && convertTo == 'f')
{
cout << "You have choosen to convert Celsius into Fahrenheit.\n";
cout << "Enter the tempature in Celsius: ";
cin >> cel;
cToF();
cout << "The temperature is: " << fer << ".";
}
if (whatIsConvert == 'c' && convertTo == 'k')
{
cout << "You have choosen to convert Celsius into Kelvin.\n";
cout << "Enter the tempature in Celsius: ";
cin >> cel;
cToK();
cout << "The temperature is: " << kel << ".";
}
if (whatIsConvert == 'f' && convertTo == 'c')
{
cout << "You have choosen to convert Fahrenheit into Celsius.\n";
cout << "Enter the tempature in Fahrenheit: ";
cin >> fer;
fToC();
cout << "The temperature is: " << cel << ".";
}
if (whatIsConvert == 'f' && convertTo == 'k')
{
cout << "You have choosen to convert Fahrenheit into Kelvin.\n";
cout << "Enter the tempature in Fahrenheit: ";
cin >> fer;
fToK();
cout << "The temperature is: " << kel << ".";
}
if (whatIsConvert == 'k' && convertTo == 'c')
{
cout << "You have choosen to convert Kelvin into Celsius.\n";
cout << "Enter the tempature in Kelvin: ";
cin >> kel;
cout << "The temperature is: " << cel << ".";
}
if (whatIsConvert == 'k' && convertTo == 'f')
{
cout << "You have choosen to convert Kelvin into Fahrenheit.\n";
cout << "Enter the tempature in Kelvin: ";
cin >> kel;
kToF();
cout << "The temperature is: " << fer << ".";
}
system("pause");
return 0;
}
[/code]
[code]string AbbreviationToWord(char character) {
if(character== 'f')
return "Fahrenheit";
etc
}[/code]
[code]
cout << "You have choosen to convert " << AbbreviationToWord(whatIsConvert) << " into " << AbbreviationToWord(convertTo);
etc
[/code]
You should also look into switch statements.
[editline]13th September 2011[/editline]
My instincts tell me to have a function that converts everything to a standard format (celsius for instance), and then have another function that converts from that standard format to the desired format.
[code]
double ConvertToStandard(char current_format, double input_value);
double ConvertToDesired(char desired_format, double input_value);
[/code]
[QUOTE=RyanDv3;32270624][code]string AbbreviationToWord(char character) {
if(character== 'f')
return "Fahrenheit";
etc
}[/code]
[code]
cout << "You have choosen to convert " << AbbreviationToWord(whatIsConvert) << " into " << AbbreviationToWord(convertTo);
etc
[/code]
You should also look into switch statements.
[editline]13th September 2011[/editline]
My instincts tell me to have a function that converts everything to a standard format (celsius for instance), and then have another function that converts from that standard format to the desired format.
[code]
double ConvertToStandard(char current_format, double input_value);
double ConvertToDesired(char desired_format, double input_value);
[/code][/QUOTE]
Alright thank you! I think I'm going to re-write this program to use switch statements.
Also, I see you didn't use any of my earlier posted code; those functions you have now serve no purpose other than organizational. This is because you only use them once and they don't take input or output any values. There's also no need for globally declared variables.
Finally, don't shorten variable names, especially already short words like celsius. If it weren't for how simple your program is, this sort of naming would make it almost unreadable.
[QUOTE=RyanDv3;32270757]Also, I see you didn't use any of my earlier posted code; those functions you have now serve no purpose other than organizational. This is because you only use them once and they don't take input or output any values. There's also no need for globally declared variables.
Finally, don't shorten variable names, especially already short words like celsius. If it weren't for how simple your program is, this sort of naming would make it almost unreadable.[/QUOTE]
The global variables were a bad idea, sorry. And I am just using the functions for organization, it's just easier for me to see all the formulas in one place. What would you recommend other than that? And yeah, the variables are horribly named I guess, for some reason it works better in my mind like that, but I'm sure there is a better way. I'll get on renaming those.
[QUOTE=Werem00se;32270841]The global variables were a bad idea, sorry. And I am just using the functions for organization, it's just easier for me to see all the formulas in one place. What would you recommend other than that? And yeah, the variables are horribly named I guess, for some reason it works better in my mind like that, but I'm sure there is a better way. I'll get on renaming those.[/QUOTE]
Take a look at my CelsiusToFahrenheit() function at the top of this page. Also, don't worry, everyone here is learning.
When doing collision I get four values indicating the absolute value (I sound smart now) to push the player out in a direction.
I also check neighboring tiles, for example, If I determine the player should be pushed up, and there is a tile stacked above the one it's checking, it won't move up.
[QUOTE=RyanDv3;32270896]Take a look at my CelsiusToFahrenheit() function at the top of this page. Also, don't worry, everyone here is learning.[/QUOTE]
Alright, I'm going to figure it out myself (How you did it, what is means, ect) and apply it to all of the functions. Not going to worry about switches yet, I'm going to work on properly using functions first. I see how it works, I just have to put it together in my head to apply it to the others.
I'm learning C++ classes from a book and I ran into a problem while compiling:
Here's the error log:
[code]
$ g++ fig03_11.cpp -static-libstdc++
C:\Users\TERABY~1\AppData\Local\Temp\cc7glUGj.o:fig03_11.cpp:(.text+0x4a): undefined reference to `GradeBook::GradeBook(std::string)'
C:\Users\TERABY~1\AppData\Local\Temp\cc7glUGj.o:fig03_11.cpp:(.text+0x97): undefined reference to `GradeBook::GradeBook(std::string)'
C:\Users\TERABY~1\AppData\Local\Temp\cc7glUGj.o:fig03_11.cpp:(.text+0xbf): undefined reference to `GradeBook::getCourseName()'
C:\Users\TERABY~1\AppData\Local\Temp\cc7glUGj.o:fig03_11.cpp:(.text+0xd4): undefined reference to `GradeBook::getCourseName()'
collect2: ld returned 1 exit status[/code]
And here's the code of the files:
fig03_11.cpp
[cpp]// fig 3.10 pag 90
#include <iostream>
using std::cout;
using std::endl;
#include "GradeBook.h"
int main()
{
GradeBook gradeBook1( "Cucina applicata" );
GradeBook gradeBook2( "Fisica spaziale" );
cout << "gradeBook1 creato per il corso: " << gradeBook1.getCourseName()
<< "\ngradeBook2 creato per il corso: " << gradeBook2.getCourseName()
<< endl;
return 0;
}[/cpp]
GradeBook.h
[cpp]// f 3.11 GradeBook.h
#include <string>
using std::string;
class GradeBook
{
public:
GradeBook( string );
void setCourseName( string );
string getCourseName();
void displayMessage();
private:
string CourseName;
};[/cpp]
GradeBook.cpp
[cpp]// 3.12 pag 95
#include <iostream>
using std::cout;
using std::endl;
#include "GradeBook.h" //definizione classe
GradeBook::GradeBook( string name )
{
setCourseName( name );
}
void GradeBook::setCourseName( string name )
{
courseName = name;
}
string GradeBook::getCourseName()
{
return courseName;
}
void GradeBook::displayMessage()
{
cout << "Welcome to the gradebokk for " << getCourseName() << endl;
}
[/cpp]
I tried troubleshooting but I can't find out what's wrong here. Can anyone help?
Okay, so you are declaring Celsius here : [code]double CelsiusToFahrenheit(double celsius)
{
return (celsius/ (5 / 9.0))+ 32;
}[/code] as a parameter in a function. Right?
Then when you get to this point [code]cin >> input_value;
cout << "The temperature is: " << CelsiusToFahrenheit(input_value) << ".";[/code] input_value turns into Celsius, and from there does it's math and returns input_Value as the converted number. Right? This is what I've got by staring at it for 20 minutes, trying to put it together, any of it right?
[QUOTE=Werem00se;32271303]Okay, so you are declaring Celsius here : (code) as a parameter in a function. Right?
Then when you get to this point [code]cin >> input_value;
(code) input_value turns into Celsius, and from there does it's math and returns input_Value as the converted number. Right? This is what I've got by staring at it for 20 minutes, trying to put it together, any of it right?[/QUOTE]
Yep
[editline]13th September 2011[/editline]
[QUOTE=TerabyteS_;32271217]I'm learning C++ classes from a book and I ran into a problem while compiling:
stuff
I tried troubleshooting but I can't find out what's wrong here. Can anyone help?[/QUOTE]
I just compiled it, and the only error I got was that you used "courseName" instead of the correct "CourseName" twice.
[QUOTE=TerabyteS_;32271217]Can anyone help?[/QUOTE]
Build with g++ fig03_11.cpp GradeBook.cpp -static-libstdc++.
I'm trying to compile SFML with VS2010, and the .libs and .dlls it generates don't seem to be usable.
If I want to use the dynamic version, I can't, because no sfml-xxxx-d.lib files are compiled.
If I want to sue the static version, I cant, because although I add the sfml-xxx-s-d.lib files to my linker inputs, I still get linker errors as if I hadn't.
[editline]13th September 2011[/editline]
I remember using SFML was aggravating after switching to VS2010, I'm just surprised that years later, the problem still exists.
Of course, I'm probably doing something like an idiot, so point it out so I can get on with my work.
[QUOTE=RyanDv3;32272018]I'm trying to compile SFML with VS2010, and the .libs and .dlls it generates don't seem to be usable.
If I want to use the dynamic version, I can't, because no sfml-xxxx-d.lib files are compiled.
If I want to sue the static version, I cant, because although I add the sfml-xxx-s-d.lib files to my linker inputs, I still get linker errors as if I hadn't.
[editline]13th September 2011[/editline]
I remember using SFML was aggravating after switching to VS2010, I'm just surprised that years later, the problem still exists.
Of course, I'm probably doing something like an idiot, so point it out so I can get on with my work.[/QUOTE]
SFML 1.6 or 2.x-git?
1.6
[QUOTE=RyanDv3;32257482]I cleaned up your code a bit:
[cpp]
double CelsiusToFahrenheit(double celsius)
{
return (celsius/ (5 / 9.0))+ 32;
}
[/QUOTE]
Celsius to Fahrenheit F = (C x 9/5) + 32
I'm so confused on how yours works.
[QUOTE=RyanDv3;32272240]1.6[/QUOTE]
Just use 2.0.
[editline]13th September 2011[/editline]
[QUOTE=Werem00se;32272257]Celsius to Fahrenheit F = (C x 9/5) + 32
I'm so confused on how yours works.[/QUOTE]
He's dividing by 5/9 which is the same as multiplying with 9/5.
[QUOTE=thf;32272470]Just use 2.0.
[/QUOTE]
This would appear much harder than overcoming my problems with 1.6...
[QUOTE=RyanDv3;32272707]This would appear much harder than overcoming my problems with 1.6...[/QUOTE]
Why not just get used to it right now? It's going to be the next version anyway.
If I'm having trouble with the official version, trying the development snapshot seems foolhardy.
Anyways, I found a temporary workaround, so whatever. If anyone can explain why I'm getting those issues, do tell.
[QUOTE=ZeekyHBomb;32271651]Build with g++ fig03_11.cpp GradeBook.cpp -static-libstdc++.[/QUOTE]Does this mean that I'll have to specify every single one of the external classes' name when I compile? Oh god this sucks
[QUOTE=TerabyteS_;32272950]Does this mean that I'll have to specify every single one of the external classes' name when I compile? Oh god this sucks[/QUOTE]
Usually you use a build system (makefiles, CMake, premake, IDE solutions), not manually typing that stuff in.
[QUOTE=Jookia;32273189]Usually you use a build system (makefiles, CMake, premake, IDE solutions), not manually typing that stuff in.[/QUOTE]Could you give me more information on how that works please? I'm currently compiling with MinGW.
So, whenever I tried to convert Fahrenheit to Celsius in a one step line it gave me the wrong answer. No matter what I tried. So, I had to use this confusing line of code.
[code]double FahrenheitToCelsius(double fehrenheit)
{
double placeHolder = fehrenheit - 32;
fehrenheit = placeHolder * (5.0f/9.0f);
return fehrenheit;
}[/code]
[editline]13th September 2011[/editline]
Or is that acceptable?
Sorry, you need to Log In to post a reply to this thread.