jfk20004
Messages postés39Date d'inscriptionmercredi 25 août 2004StatutMembreDernière intervention13 novembre 2004
-
11 nov. 2004 à 20:57
jfk20004
Messages postés39Date d'inscriptionmercredi 25 août 2004StatutMembreDernière intervention13 novembre 2004
-
13 nov. 2004 à 11:07
JFK,
J'utilise une api wizzard.exe de windows:
Là où il y a ecrit //code TODO:j'ai insere mon code:
prob:erreur:local definition of fonction not valid
Qu'est ce qu'une definition locale de fonction et comment resoudre le prob?
c'est un prog de raytrace:est ce que l'api wizzard est adpatée pour gerer le graphisme.Y a t il un autre moyen?
jfk20004
Messages postés39Date d'inscriptionmercredi 25 août 2004StatutMembreDernière intervention13 novembre 2004 11 nov. 2004 à 22:32
JFK
oui non , je croyais que MFC c'etait justement windows!
Peux tu m'eclairer 8-) .
Le prob est de faire tourner un prog de raytrace avec un l'environement le plus simple sous windows...
Je dois prendre quoi???
jfk20004
Messages postés39Date d'inscriptionmercredi 25 août 2004StatutMembreDernière intervention13 novembre 2004 12 nov. 2004 à 09:53
JFK
le prob est que les ex qui sont donnés je les comprends et je ne vais pas passer ma vie à les refaire d'autant que ça ne me sert
à rien :il y a toujours une phase de transition qui est difficile à
gerer c'est pour ça que je viens sur un forum pour aller au delà des exemples et autres tuto qui t'aident generalement pas!!!! :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :( :(
Vous n’avez pas trouvé la réponse que vous recherchez ?
jfk20004
Messages postés39Date d'inscriptionmercredi 25 août 2004StatutMembreDernière intervention13 novembre 2004 12 nov. 2004 à 13:16
JFKvoilà le code en question:
MERCI DE TON AIDE
:big) :big) :big) :big) :big)
il ya 4 unresolved external pour les 4 fonctions :
init();
hitsphere();
draw();
main();
BEGIN_MESSAGE_MAP(CRaywinApp, CWinApp)
//{{AFX_MSG_MAP(CRaywinApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRaywinApp construction
CRaywinApp::CRaywinApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
bool init(char* inputName, scene &myScene) {
int nbMat, nbSphere, nbLight;
int i;
ifstream sceneFile(inputName);
if (!sceneFile)
return false;
sceneFile >> myScene.sizex >> myScene.sizey;
sceneFile >> nbMat >> nbSphere >> nbLight ;
myScene.matTab.resize(nbMat);
myScene.sphTab.resize(nbSphere);
myScene.lgtTab.resize(nbLight);
for (i=0; i<nbMat; ++i)
sceneFile >> myScene.matTab[i];
for (i=0; i<nbSphere; ++i)
sceneFile >> myScene.sphTab[i];
for (i=0; i<nbLight; ++i)
sceneFile >> myScene.lgtTab[i];
return true;
}
bool hitSphere(const ray &r, const sphere& s, float &t) {
// intersection rayon/sphere
vecteur dist = s.pos - r.start;
float B = r.dir * dist;
float D = B*B - dist * dist + s.size * s.size;
if (D < 0.0f) return false;
float t0 = B - sqrtf(D);
float t1 = B + sqrtf(D);
bool retvalue = false;
if ((t0 > 0.1f ) && (t0 < t)) {
t = t0;
retvalue = true;
}
if ((t1 > 0.1f ) && (t1 < t)) {
t = t1;
retvalue = true;
}
return retvalue;
}
bool draw(char* outputName, scene &myScene) {
ofstream imageFile(outputName,ios_base::binary);
if (!imageFile)
return false;
// Ajout du header TGA
imageFile.put(0).put(0);
imageFile.put(2); /* RGB non compresse */
imageFile.put(0).put(0);
imageFile.put(0).put(0);
imageFile.put(0);
imageFile.put(0).put(0); /* origine X */
imageFile.put(0).put(0); /* origine Y */
imageFile.put((myScene.sizex & 0x00FF)).put((myScene.sizex & 0xFF00) / 256);
imageFile.put((myScene.sizey & 0x00FF)).put((myScene.sizey & 0xFF00) / 256);
imageFile.put(24); /* 24 bit bitmap */
imageFile.put(0);
// fin du header TGA
// balayage
for (int y = 0; y < myScene.sizey; ++y) {
for (int x = 0 ; x < myScene.sizex; ++x) { float red 0, green 0, blue = 0;
float coef = 1.0f;
int level = 0;
// lancer de rayon
ray viewRay = { {float(x), float(y), -10000.0f}, { 0.0f, 0.0f, 1.0f}};
do {
// recherche de l'intersection la plus proche
float t = 20000.0f;
int currentSphere=-1;
for (unsigned int i = 0; i < myScene.sphTab.size() ; ++i) {
if (hitSphere(viewRay, myScene.sphTab[i], t)) {
currentSphere = i;
}
}
if (currentSphere == -1)
break;
point newStart = viewRay.start + t * viewRay.dir;
// la normale au point d'intersection
vecteur n = newStart - myScene.sphTab[currentSphere].pos;
float temp = n * n;
if (temp == 0.0f)
break;
temp = 1.0f / sqrtf(temp);
n = temp * n;
material currentMat = myScene.matTab[myScene.sphTab[currentSphere].material];
// calcul de la valeur d'éclairement au point
for (unsigned int j = 0; j < myScene.lgtTab.size() ; ++j) {
light current = myScene.lgtTab[j];
vecteur dist = current.pos - newStart;
if ( n * dist <= 0.0f )
continue;
float t = sqrtf(dist * dist);
if ( t <= 0.0f )
continue;
ray lightRay;
lightRay.start = newStart;
lightRay.dir = (1/t) * dist;
// calcul des ombres
bool inShadow = false;
for (unsigned int i = 0; i < myScene.sphTab.size() ; ++i) {
if (hitSphere(lightRay, myScene.sphTab[i], t)) {
inShadow = true;
break;
}
}
if (!inShadow) {
// lambert
float lambert = (lightRay.dir * n) * coef;
red += lambert * current.red * currentMat.red;
green += lambert * current.green * currentMat.green;
blue += lambert * current.blue * currentMat.blue;
}
}
int main(int argc, char* argv[]) {
if (argc < 3)
return -1;
scene myScene;
if (!init(argv[1], myScene))
return -1;
if (!draw(argv[2], myScene))
return -1;
return 0;
}
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CRaywinApp object
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CRaywinDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CRaywinView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
ymca2003
Messages postés2070Date d'inscriptionmardi 22 avril 2003StatutMembreDernière intervention 3 juillet 20067 12 nov. 2004 à 14:01
Pourquoi t'as mis tous le code (main y compris) dans le TODO du constructeur ????
Ce qu'il faut c'est créer un projet VIDE, créer un fichier source et y mettre le code dedans et non pas créer le squelette d'une appli MFC et de coller le code au premier TODO trouvé.
ymca2003
Messages postés2070Date d'inscriptionmardi 22 avril 2003StatutMembreDernière intervention 3 juillet 20067 12 nov. 2004 à 15:04
Petite précision :
il faut créer un projet Win32 console (main).
si tu fait un projet Win32 normal sans console, le point d'entrée sera WinMain au lieu de main.
ymca2003
Messages postés2070Date d'inscriptionmardi 22 avril 2003StatutMembreDernière intervention 3 juillet 20067 12 nov. 2004 à 16:41
j'ai dit console car dans le code que tu ajoute j'ai vu un 'main' et pas 'WinMain'.
dans un prog console, tu peut très bien créer des fenêtres mais si tu n'as pas besoin de la console , il faut faire directement une apli Win32 standard (ça dépend de ce que tu veux faire).
en ce qui concerne les todo en MFC, il y a en a un peu partout mais il faut savoir quand même ce que lon fait.
jfk20004
Messages postés39Date d'inscriptionmercredi 25 août 2004StatutMembreDernière intervention13 novembre 2004 13 nov. 2004 à 11:07
JFK
brunew m'a donné ses tutos qui fonctionne avec win32 app
:est ce que tu penses que mon code peut fonctionner avec.
à l'originr ce bout de code est livré "brut" où avec une version gtk.
J'essaie de l'implementer sous windows.à termes,je veux implementer des bout de code de povra sous windows.