|
Mostrar Temas
|
Páginas: [1]
|
1
|
Programación / Programación General / Simulaciones en Matlab
|
en: 4 Agosto 2013, 07:15 am
|
Hola, estoy haciendo un simulador de la Ley de Stokes, pero no se como hacer que cuando llegue a determinada altura sepa que llego al fluido y ahí haga las ecuaciones de fluido intente con un if, pero esto me daña el programa :S ¿Alguna sugerencia? Gracias por la atención. function varargout = Fluido(varargin) % FLUIDO MATLAB code for Fluido.fig % FLUIDO, by itself, creates a new FLUIDO or raises the existing % singleton*. % % H = FLUIDO returns the handle to a new FLUIDO or the handle to % the existing singleton*. % % FLUIDO('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in FLUIDO.M with the given input arguments. % % FLUIDO('Property','Value',...) creates a new FLUIDO or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Fluido_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Fluido_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools me nu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Fluido
% Last Modified by GUIDE v2.5 31-Jul-2013 16:01:53
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Fluido_OpeningFcn, ... 'gui_OutputFcn', @Fluido_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end
if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT
% --- Executes just before Fluido is made visible. function Fluido_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to Fluido (see VARARGIN)
% Choose default command line output for Fluido handles.output = hObject;
% Update handles structure guidata(hObject, handles);
% UIWAIT makes Fluido wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = Fluido_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure varargout{1} = handles.output;
% --- Executes on selection change in fluido. function fluido_Callback(hObject, eventdata, handles) % hObject handle to fluido (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns fluido contents as cell array % contents{get(hObject,'Value')} returns selected item from fluido
val = get(hObject, 'Value'); global de; global vis;
switch val case 2 % El usuario seleccionó la primera opción AGUA de=1000; vis=0.001; case 3 % El usuario seleccionó la segunda opción ACEITE de=920; vis=0.03; case 4 % El usuario seleccionó la 3 opción GLICERINA de=1200; vis=1.5; end % --- Executes during object creation, after setting all properties. function fluido_CreateFcn(hObject, eventdata, handles) % hObject handle to fluido (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
function radio_Callback(hObject, eventdata, handles) global r; % hObject handle to radio (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of radio as text % str2double(get(hObject,'String')) returns contents of radio as a double r=(str2double(get(hObject,'String'))); % --- Executes during object creation, after setting all properties. function radio_CreateFcn(hObject, eventdata, handles) % hObject handle to radio (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
% --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
global r ; r=str2double(get(handles.radio,'String')); global de ; global vis;
yo=15; vyo=0; g=-9.8;
tcaidali=(yo*2/g)^(1/2);
t=0:1/50:5:(((6)^2/7)+20);
%tMax = 0; %deltaT = 0.50; %t = tcaidali;
%%Ecuaciones caida libre x=0*t; vy = vyo + g*t; y=yo+vyo*t+(1/2)*g*t.^2;
%%%Material--->Cobre densidadcobre=8500; %Entra en el fluido a una altura de cinco metros if yo==5 %%Ecuaciones Fluidos
m=(densidadcobre*(4/3)*pi*(r.^2)); b=(6*pi*r*vis); E=(de*(4/3)*pi*(r.^3)*g);
vl=((2*r.^2*g*(densidadcobre-de))/(9*vis)); v=vl*(1-exp((-b*t/m))); x=vl*(t-(m/b)*(1-exp((-b/m)*t)));
for i=1:length(t) % para animar las grafica pause(1/50) % tiempo para que se detenga tiempo igual al de arriba
%subplot(2,2,1)% Matriz 2x2 posición1 plot(handles.axes1,t(i),vy(i)) xlabel(handles.axes1,'tiempo t(s)') ylabel(handles.axes1,'Velocidad en Y - Vy (m/s)') axis(handles.axes1,[min(t) max(t) min(vy) max(vy)]) hold (handles.axes1,'on') yo=yo+1; plot(handles.axes2,x(i),y(i), 'o r') xlabel(handles.axes2,'Posición x(m)') ylabel(handles.axes2,'Posición y(m)') axis(handles.axes1,axis,[-2 2 min(y) max(y)]) hold (handles.axes2,'on')
plot(handles.axes1,t(i),v(i)) xlabel(handles.axes1,'tiempo t(s)') ylabel(handles.axes1,'Velocidad en Vl - Vl (m/s)') axis(handles.axes1,axis,[min(t) max(t) min(v) max(v)]) hold (handles.axes1,'on')
end end %tMax = 3; %deltaT = 0.01; %t = 0;
%Bola caida libre %while tiempoTranscurrido < tMax %caídalibre %x =0*deltaT; % y = yo+Vyo*deltaT+(1/2)*g*deltaT.^2;
% vy = vy + g*deltaT;
%plot(handles.axes2, t, vy); % xlabel(handles.axes2,'tiempo en t(s).') % ylabel(handles.axes2,'Velocidad en Vy(m/s)') % axis([0 tMax -5 5]) % hold (handles.axes2,'on')
%end
%v=v2*(1-exp((-b/m)*t)); %x=vt*(t-(m/b)*(1-exp((-b/m)*t))); %vl=(2*r^2*g*(de-df))*9*vis;
%b=(6*Pi*r*vis); %E=(df*(4/3)*Pi*(r^3)*g); %m=(de*(4/3)*Pi*(r^2));
%plotear v vs tiempo
% --- Executes during object creation, after setting all properties. %function axes1_CreateFcn(hObject, eventdata, handles) % hObject handle to axes1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
|
|
|
2
|
Programación / Programación C/C++ / ¡Ayuda c++ y Open gl :) !
|
en: 20 Enero 2013, 04:20 am
|
¡Hola! Tengo una pequeña duda con los viewports, es decir ¿Cómo hago para que cuando agrande la pantalla no se me distorsione mi figura, es decir que guarde proporción con mi ventana? Se que se puede hacer cambiando el Ortho o los Viewports. y otra duda ¿Cómo hago para manejar dos viewports ? Es decir tengo mi figura en un pedazo de la pantalla y haciendole selección con el mouse , me muestra como un zoom de este pedazo de mi figura. Agradezco si pudieran explicarme los Viewports Muchas Gracias //Dejo un código que permite mantener proporción con la ventana, pido rectificación #include <windows.h> //Para poder usar ventanas con windows. #include <GL/glut.h> #include <stdio.h> #include <iostream> using namespace std; //variables float x,y,anchoview = 512,altoview = 512,cx=0,cy=0; void init(void){ //Esto inicializa los colores glClearColor(0.0,0.0,0.0,0.0); glMatrixMode(GL_PROJECTION); glOrtho(-250.0,250.0,-250.0,250.0,-1500,1500); } void display (void){ //inicializamos parametros y creamos figuras glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Mostrar la pantalla con el color glColor3f (0.0, 1.0, 0.0);//Color de nuestros objetos glutWireCube(490); glutSwapBuffers(); } //void ControlRaton(int button,int state,int x,int y) { //if void nuevapan (int nuevoancho, int nuevoalto){ if(nuevoancho>(nuevoalto*2)){ glViewport(((nuevoancho/2)-(nuevoancho+nuevoalto)/32),((nuevoalto/2)-(nuevoancho+nuevoalto)/32),(nuevoancho+nuevoalto)/16,(nuevoancho+nuevoalto)/16); } else { glViewport(((nuevoancho/2)-(nuevoancho+nuevoalto)/6),((nuevoalto/2)-(nuevoancho+nuevoalto)/6),(nuevoancho+nuevoalto)/3,(nuevoancho+nuevoalto)/3); //primero centramos el viewport al divir toda la dimension de la pantalla (x o y) en 2, luego le restamos un valor para correrlo hacia - x y bajarlo a - y estos valores son el nuevo viewport completo, pero divifido en algo para no sobre pasarlo } } int main (int argc, char** argv){ glutInit(&argc, argv);//inicializa GLUT, encargada de genrar la pantalla glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); //da los parámetros que glut usara para generar su pantalla glutInitWindowSize(512, 512);//Tamaño de la pantalla a crear glutInitWindowPosition(20, 20);//Posicion inciial de la pantalla glutCreateWindow("Cuadrícula");//Generacióny nombre de la pantalla glutDisplayFunc(display);//Define el contenido de nuestra pantalla, o sea la imagen a crear con la funcion display //glutMouseFunc(ControlRaton); glutReshapeFunc(nuevapan); init(); glutMainLoop(); //bucle infinito para el programa, es para esperar por eventos del telcado o el mause (si hay presion y luego se ejecuta), para usar eventos, primero debemos registrarlos }
|
|
|
3
|
Programación / Programación C/C++ / Ayuda con este programa?
|
en: 27 Septiembre 2012, 05:28 am
|
Hola! Es un "brazo" y necesito que se mueva 180 grados por el teclado , son dos piezas diferentes pero no se como hacer lo del teclado y la transformación no me salee Una ayudita me caería bien Gracias!!! CÓDIGO: #include<GL/glut.h> #include <math.h> //Este es el tuyo float y; float q0[2]={-30,50}; float q1[2]={-30,230}; float q2[2]={30,230}; float q3[2]={30,50}; float b0[2] ,b1[2] ,b2[2],b3[2], t[2]; float save0[2],save1[2],save2[2],save3[2]; float ang; //****************************************** TRASLACIONES************************************************** void operaciones (float p[2], float p1[2]) //Parámetros de Entrada { float R[3][3]={1,0,0, 0,1,0, 0,0,1}; p1[0]= R[0][0]*p[0]+ R[0][1]*p[1] + R[0][2]*1; p1[1]= R[1][0]*p[0]+ R [1][1]*p[1] + R[1][2]*1; return; } void escalado2D (float p[2], float p1[2], float s[2]) //Parámetros de Entrada y parámetros de traslación x0 y y0 { float S[3][3]={0,0,0, 0,1,0, 0,0,1}; S[0][0]=s[0]; //s[0] es sx S[1][1]=s[1]; //s[1] es sy p1[0]= S[0][0]*p[0]+ S p1[1]= S[1][0]*p[0]+ S [1][1]*p[1] + S[1][2]*1; //Matriz de traslación. return; } void traslacion2D (float p[2], float p1[2], float t[2]) //Parámetros de Entrada y parámetros de traslación x0 y y0 { float T[3][3]={0,0,0, 0,1,0, 0,0,1}; T[0][1]=t[0]; //t[0] es sx T[1][0]=t[1]; //t[1] es sy p1[0]= T[0][0]*p[0]+ T p1[1]= T[1][0]*p[0]+ T [1][1]*p[1] + T[1][2]*1; //Matriz de traslación. return; } void rotacion2D (float p[2], float p1[2], float ang) //Parámetros de Entrada y parámetros de traslación x0 y y0 { float R[3][3]={0,0,0, 0,1,0, 0,0,1}; float theta; theta=ang*3.1415/180; R[0][0]=cos(theta); R[0][1]=-sin(theta); R[1][0]=sin(theta); R[1][1]=cos(theta); p1[0]= R[0][0]*p[0]+ R p1[1]= R[1][0]*p[0]+ R [1][1]*p[1] + R[1][2]*1; //Matriz de Rotación. return; } //******************************************FIN TRASLACIONES*************************************************** void ejesguia() { y=500-y; glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0,1.0,0.0); glBegin(GL_LINES); glPointSize(0.8); glVertex2i(0,10); glVertex2i(0,490); glVertex2i(-240,10); glVertex2i(240,10); glEnd(); // Base glColor3f(1.0,1.0,0.0); glBegin(GL_POLYGON); glVertex2f(-150,10); glVertex2f(-150,80); glVertex2f(150,80); glVertex2f(150,10); glEnd(); // PIVOTE1 (No funciona) glColor3f(1.0,0.10,0.10); glBegin(GL_POINT); glPointSize(30.0); glVertex2f(0,80); glEnd (); glFlush(); } void Brazo1() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,0.0,1.0); glBegin(GL_POLYGON); glVertex2f(-30,50); glVertex2f(-30,230); glVertex2f(30,230); glVertex2f(30,50); glEnd(); glFlush(); } void Brazo2() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0,0.0,1.0); glVertex2f(-30,210); glVertex2f(-30,430); glVertex2f(30,430); glVertex2f(30,210); glEnd(); glFlush(); } void moveBrazo1 () { //traslada origen t[0]=0.0; t[1]=0.0; traslacion2D(q0,b0,t); traslacion2D(q1,b1,t); traslacion2D(q2,b2,t); traslacion2D(q3,b3,t); save0[0]=q0[0]; save1[0]=q1[0]; save2[0]=q2[0]; save3[0]=q3[0]; save0[1]=q0[1]; save1[1]=q1[1]; save2[1]=q2[1]; save3[1]=q3[1]; // rota cada 10 grados ang= 10; rotacion2D(q0,b0,ang); rotacion2D(q1,b1,ang); rotacion2D(q2,b2,ang); rotacion2D(q3,b3,ang); //Posicion Inciial } void teclasEspeciales(int key, int x, int y) { /*switch (key) { case GLUT_KEY_LEFT: if (// lame la funcion que me rota o hace ); break; case GLUT_KEY_RIGHT: if (); break; case GLUT_KEY_UP: if () ; break; case GLUT_KEY_DOWN: if (); break; } */ } void init () { glClearColor (0.0, 0.0, 0.0, 0.0); glColor3f(1.0, 1.0, 1.0); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho(-250, 250, 0, 500, -1.0, 1.0); } int main(int argc, char** argv) { glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(0,0); glutCreateWindow("Brazo"); glutDisplayFunc(ejesguia); init(); glutMainLoop(); }
|
|
|
4
|
Programación / Programación C/C++ / Transformaciones geometricas en open gl
|
en: 16 Septiembre 2012, 06:02 am
|
Hola! Es que necesito de su ayuda, tengo un código que me permite girar la figura con un menú, pero lo que pasa es que tiene que Rotar, escalar y Trasladar; Como hago para que rote pero en su mismo lugar, por que esta me aparece en la esquina de la pantalla y en la escala se me deforma totalmente Agradezco su ayuda CÓDIGO: #include <iostream> #include <GL/glut.h> #include <stdlib.h> using namespace std; int click[2] = {0,0}; void menuaplicacion(int); void operaciones (float p[2], float p1[2]) //Parámetros de Entrada { float R[3][3]={1,0,0, 0,1,0, 0,0,1}; p1[0]= R[0][0]*p[0]+ R[0][1]*p[1] + R[0][2]*1; p1[1]= R[1][0]*p[0]+ R [1][1]*p[1] + R[1][2]*1; return; } //Para rotar float q0[2]={click float q1[2]={click float q2[2]={click float q3[2]={click float q4[2]={click float b0[2] ,b1[2] ,b2[2],b3[2],b4[2],b5[2], r[2]; float ang; void rotacion2D (float p[2], float p1[2], float ang) { float R[3][3]={0,0,0, 0,1,0, 0,0,1}; float theta; theta=ang*3.1415/180; R[0][0]=cos(theta); R[0][1]=-sin(theta); R[1][0]=sin(theta); R[1][1]=cos(theta); p1[0]= R[0][0]*p[0]+ R p1[1]= R[1][0]*p[0]+ R [1][1]*p[1] + R[1][2]*1; return; } // Para Traslacion /*void traslacion2D (float p[2], float p1[2], float s[2]) { float T[3][3]={0,0,0, 0,1,0, 0,0,1}; T[0][1]=t[0]; //s[0] es tx T[1][0]=t[1]; //s[1] es ty p1[0]= T[0][0]*p[0]+ T p1[1]= T[1][0]*p[0]+ T [1][1]*p[1] + T[1][2]*1; float b0[2] ,b1[2] ,b2[2],b3[2],b4[2],b5[2], t[2]; return; } */ //Para Escalado float s[2]; void escalado2D (float p[2], float p1[2], float s[2]) { float S[3][3]={0,0,0, 0,1,0, 0,0,1}; S[0][0]=s[0]; //s[0] es sx S[1][1]=s[1]; //s[1] es sy p1[0]= S[0][0]*p[0]+ S p1[1]= S[1][0]*p[0]+ S [1][1]*p[1] + S[1][2]*1; return; } //********************************************EMPIEZA FORMALMENTE EL TRABAJO **************************************************************** void init(void) { glClearColor(0.0,0.0,0.0,0.0); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0,500.0,0.0,500.0); int submenu1,submenu2,submenu3,submenu4; submenu1=glutCreateMenu(menuaplicacion); glutAddMenuEntry("45", 1); glutAddMenuEntry("-45", 2); submenu2=glutCreateMenu(menuaplicacion); glutAddMenuEntry("Doble", 3); glutAddMenuEntry("Mitad", 4); submenu3=glutCreateMenu(menuaplicacion); glutAddMenuEntry("Al Origen", 5); glutAddMenuEntry("Posicion Inicial", 6); submenu4=glutCreateMenu(menuaplicacion); glutAddMenuEntry("Retornar Posicion Inicial", 7); glutAddMenuEntry("Desde 0", 8); glutCreateMenu(menuaplicacion); glutAddSubMenu("Rotar",submenu1); glutAddSubMenu("Escalar",submenu2); glutAddSubMenu("Trasladar",submenu3); glutAddSubMenu("Reiniciar",submenu4); glutAttachMenu(GLUT_RIGHT_BUTTON); glutAttachMenu(GLUT_MIDDLE_BUTTON); } void ejesguia() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0,1.0,0.0); glBegin(GL_LINES); glPointSize(0.8); glVertex2i(30,30); glVertex2i(30,470); glVertex2i(30,30); glVertex2i(470,30); glEnd(); glFlush(); } void mouse(int button, int state, int x=0, int y=0) { if (state==0) return; y =500-y; if (state == 1 && click[0]==0 && click[1]==0) { click click [1]=y; } cout<<"Coordenada en X guardada"<<click[0]<<endl; cout<<"Coordenada en Y guardada"<<click[1]<<endl; glColor3f (0.73, 0.25, 0.83); glBegin (GL_POLYGON); glVertex2f(click glVertex2f(click glVertex2f(click glVertex2f(click glVertex2f(click glEnd (); glFlush(); } void menuaplicacion(int value) { if(value==1) { // Rota mas 45 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); ejesguia(); glutMouseFunc(mouse); ang= 45; rotacion2D(q0,b0,ang); rotacion2D(q1,b1,ang); rotacion2D(q2,b2,ang); rotacion2D(q3,b3,ang); rotacion2D(q4,b4,ang); glColor3f(0.50,0.21,0.42); glBegin(GL_POLYGON); glVertex2fv(b0); glVertex2fv(b1); glVertex2fv(b2); glVertex2fv(b3); glEnd(); glFlush(); } if(value==2) { // Rota -45 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); ejesguia(); glutMouseFunc(mouse); ang= -45; rotacion2D(q0,b0,ang); rotacion2D(q1,b1,ang); rotacion2D(q2,b2,ang); rotacion2D(q3,b3,ang); rotacion2D(q4,b4,ang); glColor3f(0.50,0.21,0.42); glBegin(GL_POLYGON); glVertex2fv(b0); glVertex2fv(b1); glVertex2fv(b2); glVertex2fv(b3); glVertex2fv(b4); glVertex2fv(b5); glEnd(); glFlush(); } if(value==3) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); ejesguia(); glutMouseFunc(mouse); s[0]=2; s[1]=2; escalado2D(q0,b0,s); escalado2D(q1,b1,s); escalado2D(q2,b2,s); escalado2D(q3,b3,s); escalado2D(q4,b4,s); glColor3f(1,1,0); glBegin(GL_POLYGON); glVertex2fv(b0); glVertex2fv(b1); glVertex2fv(b2); glVertex2fv(b3); glEnd(); glFlush(); } if(value==4) { // Mitad glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); ejesguia(); glutMouseFunc(mouse); s[0]=0.5; s[1]=0.5; escalado2D(q0,b0,s); escalado2D(q1,b1,s); escalado2D(q2,b2,s); escalado2D(q3,b3,s); escalado2D(q4,b4,s); glColor3f(1,1,0); glBegin(GL_POLYGON); glVertex2fv(b0); glVertex2fv(b1); glVertex2fv(b2); glVertex2fv(b3); glEnd(); glFlush(); } if(value==5) { // (0;0) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); ejesguia(); glutMouseFunc(mouse); } if(value==6) { // (xo,yo) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); ejesguia(); glutMouseFunc(mouse); } if(value==7) { //Posición Inicial glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); ejesguia(); glutMouseFunc(mouse); } if(value==8) { // Desde0 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); ejesguia(); glutMouseFunc(mouse); } } // FINMenú //Main int main (int argc,char** argv) { int menu, submenu1; //iniciacion de GLUT y pantalla glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowPosition(50,100); glutInitWindowSize(500,500); glutCreateWindow("Transformaciones"); glutMouseFunc(mouse); glutDisplayFunc (ejesguia); glutReshapeWindow (500,500); init(); glutMainLoop(); }//Findel Main
|
|
|
5
|
Programación / Programación C/C++ / SubMenus en Open gl
|
en: 31 Agosto 2012, 06:06 am
|
Hola!! Lo que pasa es que estoy haciendo un Menú en Opengl Debe en una opción reiniciarse, cambiar color de fondo y 3 salir 1.Pero es de un trique y cuando se reinicia no quiero que se borre todo (Mi cuadricula) entonces no le pondría la de GL_CLEAR 2. No se muy bien manejar los submenus, entonces no se como hacer que cambie el color de fondo Entonces necesito no se asesoría al respecto, por que cuando le doy reiniciar me termina saliendo color Aquí les dejo el Programa, quizá tengan alguna idea y Agradezco su Ayuda! #include <iostream> #include <GL/glut.h> #include <math.h> using namespace std; int matrizDatos[3][3]={-1,-1,-1,-1,-1,-1,-1,-1,-1}; void verificar(); int figura = 0; void menutriqui(int); void init(void) { glClearColor(0.0,0.0,0.0,0.0); glMatrixMode(GL_PROJECTION); //establece los parámetros de proyeccion gluOrtho2D(0.0,500.0,0.0,500.0); figura = 0; int submenu1; submenu1=glutCreateMenu(menutriqui); glutAddMenuEntry("Un Color", 3); glutAddMenuEntry("Otro Color", 4); glutAddMenuEntry("Tercer Color", 5); glutCreateMenu(menutriqui); glutAddMenuEntry("Reiniciar",1); glutAddSubMenu("Color de Fondo",submenu1); glutAddMenuEntry("Salir",2); glutAttachMenu(GLUT_RIGHT_BUTTON); } void lineSegment(void) { glClearColor(1.0f,1.0f,1.0f,1.0f); glClear(GL_COLOR_BUFFER_BIT); //borra la ventana de visualización glColor3f(0.0,1.0,0.0); //establece el color del segmento de línea glBegin(GL_LINES); glVertex2i(200,100); //especifica la geometria del segmento de línea glVertex2i(200,400); glVertex2i(300,100); //especifica la geometria del segmento de línea glVertex2i(300,400); glVertex2i(100,200); //especifica la geometria del segmento de línea glVertex2i(400,200); glVertex2i(100,300); //especifica la geometria del segmento de línea glVertex2i(400,300); glEnd(); glFlush(); } void imprimirMatriz() { for(int i=0;i<3;i++) { for(int j=0; j<3; j++) cout<<matrizDatos [j]<<", "; cout<<endl; }
}
void clic(int button, int state, int x, int y ) // Eventos del Mouse { if(state==GLUT_UP)return; int col, row; y = 500 -y;
if((x>100)&&(x<200)) col=0; else if((x>200)&&(x<300)) col=1; else if((x>300)&&(x<400)) col=2; else return;
if((y>100)&&(y<200)) row=0; else if((y>200)&&(y<300)) row=1; else if((y>300)&&(y<400)) row=2; else return;
int coordX = 150 + 100*col; int coordY = 150 + 100*row;
if(figura == 0 && matrizDatos[row][col]==-1) { matrizDatos[row][col]=0; glColor3f(0.1f,0.1f,0.1f); figura = 1; glBegin(GL_LINES); glVertex2i(coordX - 40 ,coordY -40); //especifica la geometria del segmento de línea glVertex2i(coordX + 40 ,coordY +40); glVertex2i(coordX - 40 ,coordY +40); //especifica la geometria del segmento de línea glVertex2i(coordX + 40 ,coordY -40);
glEnd(); figura=1;
} if (figura == 1 &&matrizDatos[row][col]==-1) { matrizDatos[row][col]=1; glColor3f(0.0f,0.0f,1.0f); figura = 0; glBegin(GL_LINE_LOOP); glVertex2f(coordX - 40 ,coordY -40); glVertex2f(coordX + 40 ,coordY -40); glVertex2f(coordX ,coordY +40);
figura=0; }
glEnd();
glFlush();
verificar(); imprimirMatriz();
}
void verificar(void)//FUNCION VERIFICAR { if (matrizDatos[0][0]==0 && matrizDatos[1][0]== 0 &&matrizDatos[2][0]==0 ||matrizDatos[0][0]==1 && matrizDatos[1][0]== 1 &&matrizDatos[2][0]==1 ) { glBegin(GL_LINES); glColor3f(0.0f,0.0f,1.0f); glVertex2i(150,100); glVertex2i(150,400); glEnd(); glFlush(); figura=3; cout<<"GANASTE"; } else if (matrizDatos[0][1]==0 &&matrizDatos[1][1]==0 &&matrizDatos[2][1]==0 || matrizDatos[0][1]==1 &&matrizDatos[1][1]==1 &&matrizDatos[2][1]==1) { glBegin(GL_LINES); glColor3f(0.0f,0.0f,1.0f); glVertex2i(250,100); glVertex2i(250,400); glEnd(); glFlush(); figura=3; cout<<"GANASTE"; }
else if (matrizDatos[0][2]==0 &&matrizDatos[1][2]==0 &&matrizDatos[2][2]==0 || matrizDatos[0][2]==1 &&matrizDatos[1][2]==1 &&matrizDatos[2][2]==1) { glBegin(GL_LINES); glColor3f(0.0f,0.0f,1.0f); glVertex2i(350,100); glVertex2i(350,400); glEnd(); glFlush(); figura=3; cout<<"GANASTE"; }
else if (matrizDatos[0][0]==0 &&matrizDatos[0][1]==0 &&matrizDatos[0][2]==0 || matrizDatos[0][0]==1 &&matrizDatos[0][1]==1 &&matrizDatos[0][2]==1) { glBegin(GL_LINES); glColor3f(0.0f,0.0f,1.0f); glVertex2i(100,150); glVertex2i(400,150); glEnd(); glFlush(); figura=3; cout<<"GANASTE"; } else if (matrizDatos[1][0]==0 &&matrizDatos[1][1]==0 &&matrizDatos[1][2]==0 || matrizDatos[1][0]==1 &&matrizDatos[1][1]==1 &&matrizDatos[1][2]==1) { glBegin(GL_LINES); glColor3f(0.0f,0.0f,1.0f); glVertex2i(100,250); glVertex2i(400,250); glEnd(); glFlush(); figura=3; cout<<"GANASTE"; }
else if (matrizDatos[2][0]==0 &&matrizDatos[2][1]==0 &&matrizDatos[2][2]==0 || matrizDatos[2][0]==1 &&matrizDatos[2][1]==1 &&matrizDatos[2][2]==1) { glBegin(GL_LINES); glColor3f(0.0f,0.0f,1.0f); glVertex2i(100,350); glVertex2i(400,350); glEnd(); glFlush(); figura=3; cout<<"GANASTE"; }
else if(matrizDatos[0][0]==0 &&matrizDatos[1][1]==0 &&matrizDatos[2][2]==0 || matrizDatos[0][0]==1 &&matrizDatos[1][1]==1 &&matrizDatos[2][2]==1)//verificar diagonal 1 { glBegin(GL_LINES); glColor3f(0.0f,0.0f,1.0f); glVertex2i(100,100); glVertex2i(400,400); glEnd(); glFlush(); figura=3; cout<<"GANASTE"; }
else if(matrizDatos[0][2]==0 && matrizDatos[1][1]==0 && matrizDatos[2][0]==0 || matrizDatos[0][2]==1 &&matrizDatos[1][1]==1 &&matrizDatos[2][0]==1)//verificar diagonal 2 { glBegin(GL_LINES); glColor3f(0.0f,0.0f,1.0f); glVertex2i(400,100); glVertex2i(100,400); glEnd(); glFlush(); figura=3; cout<<"GANASTE"; }
}
void menutriqui(int value) // Menutriqui { if(value==1) glutPostRedisplay; if(value==2) exit(0); if(value==3) glClearColor(1.0f,1.0f,1.0f,1.0f ); if(value==4) glClearColor(1.0f,0.0f,1.0f,0.0f ); if(value==5) glClearColor(0.0f,1.0f,0.0f,1.0f ); }
int main (int argc,char** argv) { glutInit(&argc,argv); //Inicializa GLUT glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); //establece el modo de visualizacion glutInitWindowPosition(50,100); //establece la posicion de la esquina superior //izquierda de la ventana de visualizacion glutInitWindowSize(500,500); //establece el ancho y la altura de la ventana //de visualizacion glutCreateWindow("Triqui"); //crea la ventana de visualizacion init(); //ejecuta el procedimiento de inicializacion glutMouseFunc(clic); glutDisplayFunc(lineSegment);//envia los graficos a la ventana de visualizacion glutMainLoop(); //muestra todo y espera }
|
|
|
6
|
Programación / Programación C/C++ / Open Gl en C++
|
en: 1 Agosto 2012, 00:39 am
|
Hola! Soy nueva en el tema de Open Gl, y pues le agradecería muchisimo tutoriales o explicación respecto al tema. Con base a eso Necesito crear un triqui(3 en Línea) en este programa y pues no se mucho al respecto pero llevo esto Agradezco de Antemano su ayuda.
Gracias!!!
|
|
|
7
|
Programación / Programación C/C++ / C++ y P.OO
|
en: 22 Julio 2012, 04:37 am
|
Tengo este código, pero no me deja declarar los métodos donde están y la verdad no creo que este bien :S Les Agradecería mucho la ayuda y una explicación de P.o.o #include <iostream> using namespace std; class IntroCompGraf { private: int x[100][3]; public: void leerDatos(); float alturaMedia(); float pesoMedia(); int numMujeres(); int numHombres(); };// Fin ICG float am1,am2; int A[3][3]={170,80,0,160,1,165,70,0}; int C[2][3]={170,60,0,165,65,1}; void IntroCompGraf::leerDatos(int B [][3]); { for(i=0;i<n;i++) { for(j=0;j<3;j++) { x [j]=B[j]; } }; return ; };//LeerD
float IntroCompGraf::alturaMedia(int n) { int suma=0, media; for(i=0;i<n;i++) {
suma=x }; media=suma/n; return media; };//finaM
float IntroCompGraf::pesoMedia(int n) { int suma=0, media; for(i=0;i<n;i++) {
suma=x[1]+suma;
}; media=suma/n; return media; };//finpM
float IntroCompGraf::numHombres(int n) { int aux; for(i=0;i<n;i++) { if(x[3]=1) { aux=++ }; };
return aux; };//finnH
float IntroCompGraf::numMujeres(int n) { int aux; for(i=0;i<n;i++) { if(x[4]=1) { aux=++ }; };
return aux; };//finnM
int main () {
IntroCompGraf g1,g2; g1.leerDatos(A,3); am1=g1.alturaMedia(); g2.leerDatos(C,2); am2=g2.alturaMedia();
}//Fin Main
Muchas Gracias!
|
|
|
8
|
Programación / Programación C/C++ / ¿Cómo se puede hacer un programa con listas en c++?
|
en: 29 Abril 2012, 06:01 am
|
Ayuda un poco con el Tema de Listas en C++ Bien necesito hacer un programa que utilice listas y haga los siguiente: Las notas del estudiante Haga el promedio Me diga cual es el mayor y cual es el menor Cuales son los que perdieron y los que pasaron y llevo lo siguiente: Pienso hacerlo con funciones para cada uno, Que tal una ayudita en este código y explicación de las Listas se lo agradecería float nota2; float nota3; float definitiva; nodo *sig; }; int main () { nodo *L;//uno contiene datos y el otro genera la lista/ nodo *P; int i; float promedio=0; float notamayor; float notamenor; L=NULL;//sin * por que le asigno datos for (i=1;i<=5;i++) { P=new nodo; cout<<"hola, porfavor digite la primera nota del estudiante"; cin>>P->nota1; cout<<"porfavor digite la segunda nota del estudiante"; cin>>P->nota2; cout<<"hola, porfavor digite la tercera nota del estudiante"; cin>>P->nota3; P->definitiva=(P->nota1+P->nota2+P->nota… cout<<"la definitiva del estudiante es :" <<P->definitiva<<endl; P->sig=L; L=P; } P=L; while(P!=NULL) { promedio=+P->definitiva; P=P->sig; } cout<<"el promedio de los estudiantes es: "<<promedio<<endl; system("pause"); return 0; }//Fin Main()
|
|
|
|
|
|
|