GDICommander 54 Posting Whiz in Training

Can you divide your window into sections (like address info, preferences, interests), so you can query sections like this:

addressInfo.Fill(l_text);
preferences.Fill(l_text);
interests.Fill(l_text);

It will distribute your construction of the l_text variable over the sections and make the code less ugly by having less bigger methods.

I suggest, if it's the case, that you consider refactoring your code in more managable sections and class, instead of having one big class.

For the "for" loop, just put it in a method with a name like "BuildTextVar". It will look like this:

public string BuildTextVar()
{
string l_text;
//Insert for loop here.
return l_text;
}

Hope this helps!

GDICommander 54 Posting Whiz in Training

Since you're new to programming, I will tell you some programming tips:

-Try to indent your code (inserting tabs or spaces when you're between brackets).
It will make your loops (for), your conditions (if) and all your code more easy to read and understand.
For example:

int main()
 {
     return 0; //Inserting tab to make the code more readable.
 }

Your code will look like:

FactorialClass factorial = new FactorialClass();
factorial.CalculateFactorial(4);

OR

FactorialClass.CalculateFactorial(4); //Static method invocation (no need of creating an object)

AND

UseFactorial useF = new UseFactorial();
useF.CalculateFactorial(4);

In C#, you create a class like this:

class MyClass
{
    //A method example (this is a comment)
    public void MyMethod()
    {
    }
}

I will leave to you the work of implementing CalculateFactorial methods.

Hope this helps.

GDICommander 54 Posting Whiz in Training

I found a solution to my problem. It was a bug of EndDialog in MFC that reactivates the parent even if there is more modal windows still active and attached to the same parent.

See this page for more details:

http://www.codeproject.com/KB/dialog/notmodaldialogs.aspx?msg=3289022

GDICommander 54 Posting Whiz in Training

Hello!

I have problems with modal MFC windows over 3dsMax.

I'm popping a MFC modal window over 3dsMax (I'm programming a plugin for 3dsMax, if you mind), so I can't click on any 3dsMax window button, because the modal window is here.

The modal window, by clicking on a button, then makes a .NET window appear on another application. The modal window is still there. (The communication between the plugin and the other application is done with COM.) The problem is the following: when the .NET window is closed, the MFC window seems to lose its modality. I can click on 3dsMax buttons and I don't want that.

Can you propose me solutions to this?

GDICommander 54 Posting Whiz in Training

Hello, everyone!

I'm using the Win32 API PeekMessage function to retrieve key stroke events. I have a problem: suppose that someone holds the A button. PeekMessage will return messages for the A press event. Now, while A is pressed, someone holds B. PeekMessage will return only the B press event message.

Do you know a way to retrieve A messages, even if B is holded by the player?

Thank you!

GDICommander 54 Posting Whiz in Training

There is also the Windows calculator who can do decimal-to-binary and binary-to-decimal transformations. It might be useful if you want to validate what you do in code.

GDICommander 54 Posting Whiz in Training

The key type is a template type provided by the client code. I don't want to force the client to implement an operator<, just for the std::map part of an algorithm.

GDICommander 54 Posting Whiz in Training

Hi, everyone!

I'm in search of an associative container that does not need an implementation of operator< for the key type. std::map and std::set requires that, so I think that I need another kind of associative container.

I can always implement my own contained using a vector of pairs, but I will lose the O(1) access of a key-value pair.

Can you help me?

GDICommander 54 Posting Whiz in Training

I found the solution for my problem. I forgot to add the Xerces libraries to one of my test projects of my Visual Studio studio. I also added the /bin directory of Xerces in the PATH environment variable to be able to use the .dlls.

I hope that this may help someone in the future.

Salem commented: Nice - and good job :) +18
GDICommander 54 Posting Whiz in Training

Hi, everyone!

When I'm building my project on Visual Studio 2008 that uses Xerces, I have the following linker errors:

2>XmlPersistingService.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl xercesc_2_8::XMLPlatformUtils::Initialize(char const * const,char const * const,class xercesc_2_8::PanicHandler * const,class xercesc_2_8::MemoryManager * const,bool)" (__imp_?Initialize@XMLPlatformUtils@xercesc_2_8@@SAXQEBD0QEAVPanicHandler@2@QEAVMemoryManager@2@_N@Z) referenced in function "public: __cdecl XmlPersistingService::XmlPersistingService(char const *)" (??0XmlPersistingService@@QEAA@PEBD@Z)
2>XmlPersistingService.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static char const * const xercesc_2_8::XMLUni::fgXercescDefaultLocale" (__imp_?fgXercescDefaultLocale@XMLUni@xercesc_2_8@@2QBDB)
2>XmlPersistingService.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl xercesc_2_8::XMLPlatformUtils::Terminate(void)" (__imp_?Terminate@XMLPlatformUtils@xercesc_2_8@@SAXXZ) referenced in function "public: __cdecl XmlPersistingService::~XmlPersistingService(void)" (??1XmlPersistingService@@QEAA@XZ)
2>XmlPersistingService.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class xercesc_2_8::DOMImplementation * __cdecl xercesc_2_8::DOMImplementationRegistry::getDOMImplementation(wchar_t const *)" (__imp_?getDOMImplementation@DOMImplementationRegistry@xercesc_2_8@@SAPEAVDOMImplementation@2@PEB_W@Z) referenced in function "public: void __cdecl XmlPersistingService::WriteToXml(class Bill const &)" (?WriteToXml@XmlPersistingService@@QEAAXAEBVBill@@@Z)
2>XmlPersistingService.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static wchar_t * __cdecl xercesc_2_8::XMLString::transcode(char const * const)" (__imp_?transcode@XMLString@xercesc_2_8@@SAPEA_WQEBD@Z) referenced in function "public: void __cdecl XmlPersistingService::WriteToXml(class Bill const &)" (?WriteToXml@XmlPersistingService@@QEAAXAEBVBill@@@Z)

I added the required libs (xerces-c_2_D.lib and the rest) in the input libs of the linker settings. I added the <xercesc>/lib directory, so the linker can find them. The famous "Treat wchar as data type" option is turned on.

I have a 64-bit machine, so I downloaded the xerces-c_2_8_0-x86_64-windows-vc_8_0.zip package on the Xerces-C++package.

Unfortunately, the linker errors are still there. Can you help me?

GDICommander 54 Posting Whiz in Training

Thanks for the help! I didn't know that the copy constructor of a class that is thrown needs to be public.

GDICommander 54 Posting Whiz in Training

Hi, everyone!

I'm having trouble with a linker error (I'm using Visual Studio 2008) and I would like to have some tips on solving this problem:

This is my code:

Bill.cpp

#include "Bill.h"
#include "../Exceptions/InvalidArgumentException.h"

Bill::Bill()
{

}

Bill::Bill(string shopName)
{
	if (shopName == "")
	{
		throw(InvalidArgumentException("The shop name cannot be empty."));
	}

	m_shopName = shopName;
}

InvalidArgumentException.h

#ifndef INVALIDARGUMENTEXCEPTION_H
#define INVALIDARGUMENTEXCEPTION_H

#include <exception>

using namespace std;

class InvalidArgumentException : public exception
{
public:
	InvalidArgumentException(const char* invalidArgument);

	const char* what() const throw();

	static size_t MaximumMessageLength()
	{
		return 100;
	}

private:
	InvalidArgumentException();
	InvalidArgumentException(const InvalidArgumentException&);

	void InitializeMessage();
	void ValidateArgument(const char* invalidArgument);

	const char* m_invalidArgument;
	char m_message[100];		//TODO: Change the way of returning a const char*. That's ugly to use an automatic-allocated array.
};

#endif

InvalidArgumentException.cpp

#include <string>

#include "InvalidArgumentException.h"

//Public Methods

InvalidArgumentException::InvalidArgumentException(const char* invalidArgument)
{
	ValidateArgument(invalidArgument);

	m_invalidArgument = invalidArgument;
	InitializeMessage();
}

const char* InvalidArgumentException::what() const throw()
{
	return m_message;
}

//Private Methods

void InvalidArgumentException::InitializeMessage()
{
	strcpy_s(m_message, m_invalidArgument);
}

void InvalidArgumentException::ValidateArgument(const char* invalidArgument)
{
	if (invalidArgument == 0)
	{
		throw(std::exception("The message pointer is null."));
	}
	else if (strlen(invalidArgument) == 0)
	{
		throw(std::exception("The message is empty."));
	}
	else if (strlen(invalidArgument) > MaximumMessageLength())
	{
		throw(std::exception("The message is too long."));
	}
}

The linker output is:

1>Linking...
1>LINK : .\Output\Debug\Billzilla.exe not found or not built by the last incremental link; performing full link
1>Bill.obj : error LNK2001: unresolved external symbol "private: __thiscall InvalidArgumentException::InvalidArgumentException(class InvalidArgumentException const &)" (??0InvalidArgumentException@@AAE@ABV0@@Z)
1>.\Output\Debug\Billzilla.exe : fatal error LNK1120: 1 unresolved externals

GDICommander 54 Posting Whiz in Training

Yeah, just ask your questions and post some code on the forum. It's the better way, more people can answer your questions.

GDICommander 54 Posting Whiz in Training

Why don't you write that for getting input from the user:

string breed;
cin >> breed;

This method does not get the "\n".

GDICommander 54 Posting Whiz in Training

Just post your code if you have problems and we'll check it.

GDICommander 54 Posting Whiz in Training

Unfortunately, I cannot send you the assemblies because of the security policies of where I work.

I tried to add the directory path of the Photoshop CS4 executable to the %PATH% variable (because it wasn't here), but it didn't work.

Maybe I will try to uninstall CS3 and see if the ApplicationClass constructor launches CS4, but it is not an acceptable workaround for the user of my program. Any other ideas?

GDICommander 54 Posting Whiz in Training

Unfortunately, I can't call Process.Start() because I will need to get the opened images in Photoshop in my code. So, I need a "pointer" on the application and ApplicationClass can provide it to me.

GDICommander 54 Posting Whiz in Training

Hi, everyone!

I am using Interop.Photoshop.Dll from my C# Windows Forms application. I am using a com object that Adobe Photoshop CS4 provides to use Photoshop in my C# program.

I'm using the ApplicationClass class to launch Photoshop. I have Photosoft CS3 and CS4 on my machine. When I do this:

Photoshop.ApplicationClass app = new Photoshop.ApplicationClass()

It launches Photoshop CS3 and does not launch CS4. Is there someone who knows the cause of this?

P.S: I checked my registry at // HKEY_CLASSES_ROOT\Photoshop.AdobePlugin\shell\open\command and it points to the Photoshop CS4 executable.

GDICommander 54 Posting Whiz in Training

Hi, everyone!

I'm writing a program in C# that needs to know opened files in a Photoshop CS4 window.

The old versions of Photoshop have a MDIClient window in the program that can be getted with GetWindow() and GetClassName() calls. So, I can get the name from the window title bar and parse it from this format: name @ pictureattributes. Unfortunately, CS4 does not have a MDIClient, so I can't use this method to get the name, for now.

Is there someone who can point me to a possible solution to this problem?

GDICommander 54 Posting Whiz in Training
GDICommander 54 Posting Whiz in Training

If your operator=() works, extract the code that creates a new list with the one provided as a parameter and use it in your copy constructor. Search for the refactoring tip Extract Method.

GDICommander 54 Posting Whiz in Training

According to http://msdn.microsoft.com/en-us/library/yt4xw8fh.aspx :

The /Wp64 compiler option and __w64 keyword are deprecated and will be removed in a future version of the compiler. If you use the /Wp64 compiler option on the command line, the compiler issues Command-Line Warning D9035. Instead of using this option and keyword to detect 64-bit portability issues, use a Visual C++ compiler that targets a 64-bit platform. For more information, see 64-Bit Programming with Visual C++.

For your information, there are 2 types of processors: 32-bit and 64-bit. If you have a 32-bit processor, the compiler will produce processor instructions understandable for your 32-bit processor. (32 0 or 1) It's the same thing for 64-bit processors.

The Visual C++ Compiler will produce 64-bit instructions at compile time for your program if you select x64 as the target. If you select Win32, it will produce 32-bit instructions for your processor. Note that the /w64 flag (Detect 64-bit portability issues) on the command line is deprecated. So, it is recommended to only select the target (Win32 or x64) for your needs and not use the flag.

For the subsystem, check here for more details: http://msdn.microsoft.com/en-us/library/fcc1zstk%28VS.71%29.aspx. Windows should be ok, but choosing an other choice will optimize the executable, for example POSIX, if you want to develop a multi-threaded application.

GDICommander 54 Posting Whiz in Training

If you are using UNIX, you can use valgrind to check for memory leaks. You need to add --tool=memcheck on the command line to check for leaks.

GDICommander 54 Posting Whiz in Training

For the step 13, it tells Visual Studio to include these libraries for the link, because the functions you are using with SDL are implemented in these libraries. The librairies must be in the additional library directories (in Linker/General) or in C:\Program Files\Microsoft Visual Studio (your number)\VC\lib.

GDICommander 54 Posting Whiz in Training

You can implement a sort strategy on your linked list, like bubble sort, quick sort, merge sort. Some strategies do not require an additionnal container for the answer.

GDICommander 54 Posting Whiz in Training

It is normal that you jump directly to system("pause") when the operator is not correct the first time. You are leaving the if-else clause after the second input prompt. You should do something like...

while(input is not correct)
{
//Ask for input
//Verify it.
}

GDICommander 54 Posting Whiz in Training

You should pay attention to how you have divided your problem into functions.

A function like computeCommission(int price) can be useful...

GDICommander 54 Posting Whiz in Training

http://www.codeguru.com/forum/showthread.php?t=366064

You can use std::sort with a STL container, like a vector or a list. You will need to write a function that determines if a element is greater that an other one.

GDICommander 54 Posting Whiz in Training

Your main() should be in an other file...

GDICommander 54 Posting Whiz in Training

Looks good, but there is a piece of code I would like to show you:

if(is_door_opened==true)

You can simplify this conditionnal expression with:

if (IsDoorOpened())

and make this method private, if no other entity external to the class has a need for it. This is a refactoring tip (Simplify Conditional Expressions) and not a object-oriented tip. When you have a lot of AND and OR in a condition, better use a method like the one presented to make the code more readable.

GDICommander 54 Posting Whiz in Training

This behavior is expected, because the operator >> of cin reads input in his stream until a end-of-line or a whitespace is found. So, the next operator>> call finds remaining input (the other words after the whitespace) in the cin buffer and takes the data. If you want to prevent this situation, you need to truncate the input to the first whitespace or the end-of-line character. You can do it by doing a fscanf call like this:

fscanf(stdin, %s\n, your_string_variable);

This is a C-style way to do it and I would like to see other ways, C++ oriented, to prevent a whitespace in the input.

GDICommander 54 Posting Whiz in Training

I did a mistake in my last post: the >> operator reads data until a end-of-line character OR a whitespace is found.

GDICommander 54 Posting Whiz in Training

http://www.csse.monash.edu.au/~jonmc/CSE2305/Topics/10.19.OpOverload/html/text.html

On this page, look the Complex class example at the bottom. It explains that you need to declare the prototype of the function as "friend" in the class.

GDICommander 54 Posting Whiz in Training

This site helped me a lot to understand the design patterns:

http://sourcemaking.com/design_patterns

GDICommander 54 Posting Whiz in Training

Are you sure that the file denoted with the name you provided exists?

I'm pretty sure that the answer is yes, but do you really have gSize vertices in your file? Do you really have a line at each end of a vertex definition in your file that is -999? Do you have a operator!= that takes a int has a parameter?

Remember that the >> operator reads data until a end-of-line character is found (this operator reads a line in a file).

If it's possible, can you post the content of the input file?

GDICommander 54 Posting Whiz in Training

Hello everyone!

I'm having a bad time trying to find a solution to my problem:

I'm developping a client-server application. On the server side, I am calling a method, Recoit (receive), that calls internally msgrcv(), a UNIX system call for message-passing purposes. The problem is that I always receive a "Arg list too long" error message. According to this site, http://publib.boulder.ibm.com/iseries/v5r1/ic2924/index.htm?info/apis/ipcmsgrc.htm, the size of the message I passed to Recoit is too small for the real data size of the message. I really don't know how to solve this problem. This is the necessary code to understand the problem. Note that the error is one the first Recoit call in start().

/**
	\brief Cette fonction part le serveur.
*/
void start(int listenPortNb)
{
	if (listenPortNb == -1)
	{
		std::cout << "You have forget to set a listening port number." << std::endl;
		return;
	}

	int basePortNb = 90000000;
	int offsetValue = 0;

	Port connPort(listenPortNb);
	while (true)
	{
		//Réception de la demande de connexion.
		Message connRequest;
		std::cout << "Message size: " << MSG_SIZE << std::endl;
		connPort.Recoit(&connRequest, MSG_SIZE);		//Attente bloquante.

		std::cout << "The server has received " << connRequest.mtype << std::endl;

		//Traitement de la requête de connexion.
		if (connRequest.mtype == CONN_REQUEST)
		{
			//On décide du numéro du port qui sera utilisé.
			int* connPortNb = (int*) malloc(sizeof(int));
			*connPortNb = basePortNb + offsetValue;		//TODO: Ce sera le thread qui devra libérer la mémoire.
			//Incrémentation de l'offset pour la prochaine connexion.
			++offsetValue;

			//On bâtit le message à retourner au client.
			Message …
GDICommander 54 Posting Whiz in Training

Thank you for your help. It worked when I added pcslib.cpp with the other file on the command line with g++.

GDICommander 54 Posting Whiz in Training

Hello, everyone! It's been a long time using C++ and I have a link problem.

This is the code...

#include <iostream>
#include "libc++/pcslib.h"

int main()
{
        std::cout << "About to load the server and all the clients." << std::endl;

        Pcs serverProcess("server");
        Pcs clientProcess("client");

        serverProcess.Join();
        clientProcess.Join();

        std::cout << "After joining with processes." << std::endl;                       

        return 0;
}

The included file pcslib.h is:

#include <unistd.h>
#include <stdio.h>
#include <iostream>
#include <sys/wait.h>
#include <signal.h>
#include <errno.h>

class Pcs {
   private:
      int pcsid;
      int status;
   public:
      Pcs();
      Pcs(char *fichier);
      void Fork(char *fichier);
      int Join();
      void Detruit();
};

There's a cpp file, pcsfile.cpp, that implements the public methods. When I'm passing the first block of code to the compiler (g++), I'm having this message and I don't know why. Can you help me?

Undefined first referenced
symbol in file
Pcs::Join() /var/tmp//ccsCx3jl.o
Pcs:: Pcs(char*) /var/tmp//ccsCx3jl.o
ld: fatal: Symbol referencing errors. No output written to loader
collect2: ld returned 1 exit status

GDICommander 54 Posting Whiz in Training

Hello everyone!

I'm looking for a class in the Java API that can take the complete structure of a directory in itself and that can be passed on sockets, so it can be used on other machines of a network.

Is there someone that can show me an existing class? I think that a File object cannot be used on an another machine for navigating through a directory structure, so I'm looking for another class.

Thank you for your help!

GDICommander 54 Posting Whiz in Training

Hello everyone! It's me again.

I replaced malloc calls with calloc and I put sizeof(char*) for the memory allocation call for the rows of the 2D array. There are no runtime errors.

Thank you for introducing me to calloc and for helping me with memory allocation in C!

GDICommander 54 Posting Whiz in Training

Unfortunately, no. Now I have a runtime error on the free() call at the last line of fillArray(). The change of char* to char for referenceArray has introducted a new problem in the fillArray() function. I should look at it before debugging other sections of code.

GDICommander 54 Posting Whiz in Training

Ok, here is the complete code.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//Variables globales.
int width;
int height;

const char ALIVE = '1';
const char DEAD = '0';

char** referenceArray;

void fillArray(char** referenceArray, FILE* grid)
{
	//Chaîne qui va contenir une ligne du fichier.
	char* lineContent = malloc((width + 1) * sizeof(char));		//Pour contenir le "\0"
	
	int i, j;

	for (i = 0; i < height; ++i)
	{
		printf("Iteration nb %d\n", i);
		referenceArray[i] = malloc(width * sizeof(char));	//Allocation de la mémoire pour une ligne du tableau.
		fgets(lineContent, width + 1, grid);	//width + 1 pour aller chercher "width" caractères.
		printf("String: %s\n", lineContent);

		for (j = 0; j < width; ++j)
		{
			referenceArray[i][j] = lineContent[j];
		}

		fgets(lineContent, 2, grid);		//On se débarasse du "\n" au bout.
	}

	free(lineContent);
}

/**
	\brief Détermine si une cellule est vivante.
*/
int isAlive(char* cell)
{
	return (*cell == ALIVE) ? 1 : 0;
}

/**
	\brief Détermine si une cellule est morte.
*/
int isDead(char* cell)
{
	return (*cell == DEAD) ? 1 : 0;
}

/**
	\brief Compte le nombre de voisins d'une cellule.
	\param i	Rangée i de la cellule.
	\param j	Colonne j de la cellule.
	\return	Le nombre de voisins.
*/
int countNeighbors(int i, int j)
{
	int up = i-1;
	int bottom = i+1;
	int left = j-1;
	int right = j+1;

	int neighborCount = 0;

	int currentI, currentJ;

	//Si on est à gauche du tableau, on n'ira pas vérifier à gauche de la cellule.
	if (left < …
GDICommander 54 Posting Whiz in Training

I don't think that I'm freeing the 2D array twice, because it is filled first in the fillArray() function. The referenceArray pointer is cleaned first and points to the newReferenceArray pointer. Then newReferenceArray becomes a new reference array again. The "referenceArray" pointer is supposed to delete the memory of the old new referenceArray and to point on the new referenced array.

Note: I have updated the code with the fillArray() function.

GDICommander 54 Posting Whiz in Training

Hello, everyone!

I have a problem with memory free. Here is the necessary code to understand the problem:

void fillArray(char** referenceArray, FILE* grid)
{
	//Chaîne qui va contenir une ligne du fichier.
	char* lineContent = malloc((width + 1) * sizeof(char));		//Pour contenir le "\0"
	
	int i, j;

	for (i = 0; i < height; ++i)
	{
		printf("Iteration nb %d\n", i);
		referenceArray[i] = malloc(width * sizeof(char));	//Allocation de la mémoire pour une ligne du tableau.
		fgets(lineContent, width + 1, grid);	//width + 1 pour aller chercher "width" caractères.
		printf("String: %s\n", lineContent);

		for (j = 0; j < width; ++j)
		{
			referenceArray[i][j] = lineContent[j];
		}

		fgets(lineContent, 2, grid);		//On se débarasse du "\n" au bout.
	}

	free(lineContent);
}


char** referenceArray;
char** newReferenceArray;

referenceArray = malloc(height * sizeof(char*));
fillArray(referenceArray, grid);

do
	{
		survivorCount = 0;

		newReferenceArray = computeNextGen(&survivorCount);

		printf("Survivor count: %d\n", survivorCount);

		//TODO: Memory free problems!
		for (i = 0; i < height; ++i)
		{
			free(referenceArray[i]);
		}
		free(referenceArray);

		referenceArray = newReferenceArray;

		++generationCount;
	}
	while (survivorCount != 0 && generationCount < generationLimit);

And here is the computeNextGen function.

char** computeNextGen(int* survivorCount)
{
	int i = 0;
	int j = 0;

	char cellStatus;

	char** arrayToReturn = malloc(height * sizeof(char));
	for (i = 0; i < height; ++i)
	{
		arrayToReturn[i] = malloc(width * sizeof(char));
	}

        return arrayToReturn;
}

The problem happens at the iterations of the Life Game that follows the first one. Microsoft Visual Studio complains on runtime at the free(referenceArray) in the do-while loop. Looking at the code makes me blind …

GDICommander 54 Posting Whiz in Training

Hello everyone!

I'm developping a chat application in a client/server context and every client has a shared directory. I want the server to know the directory structure of each shared directory of every client. I'm asking myself if there's an existing class in the Java API that can keep a directory structure on the server side, without containing the entire files.

I was thinkning of the File class, but it seems to work with a "real" file system on a "client side". I'm only interested for the structure of the shared directory (directory names and file names). So, if someone knows the existence of a class that can satisfy my needs, I would like to know. Otherwise, I will have to code a DirectoryTree class.

GDICommander 54 Posting Whiz in Training

Hi, everyone!

I'm having problems with the implantation of a free camera in a 3D world. For now, I'm using the A/D/W/S keys to make the camera go right, left, forward and backward. The problem is that I don't see the effects of the forward and backward movements. Even with high translation values, the effect (being visually close of far of the object) doesn't appear.

Can you help me with this problem? I tried to solve this for hours, but I am so blindfooled by my code so I can't see the cause of the problem. The transformation matrix looks good...

N.B: You may need some additional includes to make the code work.

#include <gl/glut.h>
#include <stdio.h>

//Facteurs de translation et de rotation.
GLdouble translationFactor = 25.0;
GLdouble rotationFactor = 0.5;

GLdouble objectTransformationMatrix[16];

GLint windowX = 500;
GLint windowY = 500;

void init(void) 
{
	glClearColor (0.0, 0.0, 0.0, 0.0);

	GLfloat materialSpecular[] = { 1.0, 1.0, 1.0, 1.0 };
	GLfloat materialShininess[] = { 50.0 };
	GLfloat lightPosition[] = { 5.0, 5.0, 0.0, 0.0 };
	GLfloat lightAmbiant[] = {0.0, 0.0, 1.0, 0.0 };		//Couleur d'ambiance bleue.

	//Préparation et activation de la source lumineuse.
	glShadeModel(GL_SMOOTH);

	glMaterialfv(GL_FRONT, GL_SPECULAR, materialSpecular);
	glMaterialfv(GL_FRONT, GL_SHININESS, materialShininess);

	glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
	glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbiant);

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);

	glDepthFunc( GL_LESS );
	glEnable(GL_DEPTH_TEST);

	//Préparation du système de coordonnées...
	glViewport(0, 0, 500, 500);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0.0, 500.0, 0.0, 500.0, -5000.0, 5000.0);

	//On met la perspective de vue ici.
	//gluPerspective(90, (GLdouble)windowX / (GLdouble)windowY, 1, 300);
	//gluPerspective(90, 1, 1, 300);

	//Matrice de transformation …
GDICommander 54 Posting Whiz in Training

Thank you for all your tips. Now I understand how to do rotations and translations properly.

GDICommander 54 Posting Whiz in Training

Thanks for the help! My main error was the use of the GL_MODELVIEW flag instead of the GL_MODELVIEW_MATRIX flag.

Now I would like to do rotations. I know how to use glRotate*(), but I don't want to provide a vector expressed by the origin. For example, I would like to put a vector at the center of a square and make this square rotate around this vector. Any ideas to guide me?

GDICommander 54 Posting Whiz in Training

Hello, everyone!

I'm starting to learn OpenGL and I have a problem with linear transformations.

The program is very basic: I want to draw 4 squares and make them move individually (by doing translations and rotation). I understand that I need to stock all the transformation in a matrix, so I can multiply it to the square information to get the good translation and rotation parameters. Unfortunately, the red square (the one missing) doesn't want to print on the screen. I have searched for a long time and I don't know what causes the problem: maybe a bad mode initialize or something else... Can someone help me? I have posted the code below.

N.B: You may need to add some includes for the code to work. My confguration of OpenGL only needs <gl/glut.h>

#include <gl/glut.h>
#include <stdio.h>

/**
	This program draws 4 squares and do moves on them (translations, rotations, ...)
*/

GLint windowX;
GLint windowY;

GLdouble redTransformationMatrix[16];

void reshape(GLint x, GLint y)
{
	windowX = x;
	windowY = y;

	glViewport(0,0,windowX,windowY);						// Reset The Current Viewport

	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
	glLoadIdentity();									// Reset The Projection Matrix

	glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
	glLoadIdentity();									// Reset The Modelview Matrix
}

/**
	\brief	Initializes transformations.
*/
void init()
{
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glGetDoublev(GL_MODELVIEW_MATRIX, redTransformationMatrix);		//Sets the red square transformation matrix with an identity matrix.
}

/**
	\brief Function that is called when a key is pressed on the keyboard.
	\param key		The ASCII value of the key.
	\param …
GDICommander 54 Posting Whiz in Training

There are options in the "Compiler" section in Code::blocks to make a faster executable. This will result in a longer compilation, but the program will be faster.

On Visual Studio, you can compile release and debug versions. Release versions are faster, because they don't contain debugging symbols (in the generated assembly code) required to debug an application in the debug version. The equivalent (debug and release) may exist in Code::Blocks.

And, as always, the speed of the execution mainly depends on what you do in the program. Are you using slow library functions? Slow and very greedy algorithms?