|
|
It looks like homework.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
I'm attempting (and failing horribly) to put a function that draws multiple circles into an array.
I will be using flags to turn the circles on and off, and I need to initialize it in my main function so the random generator won't run every time the screen refreshes. This is what I have so far in putting my circles in an array:
I get an error on this first line here saying : c:26: error: expected identifier or ‘(’ before ‘[’ token
I've no idea why, it looks like it's set up right to me
struct Row1[15] = {drawCircleRow1()}
int drawCircleRow1()
{
for
(o=0; o<15; o++)
{
random_generator(0,3);
glPushMatrix();
glTranslatef((o+1.9)*28,455,1);
if (randomValue == 0)
{
glColor3f(0,.5,0);
}
else if (randomValue == 1)
{
glColor3f(.5,0,0);
}
else
{
glColor3f(0,0,.5);
}
glLineWidth(1.0);
drawCircle(14,200);
glPopMatrix();
}
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
ballPhysics();
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowSize(WIDTH, HEIGHT);
glutCreateWindow("Bubble Buster");
glutDisplayFunc(displayFunction);
glutSpecialFunc(functionSpecial);
glutKeyboardFunc(keyboardFunction);
glutTimerFunc(1,timerFunction,0);
gluOrtho2D(0, WIDTH, 0, HEIGHT);
glClearColor(1, 1, 1, 0);
glutMainLoop();
return 0;
}
|
|
|
|
|
"o" is by far the worst identifier one could possibly choose for a variable as it is short (OK, so are "i" and "n"), and easily confused with "0".
|
|
|
|
|
Nah, 'O ' is worse. And 'thisIsTheOuterLoopIndex' even worse.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: 'O' is worse. And 'thisIsTheOuterLoopIndex' even worse.
Nope. 'O' is better than 'o' as you have better probability in finding (and replacing) those in an editor without hitting keywords such as 'for' and 'continue'; and 'thisIsTheOuterLoopIndex' is self-descriptive which is good (unless it were incorrect).
|
|
|
|
|
Luc Pattyn wrote: 'thisIsTheOuterLoopIndex' is self-descriptive which is good
Way too long. Maybe it could be reduced to an acronym? You know, something like tIT_OLI?
|
|
|
|
|
Well, acronym is appropriate with T heO uterO uterL oopO nlyN eededG lolbal...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You know, I hear that all the time...
|
|
|
|
|
Luc Pattyn wrote: 'thisIsTheOuterLoopIndex' is self-descriptive
Nope: it's idiotic (well, it's a self-descriptive-idiotic identifier).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
Good night, Luc.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You really need to study basic array operations before trying to tackle something like this. There are so many things wrong with the first line alone it's difficult to know where to start...
1) Is Row1 a type you've defined? (It looks like it, since you say it's a struct...)If so, the array declaration is missing a variable name. Or...
2) Is Row1 the variable name? (It looks like it, since you're trying to initialize the array with int's, and not Row1 objects.) If so, you're missing the type, and you misuse the struct keyword...
Like I said, I'd suggest hitting the books and studying array basics. It's really difficult to offer advice on more complicated issues like ball movement if errors with the basics keep us from understanding your intent.
And thanks for using the code block tag. Not to be a nag, but you still need to look at standard indentation practices - reading your code is more difficult than it need be. (Hint - select the code in Visual Studio and simultaneously press Shift+Alt+F.)
Just trying to help, man.
|
|
|
|
|
Alright, I'll go read up on arrays some more, do you know any good sites that explains arrays using C?
I'm using Ubuntu, not Visual Studio, I've been tabbing over myself.
|
|
|
|
|
Chidori-chan wrote: do you know any good sites that explains arrays using C?
Buy any book on C; Kernighan & Ritchie wrote the definitive one some thirty years ago, which explains everything in concise detail.
|
|
|
|
|
Here, check these out -
C++ Arrays[^]
C++ Beginner's Guide[^]
The second one is an ebook that you have to download a chapter at a time. Check out chapter 4.
Don't get discouraged. You just need to get a couple basic concepts under your belt and the program will probably fall into place pretty easily.
|
|
|
|
|
Hi,
I have a small project and I need help on how to get the complete path and filename on Drag and Drop to a listbox. Afterwhich, I have to run another application to process the file and output the result on the same path and with a different filename. I'm using Visual C++ express edition 2005 (windows froms).
roughly like:
private: System::Void listbox1_DragDrop(System::Object^ sender, System::Windows::Forms::DragEventArgs^ e) {
//get filename and complete path
//execute a C++ application .exe to process file with an output
//change the output filename on the same path
//open excel (.csv) application to display the ouput file
}
and I'm planning to improve it further.
Sorry, if this question has been asked before. I'm really new in Visual C++ and want to learn by creating this small project.
The .exe that I want to run was also written by me on a console application (C++) and want to re-use it using GUI.
Thanks and Regards....
|
|
|
|
|
please, just a little help...
|
|
|
|
|
Well,
I have not used the Visual C++ 2005, but in Visual C++ 6 you can get the filename and the complete path with:
extern CMyApp theApp;
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
char FileName[MAX_PATH];
GetModuleFileName(NULL, FileName, MAX_PATH);
CString m_szName = FileName;
m_szName = m_szName.Left(m_szName.ReverseFind('\\'));
m_szName += "\\MyNewName.ext";
CFile f (m_szName, CFile::modeCreate | CFile::modeReadWrite);
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
I've been working on getting a circle to fire out of a cannon and move across the screen, but the closest I've come is making it jump to the end point. I think it's because of where I'm putting the function. However, wherever else I've put it, it has frozen my program.
So what I'm wanting, is when I press my space bar, my single circle from the draw fire function below to be seen moving across the screen to the top.
Here's the snippets of my code that pertain to this function:
float fire;
glPushMatrix();
glTranslatef(250+aim,102+fire,1);
random_generator(0,3);
if (randomValue == 0)
{
glColor3f(0,.5,0);
}
else if (randomValue == 1)
{
glColor3f(.5,0,0);
}
else
{
glColor3f(0,0,.5);
}
glLineWidth(1.0);
drawFire(14,200);
glPopMatrix();
void keyboardFunction(unsigned char key, int x, int y)
{
switch (key)
{
case 'r' : d=1; break;
case 's' : d=2; break;
case ' ' :
for (fire=0; fire<353; fire++)
{
};
break;
}
glutPostRedisplay();
}
Do you all have any idea what I could do to make it move across the screen instead of jumping?
|
|
|
|
|
Your code is not very clear but it seems you are trying to move your circle inside a for loop (even if this loop is empty). That's not going to work: you need to render the full scene each time something change or at a specific time rate (which is usually used for games). As you have one single thread (and you shouldn't have more in this situation), your for loop will prevent any redrawing on the screen (thus, you see a jump). You need to keep a flag that specifies if the circle is moving or not and if this flag is set, you ahve to update the circle position at each frame depending on the elapsed time.
If your program is written in C++ (and not pure C), I suggest you take a look at my signature for the OpenGL tutorial. All these things are explained but you need to have a good background in C++.
|
|
|
|
|
Thanks, but do you know of any tutorials that are pure C? That's what I'm writing my code in.
|
|
|
|
|
void RFX_Text_Bulk(
CFieldExchange* pFX,
LPCTSTR szName,
LPSTR* prgStrVals,
long** prgLengths,// show how to setup and implement
int nMaxLength
);
I need for someone to show me how to setup and implement this field " long** prgLengths"
all examples I've seen shows long* prgLengths in the header and prgLengths = NULL; in the constructor.
I tried that in my program and it came up with an error(compiler) that last two varables not implemented, meaning
long** prgLengths and int nMaxLength .
I have a CString that can at times greatly exceed the max of 255 char. That's why I need to implement the RFX_Text_Bulk function, but I can't find an example to show me how to do so.
Can anyone show me how with a working example. Please note that most times this varable will not be longer that 255 char, then there are times that it will!
A C++ programming language novice, but striving to learn
|
|
|
|
|
My best guess without reading the documentation:
CFieldExchange fieldX;
LPCTSTR szName[256];
LPSTR prgStrVals;
long* prgLengths;
int nMaxLength = 255;
RFX_Text_Bulk(&fieldX, szName, &prgStrVals, &prgLengths, nMaxLength);
Just provide the address of the variable that is a pointer to a long.
|
|
|
|
|
Sorry, that doesn't work. I thought the same thing. they want something for "prgLengths" but I don't know what. I've tried many examples shown through out the internet, but the errors remain.
A C++ programming language novice, but striving to learn
|
|
|
|
|