|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Jun 2003
Messaggi: 1041
|
[C++] C++ e OpenGL
Salve ragazzi...
Ho un grande problema. Ho un codice in C++ e vorrei fare la versione in OpenGL. Qualcuno mi può dare una mano per favore con OpenGL?
__________________
Ho trattato con: ))Lexandrus((, abc3d, al2, almar, antonio panaro, bimbo-gio, bruno sorbelli, CLURACAN, cervoale, cristoforobiagrtti, danisevoo, dayz, DrUg@tO, eric654, Feroz, firmus, gigio75, grezzo, icest0rm, leleweb, linears4, madelui, Maverick82^, morpheus3g, mrwinch, obi_wan, PERPAX, piziul, Razorx92, rigolo, robby2002, sagomaccio, sciach, semenzara, slash84, takers, tati29268, twil83, verbania, volcanik & altri... Ultima modifica di irK : 06-12-2007 alle 18:43. |
|
|
|
|
|
#2 | |
|
Senior Member
Iscritto dal: Mar 2007
Messaggi: 1792
|
Quote:
|
|
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Jun 2003
Messaggi: 1041
|
Allora io ho un codice in C++ che è un cavallo che si muove su una scacchiera.
Devo dire che non sono bravo a programmare in C++ ma lo stesso ho scritto come deve muoversi il cavallo. Il mio problema è come implementare l'OpenGL.
__________________
Ho trattato con: ))Lexandrus((, abc3d, al2, almar, antonio panaro, bimbo-gio, bruno sorbelli, CLURACAN, cervoale, cristoforobiagrtti, danisevoo, dayz, DrUg@tO, eric654, Feroz, firmus, gigio75, grezzo, icest0rm, leleweb, linears4, madelui, Maverick82^, morpheus3g, mrwinch, obi_wan, PERPAX, piziul, Razorx92, rigolo, robby2002, sagomaccio, sciach, semenzara, slash84, takers, tati29268, twil83, verbania, volcanik & altri... |
|
|
|
|
|
#4 | |
|
Senior Member
Iscritto dal: Aug 2001
Città: San Francisco, CA, USA
Messaggi: 13827
|
Quote:
Credo che dovresti almeno postare pezzi di codice che non ti sono chiari. (tutto in caso non ti fosse chiaro nulla Ciao
__________________
GPU Compiler Engineer |
|
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Con quale libreria grafica è realizzato questo codice ?
|
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Nov 2005
Messaggi: 1545
|
Usa GLUT, cerca un tutorial per fare il setup della finestra e le matrici fondamentali (World, View, Projection).
Prepara la mesh per il tuo cavallo e renderizzala settando le matrici. |
|
|
|
|
|
#7 |
|
Senior Member
Iscritto dal: Jun 2003
Messaggi: 1041
|
Sto usando Glut. Tra copia incolla, e vari tutorial online questo è il codice:
Codice:
#include <iostream>
#include <iomanip>
using namespace std;
const int size = 8;
class position {
public:
position(int x=0, int y=0) {row = x; col = y;}
int getrow() const {return row;}
int getcol() const {return col;}
int getlast_mov() const {return last_mov;}
void setlast_mov(int l_mov){last_mov=l_mov;}
private:
int row;
int col;
int last_mov;
};
template< class T >
class Stack {
public:
Stack( int SIZE = size*size );
~Stack() { delete [] stackPtr; }
bool push( const T& );
bool pop( T& );
int getsize() const {return SIZE;}
bool isEmpty() const { return top == -1; }
bool isFull() const { return top == SIZE - 1; }
private:
int SIZE;
int top;
T *stackPtr;
};
template< class T >
Stack< T >::Stack( int s )
{
SIZE = s > 0 ? s : size*size;
top = -1;
stackPtr = new T[ SIZE ];
}
template< class T >
bool Stack< T >::push( const T &pushValue )
{
if ( !isFull() ) {
stackPtr[ ++top ] = pushValue;
return true;
}
return false;
}
template< class T >
bool Stack< T >::pop( T &popValue )
{
if ( !isEmpty() ) {
popValue = stackPtr[ top-- ];
return true;
}
return false;
}
void print_board(int[][size]);
bool can_move(int,int,int,int,int[][size]);
void move_b(int,int,int,int,int[][size],int);
position update_stack(int x_pos, int y_pos, int last_mov);
void main(){
int x_pos,y_pos;
int board[size][size]={0};
int move[8][2]={1,2, 2,1, 2,-1, 1,-2, -1,-2, -2,-1, -2,1, -1,2};
do
{
cout<<"\nEnter an initial position: ";
cin>>x_pos>>y_pos;
} while ((x_pos<0)||(x_pos>=size)||(y_pos<0)||(y_pos>=size));
int last_mov=0;
position knights(x_pos,y_pos);
knights.setlast_mov(last_mov);
move_b(x_pos,y_pos,0,0,board,0);
Stack <position> knight_stack(size*size);
knight_stack.push(knights);
bool exit_loop=false;
while ((knight_stack.isEmpty()==false) && (knight_stack.isFull()==false))
{
exit_loop=false;
for (;exit_loop==false;last_mov++)
{
if (last_mov<8)
{
if (can_move(x_pos,y_pos,move[last_mov][0],move[last_mov][1],board))
{
move_b(x_pos,y_pos,move[last_mov][0],move[last_mov][1],board,0);
x_pos=x_pos+move[last_mov][0];
y_pos=y_pos+move[last_mov][1];
knight_stack.push(update_stack(x_pos,y_pos,last_mov));
last_mov=-1;
exit_loop=true;
}
}
else
{
knight_stack.pop(knights);
last_mov=knights.getlast_mov();
x_pos=knights.getrow();
y_pos=knights.getcol();
move_b(x_pos,y_pos,move[last_mov][0],move[last_mov][1],board,1);
x_pos=x_pos-move[last_mov][0];
y_pos=y_pos-move[last_mov][1];
last_mov++;
exit_loop=true;
}
}
}
if (knight_stack.isEmpty()==true)
cout<<"There are no solutions for the proposed problem... \n";
if (knight_stack.isFull()==true)
print_board(board);
}
position update_stack(int x_pos, int y_pos, int last_mov)
{
position knights(x_pos,y_pos);
knights.setlast_mov(last_mov);
return (knights);
}
void print_board(int board[][size])
{
cout<<"Here is one possible solution for the knights tour:\n";
for (int i=0;i!=size;i++)
{
for (int k=0;k!=size;k++)
{
cout<<setw(3)<<board[i][k];
}
cout<<"\n";
}
}
bool can_move(int x,int y,int delta_x,int delta_y,int board[][size])
{
if (((x+delta_x)>=size)||((x+delta_x)<0)||((y+delta_y)<0)||((y+delta_y)>=size))
return(false);
if (board[x+delta_x][y+delta_y]!=0)
return(false);
return(true);
}
void move_b(int x,int y,int delta_x,int delta_y,int board[][size],int erase){
if (erase==1)
{
board[x-delta_x][y-delta_y]=board[x][y]-1;
board[x][y]=0;
}
else
{
board[x+delta_x][y+delta_y]=board[x][y]+1;
}
position knights(x+delta_x,y+delta_y);
}
__________________
Ho trattato con: ))Lexandrus((, abc3d, al2, almar, antonio panaro, bimbo-gio, bruno sorbelli, CLURACAN, cervoale, cristoforobiagrtti, danisevoo, dayz, DrUg@tO, eric654, Feroz, firmus, gigio75, grezzo, icest0rm, leleweb, linears4, madelui, Maverick82^, morpheus3g, mrwinch, obi_wan, PERPAX, piziul, Razorx92, rigolo, robby2002, sagomaccio, sciach, semenzara, slash84, takers, tati29268, twil83, verbania, volcanik & altri... Ultima modifica di irK : 06-12-2007 alle 18:39. |
|
|
|
|
|
#8 |
|
Senior Member
Iscritto dal: Jun 2003
Messaggi: 1041
|
Postato il codice per due volte...
__________________
Ho trattato con: ))Lexandrus((, abc3d, al2, almar, antonio panaro, bimbo-gio, bruno sorbelli, CLURACAN, cervoale, cristoforobiagrtti, danisevoo, dayz, DrUg@tO, eric654, Feroz, firmus, gigio75, grezzo, icest0rm, leleweb, linears4, madelui, Maverick82^, morpheus3g, mrwinch, obi_wan, PERPAX, piziul, Razorx92, rigolo, robby2002, sagomaccio, sciach, semenzara, slash84, takers, tati29268, twil83, verbania, volcanik & altri... Ultima modifica di irK : 06-12-2007 alle 16:30. |
|
|
|
|
|
#9 |
|
Bannato
Iscritto dal: Feb 2005
Città: Roma
Messaggi: 7029
|
come mai hai realizzato una tua classe Stack? non va bene la classe stack delle STL?
|
|
|
|
|
|
#10 | |
|
Senior Member
Iscritto dal: Jun 2003
Messaggi: 1041
|
Quote:
ciao grazie
__________________
Ho trattato con: ))Lexandrus((, abc3d, al2, almar, antonio panaro, bimbo-gio, bruno sorbelli, CLURACAN, cervoale, cristoforobiagrtti, danisevoo, dayz, DrUg@tO, eric654, Feroz, firmus, gigio75, grezzo, icest0rm, leleweb, linears4, madelui, Maverick82^, morpheus3g, mrwinch, obi_wan, PERPAX, piziul, Razorx92, rigolo, robby2002, sagomaccio, sciach, semenzara, slash84, takers, tati29268, twil83, verbania, volcanik & altri... |
|
|
|
|
|
|
#11 |
|
Senior Member
Iscritto dal: Jun 2003
Messaggi: 1041
|
nessuno che mi può dare una mano?
__________________
Ho trattato con: ))Lexandrus((, abc3d, al2, almar, antonio panaro, bimbo-gio, bruno sorbelli, CLURACAN, cervoale, cristoforobiagrtti, danisevoo, dayz, DrUg@tO, eric654, Feroz, firmus, gigio75, grezzo, icest0rm, leleweb, linears4, madelui, Maverick82^, morpheus3g, mrwinch, obi_wan, PERPAX, piziul, Razorx92, rigolo, robby2002, sagomaccio, sciach, semenzara, slash84, takers, tati29268, twil83, verbania, volcanik & altri... |
|
|
|
|
|
#12 |
|
Senior Member
Iscritto dal: Nov 2000
Città: MILANO
Messaggi: 2662
|
scusa mi sembra che tu chieda un po' troppo. è come se chiedessi come si programma in c++. tu devi implementare tutta la grafica. che ti si può dire? studia opengl! non sono mica 2 comandi. cerca i tutorial di nehe. fra qualche settimana, se studi in fretta forse riesci a farlo.
|
|
|
|
|
|
#13 |
|
Senior Member
Iscritto dal: Jun 2003
Messaggi: 1041
|
Scusatemi ragazzi, lo so che forse ho chiesto troppo... ma se gentilmente qualcuno poteva aiutarmi mi faceva un grandissimo favore visto che non so quasi niente di C++. Lo so che devo leggere un pò di tutorial ecc. Però mi hanno detto che non dovevo mettere + di 3 giorni per fare questo progetto e sinceramente ci sto mettendo quasi 3 settimane
__________________
Ho trattato con: ))Lexandrus((, abc3d, al2, almar, antonio panaro, bimbo-gio, bruno sorbelli, CLURACAN, cervoale, cristoforobiagrtti, danisevoo, dayz, DrUg@tO, eric654, Feroz, firmus, gigio75, grezzo, icest0rm, leleweb, linears4, madelui, Maverick82^, morpheus3g, mrwinch, obi_wan, PERPAX, piziul, Razorx92, rigolo, robby2002, sagomaccio, sciach, semenzara, slash84, takers, tati29268, twil83, verbania, volcanik & altri... |
|
|
|
|
|
#14 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
A me sembra strano che non sapendo niente di C++ tu debba usare OpenGL...
|
|
|
|
|
|
#15 | |
|
Senior Member
Iscritto dal: Mar 2007
Messaggi: 1792
|
Quote:
|
|
|
|
|
|
|
#16 | |
|
Senior Member
Iscritto dal: Jun 2003
Messaggi: 1041
|
Quote:
__________________
Ho trattato con: ))Lexandrus((, abc3d, al2, almar, antonio panaro, bimbo-gio, bruno sorbelli, CLURACAN, cervoale, cristoforobiagrtti, danisevoo, dayz, DrUg@tO, eric654, Feroz, firmus, gigio75, grezzo, icest0rm, leleweb, linears4, madelui, Maverick82^, morpheus3g, mrwinch, obi_wan, PERPAX, piziul, Razorx92, rigolo, robby2002, sagomaccio, sciach, semenzara, slash84, takers, tati29268, twil83, verbania, volcanik & altri... Ultima modifica di irK : 06-12-2007 alle 18:45. |
|
|
|
|
|
|
#17 | |
|
Senior Member
Iscritto dal: Mar 2007
Messaggi: 1792
|
Quote:
|
|
|
|
|
|
|
#18 |
|
Bannato
Iscritto dal: Feb 2005
Città: Roma
Messaggi: 7029
|
be' oddio, pure il C++ potrebbe metterci del suo: se uno non ha padronanza ed è sfigato che gli capita un bel bug potrebbe dover aggiungere un giorno di ritardo (da 3 giorni a 4 giorni). e meno male che, da quanto ho capito, il programma non necessita di concorrenza tra thread.
|
|
|
|
|
|
#19 | |
|
Senior Member
Iscritto dal: Mar 2007
Messaggi: 1792
|
Quote:
Ultima modifica di variabilepippo : 05-12-2007 alle 16:04. |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 03:26.




















