Änfänger probleme



  • doch das programm passt soweit nur ich möchte nicht mehrere ausgaben sonder so das immer nur eine auf dem bild ist:

    |____________

    und wenn man w drückt soll alles auf dem selben bild passieren oder zumindes soll es so aussehen also nicht so

    |_____________

    w
    |___________

    sonder auf einer fläche also soll der bildschirm nach jeder eingabe gelöscht werden aber wie???

    und kann mir nochmal einer erklären wie ich die konsole auf vollbild kriege???



  • Ok, ich kann's nicht mehr mit ansehen (bzw. -lesen). 😉 Ich hab dir mal ganz schnell was dahingeschludert, was in etwa das macht, was du willst. Du kannst mit diesem Code ein 'X' per WSAD über den Bildschirm bewegen und per ESC das Programm schließen. Das ist zwar mieser Code (z.B. fehlen sämtliche Sicherheitsüberprüfungen), aber das wird dich sicher nicht stören. Eine gute Aufgabe wäre, wenn du das Programm analysierst und dann hier mit deinen eigenen Worten beschreibst, was da im Einzelnen passiert.

    Viel Spaß.

    #include <iostream>
    #include <conio.h>
    #include <windows.h>
    
    using namespace std;
    
    enum { PseudoSprite='X' };
    
    void gotoxy(int x, int y) {
    	COORD c;
    	c.X = x - 1;
    	c.Y = y - 1;
    	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
    }
    
    void ClearScreen() {
    	system("cls");
    }
    
    void PrintSprite(int x,int y) {
    	ClearScreen();
    	gotoxy(x,y);
    	putc(PseudoSprite,stdout);
    
    }
    
    int main()
    {
    	bool bQuit=false;
    	int x=40,y=25;
    
    	ClearScreen();
    
    	while(!bQuit) {
    		while(!kbhit());
    		char c=getche();
    		switch(c) {
    			case 'w':
    				--y;
    				break;
    			case 's':
    				++y;
    				break;
    			case 'a':
    				--x;
    				break;
    			case 'd':
    				++x;
    				break;
    			case 27:
    				bQuit=true;
    				break;
    		}
    		PrintSprite(x,y);
    	}
    }
    


  • sssaaaaaaaaaaauuuuuuuuuuuuuuu cccccccccccccoooooooooooooooooooolllllllllllllllllll
    danke danke danke

    aber wie bekomme ich das in vollbild????



  • 😡 Und wieder hast du nix gelernt wie auch schon nicht zuvor aus den Büchern, bitte werde kein Arzt.

    Hier lernst du C++: http://www2.fh-augsburg.de/informatik/vorlesungen/XX/c_cplus/tutorial/henkel/
    Hier lernst du alles über Windowsprogrammierung: http://msdn.microsoft.com/de-de/default.aspx
    Und hier für den Rest: http://www.google.de

    Ich hoffe du kannst dir selbst den Hintern abwischen 👎



  • valederkleine schrieb:

    aber wie bekomme ich das in vollbild????

    http://lmgtfy.com/?q=c%2B%2B+konsole+vollbild

    😉



  • Wie wär's, wenn du meinen Ratschlag mal befolgst? Analysiere das Programm, versuche zu verstehen, was da passiert und teile uns deine Ergebnisse in diesem Thread mit. 💡



  • Hallo das hier kannste auch in Vollbilschirm Schalten.
    Ist sogar mit FARBE ! xD

    Quelle: http://nehe.gamedev.net/

    Viel Spaße beim Copy & Paste

    Lesson40_bcb.cpp

    //------------------------------------------------------------------------
    //
    //  This Code Was Created By Erkin Tunca
    //	OpenGL Tutorial #39
    //  If You've Found This Code Useful, Please Let Me Know.
    //  Visit NeHe Productions At http://nehe.gamedev.net
    //
    //  Translation to CBuilder by Le Thanh Cong (conglth@hotmail.com)
    //
    //------------------------------------------------------------------------
    
    #include <windows.h>														// Header File For Windows
    #include <gl\gl.h>															// Header File For The OpenGL32 Library
    #include <gl\glu.h>															// Header File For The GLu32 Library
    #include "NeHeGL.h"															// Header File For NeHeGL
    
    #include "Physics2.h"														// Header File For Physics2.h
    
    #pragma hdrstop
    #include <condefs.h>
    
    //---------------------------------------------------------------------------
    USEUNIT("NeHeGL.cpp");
    //---------------------------------------------------------------------------
    #pragma argsused
    
    #ifndef CDS_FULLSCREEN														// CDS_FULLSCREEN Is Not Defined By Some
    #define CDS_FULLSCREEN 4													// Compilers. By Defining It This Way,
    #endif																		// We Can Avoid Errors
    
    GL_Window*	g_window;
    Keys*		g_keys;
    static BOOL g_isProgramLooping;											// Window Creation Loop, For FullScreen/Windowed Toggle																		// Between Fullscreen / Windowed Mode
    
    /*
      class RopeSimulation is derived from class Simulation (see Physics1.h). It simulates a rope with 
      point-like particles binded with springs. The springs have inner friction and normal length. One tip of 
      the rope is stabilized at a point in space called "Vector3D ropeConnectionPos". This point can be 
      moved externally by a method "void setRopeConnectionVel(Vector3D ropeConnectionVel)". RopeSimulation 
      creates air friction and a planer surface (or ground) with a normal in +y direction. RopeSimulation 
      implements the force applied by this surface. In the code, the surface is refered as "ground".
    */
    RopeSimulation* ropeSimulation = new RopeSimulation(
    													80,						// 80 Particles (Masses)
    													0.05f,					// Each Particle Has A Weight Of 50 Grams
    													10000.0f,				// springConstant In The Rope
    													0.05f,					// Normal Length Of Springs In The Rope
    													0.2f,					// Spring Inner Friction Constant
    													Vector3D(0, -9.81f, 0), // Gravitational Acceleration
    													0.02f,					// Air Friction Constant
    													100.0f,					// Ground Repel Constant
    													0.2f,					// Ground Slide Friction Constant
    													2.0f,					// Ground Absoption Constant
    													-1.5f);					// Height Of Ground
    
    BOOL Initialize (GL_Window* window, Keys* keys)								// Any GL Init Code & User Initialiazation Goes Here
    {
    	g_window	= window;
    	g_keys		= keys;
    
    	ropeSimulation->getMass(ropeSimulation->numOfMasses - 1)->vel.z = 10.0f;
    
    	glClearColor (0.0f, 0.0f, 0.0f, 0.5f);									// Black Background
    	glClearDepth (1.0f);													// Depth Buffer Setup
    	glShadeModel (GL_SMOOTH);												// Select Smooth Shading
    	glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);						// Set Perspective Calculations To Most Accurate
    
    	return TRUE;															// Return TRUE (Initialization Successful)
    }
    
    void Deinitialize (void)													// Any User DeInitialization Goes Here
    {
    	ropeSimulation->release();												// Release The ropeSimulation
    	delete(ropeSimulation);													// Delete The ropeSimulation
    	ropeSimulation = NULL;
    }
    
    void Update (DWORD milliseconds)											// Perform Motion Updates Here
    {
    	if (g_keys->keyDown [VK_ESCAPE] == TRUE)								// Is ESC Being Pressed?
    		TerminateApplication (g_window);									// Terminate The Program
    
    	if (g_keys->keyDown [VK_F1] == TRUE)									// Is F1 Being Pressed?
    		ToggleFullscreen (g_window);										// Toggle Fullscreen Mode
    
    	Vector3D ropeConnectionVel;												// Create A Temporary Vector3D
    
    	// Keys Are Used To Move The Rope
    	if (g_keys->keyDown [VK_RIGHT] == TRUE)									// Is The Right Arrow Being Pressed?
    		ropeConnectionVel.x += 3.0f;										// Add Velocity In +X Direction
    
    	if (g_keys->keyDown [VK_LEFT] == TRUE)									// Is The Left Arrow Being Pressed?
    		ropeConnectionVel.x -= 3.0f;										// Add Velocity In -X Direction
    
    	if (g_keys->keyDown [VK_UP] == TRUE)									// Is The Up Arrow Being Pressed?
    		ropeConnectionVel.z -= 3.0f;										// Add Velocity In +Z Direction
    
    	if (g_keys->keyDown [VK_DOWN] == TRUE)									// Is The Down Arrow Being Pressed?
    		ropeConnectionVel.z += 3.0f;										// Add Velocity In -Z Direction
    
    	if (g_keys->keyDown [VK_HOME] == TRUE)									// Is The Home Key Pressed?
    		ropeConnectionVel.y += 3.0f;										// Add Velocity In +Y Direction
    
    	if (g_keys->keyDown [VK_END] == TRUE)									// Is The End Key Pressed?
    		ropeConnectionVel.y -= 3.0f;										// Add Velocity In -Y Direction
    
    	ropeSimulation->setRopeConnectionVel(ropeConnectionVel);				// Set The Obtained ropeConnectionVel In The Simulation
    
    	float dt = milliseconds / 1000.0f;										// Let's Convert Milliseconds To Seconds
    
    	float maxPossible_dt = 0.002f;											// Maximum Possible dt Is 0.002 Seconds
    																			// This Is Needed To Prevent Pass Over Of A Non-Precise dt Value
    
      	int numOfIterations = (int)(dt / maxPossible_dt) + 1;					// Calculate Number Of Iterations To Be Made At This Update Depending On maxPossible_dt And dt
    	if (numOfIterations != 0)												// Avoid Division By Zero
    		dt = dt / numOfIterations;											// dt Should Be Updated According To numOfIterations
    
    	for (int a = 0; a < numOfIterations; ++a)								// We Need To Iterate Simulations "numOfIterations" Times
    		ropeSimulation->operate(dt);
    }
    
    void Draw (void)
    {
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity ();														// Reset The Modelview Matrix
    
    	// Position Camera 40 Meters Up In Z-Direction.
    	// Set The Up Vector In Y-Direction So That +X Directs To Right And +Y Directs To Up On The Window.
    	gluLookAt(0, 0, 4, 0, 0, 0, 0, 1, 0);						
    
    	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);					// Clear Screen And Depth Buffer
    
    	// Draw A Plane To Represent The Ground (Different Colors To Create A Fade)
    	glBegin(GL_QUADS);
    		glColor3ub(0, 0, 255);												// Set Color To Light Blue
    		glVertex3f(20, ropeSimulation->groundHeight, 20);
    		glVertex3f(-20, ropeSimulation->groundHeight, 20);
    		glColor3ub(0, 0, 0);												// Set Color To Black
    		glVertex3f(-20, ropeSimulation->groundHeight, -20);
    		glVertex3f(20, ropeSimulation->groundHeight, -20);
    	glEnd();
    
    	// Start Drawing Shadow Of The Rope
    	glColor3ub(0, 0, 0);													// Set Color To Black
    	for (int a = 0; a < ropeSimulation->numOfMasses - 1; ++a)
    	{
    		Mass* mass1 = ropeSimulation->getMass(a);
    		Vector3D* pos1 = &mass1->pos;
    
    		Mass* mass2 = ropeSimulation->getMass(a + 1);
    		Vector3D* pos2 = &mass2->pos;
    
    		glLineWidth(2);
    		glBegin(GL_LINES);
    			glVertex3f(pos1->x, ropeSimulation->groundHeight, pos1->z);		// Draw Shadow At groundHeight
    			glVertex3f(pos2->x, ropeSimulation->groundHeight, pos2->z);		// Draw Shadow At groundHeight
    		glEnd();
    	}
    	// Drawing Shadow Ends Here.
    
    	// Start Drawing The Rope.
    	glColor3ub(255, 255, 0);												// Set Color To Yellow
    	for (int a = 0; a < ropeSimulation->numOfMasses - 1; ++a)
    	{
    		Mass* mass1 = ropeSimulation->getMass(a);
    		Vector3D* pos1 = &mass1->pos;
    
    		Mass* mass2 = ropeSimulation->getMass(a + 1);
    		Vector3D* pos2 = &mass2->pos;
    
    		glLineWidth(4);
    		glBegin(GL_LINES);
    			glVertex3f(pos1->x, pos1->y, pos1->z);
    			glVertex3f(pos2->x, pos2->y, pos2->z);
    		glEnd();
    	}
    	// Drawing The Rope Ends Here.
    
    	glFlush ();																// Flush The GL Rendering Pipeline
    }
    LRESULT CALLBACK WindowProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	// Get The Window Context
    	GL_Window* window = (GL_Window*)(GetWindowLong (hWnd, GWL_USERDATA));
    
    	switch (uMsg)														// Evaluate Window Message
    	{
    		case WM_SYSCOMMAND:												// Intercept System Commands
    		{
    			switch (wParam)												// Check System Calls
    			{
    				case SC_SCREENSAVE:										// Screensaver Trying To Start?
    				case SC_MONITORPOWER:									// Monitor Trying To Enter Powersave?
    				return 0;												// Prevent From Happening
    			}
    			break;														// Exit
    		}
    		return 0;														// Return
    
    		case WM_CREATE:													// Window Creation
    		{
    			CREATESTRUCT* creation = (CREATESTRUCT*)(lParam);			// Store Window Structure Pointer
    			window = (GL_Window*)(creation->lpCreateParams);
    			SetWindowLong (hWnd, GWL_USERDATA, (LONG)(window));
    		}
    		return 0;														// Return
    
    		case WM_CLOSE:													// Closing The Window
    			TerminateApplication(window);								// Terminate The Application
    		return 0;														// Return
    
    		case WM_SIZE:													// Size Action Has Taken Place
    			switch (wParam)												// Evaluate Size Action
    			{
    				case SIZE_MINIMIZED:									// Was Window Minimized?
    					window->isVisible = FALSE;							// Set isVisible To False
    				return 0;												// Return
    
    				case SIZE_MAXIMIZED:									// Was Window Maximized?
    					window->isVisible = TRUE;							// Set isVisible To True
    					ReshapeGL (LOWORD (lParam), HIWORD (lParam));		// Reshape Window - LoWord=Width, HiWord=Height
    				return 0;												// Return
    
    				case SIZE_RESTORED:										// Was Window Restored?
    					window->isVisible = TRUE;							// Set isVisible To True
    					ReshapeGL (LOWORD (lParam), HIWORD (lParam));		// Reshape Window - LoWord=Width, HiWord=Height
    				return 0;												// Return
    			}
    		break;															// Break
    
    		case WM_KEYDOWN:												// Update Keyboard Buffers For Keys Pressed
    			if ((wParam >= 0) && (wParam <= 255))						// Is Key (wParam) In A Valid Range?
    			{
    				window->keys->keyDown [wParam] = TRUE;					// Set The Selected Key (wParam) To True
    				return 0;												// Return
    			}
    		break;															// Break
    
    		case WM_KEYUP:													// Update Keyboard Buffers For Keys Released
    			if ((wParam >= 0) && (wParam <= 255))						// Is Key (wParam) In A Valid Range?
    			{
    				window->keys->keyDown [wParam] = FALSE;					// Set The Selected Key (wParam) To False
    				return 0;												// Return
    			}
    		break;															// Break
    
    		case WM_TOGGLEFULLSCREEN:										// Toggle FullScreen Mode On/Off
    			g_createFullScreen = (g_createFullScreen == TRUE) ? FALSE : TRUE;
    			PostMessage (hWnd, WM_QUIT, 0, 0);
    		break;															// Break
    	}
    
    	return DefWindowProc (hWnd, uMsg, wParam, lParam);					// Pass Unhandled Messages To DefWindowProc
    }
    
    BOOL RegisterWindowClass (Application* application)						// Register A Window Class For This Application.
    {																		// TRUE If Successful
    	// Register A Window Class
    	WNDCLASSEX windowClass;												// Window Class
    	ZeroMemory (&windowClass, sizeof (WNDCLASSEX));						// Make Sure Memory Is Cleared
    	windowClass.cbSize			= sizeof (WNDCLASSEX);					// Size Of The windowClass Structure
    	windowClass.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	// Redraws The Window For Any Movement / Resizing
    	windowClass.lpfnWndProc		= (WNDPROC)(WindowProc);				// WindowProc Handles Messages
    	windowClass.hInstance		= application->hInstance;				// Set The Instance
    	windowClass.hbrBackground	= (HBRUSH)(COLOR_APPWORKSPACE);			// Class Background Brush Color
    	windowClass.hCursor			= LoadCursor(NULL, IDC_ARROW);			// Load The Arrow Pointer
    	windowClass.lpszClassName	= application->className;				// Sets The Applications Classname
    	if (RegisterClassEx (&windowClass) == 0)							// Did Registering The Class Fail?
    	{
    		// NOTE: Failure, Should Never Happen
    		MessageBox (HWND_DESKTOP, "RegisterClassEx Failed!", "Error", MB_OK | MB_ICONEXCLAMATION);
    		return FALSE;													// Return False (Failure)
    	}
    	return TRUE;														// Return True (Success)
    }
    
    // Program Entry (WinMain)
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    	Application			application;									// Application Structure
    	GL_Window			window;											// Window Structure
    	Keys				keys;											// Key Structure
    	BOOL				isMessagePumpActive;							// Message Pump Active?
    	MSG					msg;											// Window Message Structure
    	DWORD				tickCount;										// Used For The Tick Counter
    
    	// Fill Out Application Data
    	application.className = "OpenGL";									// Application Class Name
    	application.hInstance = hInstance;									// Application Instance
    
    	// Fill Out Window
    	ZeroMemory (&window, sizeof (GL_Window));							// Make Sure Memory Is Zeroed
    	window.keys					= &keys;								// Window Key Structure
    	window.init.application		= &application;							// Window Application
    	window.init.title			= "NeHe & Erkin Tunca's Physics Tutorial";	// Window Title
    	window.init.width			= 640;									// Window Width
    	window.init.height			= 480;									// Window Height
    	window.init.bitsPerPixel	= 16;									// Bits Per Pixel
    	window.init.isFullScreen	= TRUE;									// Fullscreen? (Set To TRUE)
    
    	ZeroMemory (&keys, sizeof (Keys));									// Zero keys Structure
    
    	// Ask The User If They Want To Start In FullScreen Mode?
    	if (MessageBox (HWND_DESKTOP, "Would You Like To Run In Fullscreen Mode?", "Start FullScreen?", MB_YESNO | MB_ICONQUESTION) == IDNO)
    	{
    		window.init.isFullScreen = FALSE;								// If Not, Run In Windowed Mode
    	}
    
    	// Register A Class For Our Window To Use
    	if (RegisterWindowClass (&application) == FALSE)					// Did Registering A Class Fail?
    	{
    		// Failure
    		MessageBox (HWND_DESKTOP, "Error Registering Window Class!", "Error", MB_OK | MB_ICONEXCLAMATION);
    		return -1;														// Terminate Application
    	}
    
    	g_isProgramLooping = TRUE;											// Program Looping Is Set To TRUE
    	g_createFullScreen = window.init.isFullScreen;						// g_createFullScreen Is Set To User Default
    	while (g_isProgramLooping)											// Loop Until WM_QUIT Is Received
    	{
    		// Create A Window
    		window.init.isFullScreen = g_createFullScreen;					// Set Init Param Of Window Creation To Fullscreen?
    		if (CreateWindowGL (&window) == TRUE)							// Was Window Creation Successful?
    		{
    			// At This Point We Should Have A Window That Is Setup To Render OpenGL
    			if (Initialize (&window, &keys) == FALSE)					// Call User Intialization
    			{
    				// Failure
    				TerminateApplication (&window);							// Close Window, This Will Handle The Shutdown
    			}
    			else														// Otherwise (Start The Message Pump)
    			{	// Initialize was a success
    				isMessagePumpActive = TRUE;								// Set isMessagePumpActive To TRUE
    				while (isMessagePumpActive == TRUE)						// While The Message Pump Is Active
    				{
    					// Success Creating Window.  Check For Window Messages
    					if (PeekMessage (&msg, window.hWnd, 0, 0, PM_REMOVE) != 0)
    					{
    						// Check For WM_QUIT Message
    						if (msg.message != WM_QUIT)						// Is The Message A WM_QUIT Message?
    						{
    							DispatchMessage (&msg);						// If Not, Dispatch The Message
    						}
    						else											// Otherwise (If Message Is WM_QUIT)
    						{
    							isMessagePumpActive = FALSE;				// Terminate The Message Pump
    						}
    					}
    					else												// If There Are No Messages
    					{
    						if (window.isVisible == FALSE)					// If Window Is Not Visible
    						{
    							WaitMessage ();								// Application Is Minimized Wait For A Message
    						}
    						else											// If Window Is Visible
    						{
    							// Process Application Loop
    							tickCount = GetTickCount ();				// Get The Tick Count
    							Update (tickCount - window.lastTickCount);	// Update The Counter
    							window.lastTickCount = tickCount;			// Set Last Count To Current Count
    							Draw ();									// Draw Our Scene
    
    							SwapBuffers (window.hDC);					// Swap Buffers (Double Buffering)
    						}
    					}
    				}														// Loop While isMessagePumpActive == TRUE
    			}															// If (Initialize (...
    
    			// Application Is Finished
    			Deinitialize ();											// User Defined DeInitialization
    
    			DestroyWindowGL (&window);									// Destroy The Active Window
    		}
    		else															// If Window Creation Failed
    		{
    			// Error Creating Window
    			MessageBox (HWND_DESKTOP, "Error Creating OpenGL Window", "Error", MB_OK | MB_ICONEXCLAMATION);
    			g_isProgramLooping = FALSE;									// Terminate The Loop
    		}
    	}																	// While (isProgramLooping)
    
    	UnregisterClass (application.className, application.hInstance);		// UnRegister Window Class
    	return 0;
    }																		// End Of WinMain()
    
    void TerminateApplication (GL_Window* window)							// Terminate The Application
    {
    	PostMessage (window->hWnd, WM_QUIT, 0, 0);							// Send A WM_QUIT Message
    	g_isProgramLooping = FALSE;											// Stop Looping Of The Program
    }
    

    NeHeGL.cpp

    /***********************************************
    *                                              *
    *    Jeff Molofee's Revised OpenGL Basecode    *
    *  Huge Thanks To Maxwell Sayles & Peter Puck  *
    *            http://nehe.gamedev.net           *
    *                     2001                     *
    *                                              *
    ***********************************************/
    
    #include <windows.h>													// Header File For The Windows Library
    #include <gl/gl.h>														// Header File For The OpenGL32 Library
    #include <gl/glu.h>														// Header File For The GLu32 Library
    
    #include "NeHeGL.h"														// Header File For The NeHeGL Basecode
    
    void ToggleFullscreen (GL_Window* window)								// Toggle Fullscreen/Windowed
    {
    	PostMessage (window->hWnd, WM_TOGGLEFULLSCREEN, 0, 0);				// Send A WM_TOGGLEFULLSCREEN Message
    }
    
    void ReshapeGL (int width, int height)									// Reshape The Window When It's Moved Or Resized
    {
    	glViewport (0, 0, (GLsizei)(width), (GLsizei)(height));				// Reset The Current Viewport
    	glMatrixMode (GL_PROJECTION);										// Select The Projection Matrix
    	glLoadIdentity ();													// Reset The Projection Matrix
    	gluPerspective (45.0f, (GLfloat)(width)/(GLfloat)(height),			// Calculate The Aspect Ratio Of The Window
    					1.0f, 100.0f);		
    	glMatrixMode (GL_MODELVIEW);										// Select The Modelview Matrix
    	glLoadIdentity ();													// Reset The Modelview Matrix
    }
    
    BOOL ChangeScreenResolution (int width, int height, int bitsPerPixel)	// Change The Screen Resolution
    {
    	DEVMODE dmScreenSettings;											// Device Mode
    	ZeroMemory (&dmScreenSettings, sizeof (DEVMODE));					// Make Sure Memory Is Cleared
    	dmScreenSettings.dmSize				= sizeof (DEVMODE);				// Size Of The Devmode Structure
    	dmScreenSettings.dmPelsWidth		= width;						// Select Screen Width
    	dmScreenSettings.dmPelsHeight		= height;						// Select Screen Height
    	dmScreenSettings.dmBitsPerPel		= bitsPerPixel;					// Select Bits Per Pixel
    	dmScreenSettings.dmFields			= DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
    	if (ChangeDisplaySettings (&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
    	{
    		return FALSE;													// Display Change Failed, Return False
    	}
    	return TRUE;														// Display Change Was Successful, Return True
    }
    
    BOOL CreateWindowGL (GL_Window* window)									// This Code Creates Our OpenGL Window
    {
    	DWORD windowStyle = WS_OVERLAPPEDWINDOW;							// Define Our Window Style
    	DWORD windowExtendedStyle = WS_EX_APPWINDOW;						// Define The Window's Extended Style
    
    	PIXELFORMATDESCRIPTOR pfd =											// pfd Tells Windows How We Want Things To Be
    	{
    		sizeof (PIXELFORMATDESCRIPTOR),									// Size Of This Pixel Format Descriptor
    		1,																// Version Number
    		PFD_DRAW_TO_WINDOW |											// Format Must Support Window
    		PFD_SUPPORT_OPENGL |											// Format Must Support OpenGL
    		PFD_DOUBLEBUFFER,												// Must Support Double Buffering
    		PFD_TYPE_RGBA,													// Request An RGBA Format
    		window->init.bitsPerPixel,										// Select Our Color Depth
    		0, 0, 0, 0, 0, 0,												// Color Bits Ignored
    		0,																// No Alpha Buffer
    		0,																// Shift Bit Ignored
    		0,																// No Accumulation Buffer
    		0, 0, 0, 0,														// Accumulation Bits Ignored
    		16,																// 16Bit Z-Buffer (Depth Buffer)  
    		0,																// No Stencil Buffer
    		0,																// No Auxiliary Buffer
    		PFD_MAIN_PLANE,													// Main Drawing Layer
    		0,																// Reserved
    		0, 0, 0															// Layer Masks Ignored
    	};
    
    	RECT windowRect = {0, 0, window->init.width, window->init.height};	// Define Our Window Coordinates
    
    	GLuint PixelFormat;													// Will Hold The Selected Pixel Format
    
    	if (window->init.isFullScreen == TRUE)								// Fullscreen Requested, Try Changing Video Modes
    	{
    		if (ChangeScreenResolution (window->init.width, window->init.height, window->init.bitsPerPixel) == FALSE)
    		{
    			// Fullscreen Mode Failed.  Run In Windowed Mode Instead
    			MessageBox (HWND_DESKTOP, "Mode Switch Failed.\nRunning In Windowed Mode.", "Error", MB_OK | MB_ICONEXCLAMATION);
    			window->init.isFullScreen = FALSE;							// Set isFullscreen To False (Windowed Mode)
    		}
    		else															// Otherwise (If Fullscreen Mode Was Successful)
    		{
    			ShowCursor (FALSE);											// Turn Off The Cursor
    			windowStyle = WS_POPUP;										// Set The WindowStyle To WS_POPUP (Popup Window)
    			windowExtendedStyle |= WS_EX_TOPMOST;						// Set The Extended Window Style To WS_EX_TOPMOST
    		}																// (Top Window Covering Everything Else)
    	}
    	else																// If Fullscreen Was Not Selected
    	{
    		// Adjust Window, Account For Window Borders
    		AdjustWindowRectEx (&windowRect, windowStyle, 0, windowExtendedStyle);
    	}
    
    	// Create The OpenGL Window
    	window->hWnd = CreateWindowEx (windowExtendedStyle,					// Extended Style
    								   window->init.application->className,	// Class Name
    								   window->init.title,					// Window Title
    								   windowStyle,							// Window Style
    								   0, 0,								// Window X,Y Position
    								   windowRect.right - windowRect.left,	// Window Width
    								   windowRect.bottom - windowRect.top,	// Window Height
    								   HWND_DESKTOP,						// Desktop Is Window's Parent
    								   0,									// No Menu
    								   window->init.application->hInstance, // Pass The Window Instance
    								   window);
    
    	if (window->hWnd == 0)												// Was Window Creation A Success?
    	{
    		return FALSE;													// If Not Return False
    	}
    
    	window->hDC = GetDC (window->hWnd);									// Grab A Device Context For This Window
    	if (window->hDC == 0)												// Did We Get A Device Context?
    	{
    		// Failed
    		DestroyWindow (window->hWnd);									// Destroy The Window
    		window->hWnd = 0;												// Zero The Window Handle
    		return FALSE;													// Return False
    	}
    
    	PixelFormat = ChoosePixelFormat (window->hDC, &pfd);				// Find A Compatible Pixel Format
    	if (PixelFormat == 0)												// Did We Find A Compatible Format?
    	{
    		// Failed
    		ReleaseDC (window->hWnd, window->hDC);							// Release Our Device Context
    		window->hDC = 0;												// Zero The Device Context
    		DestroyWindow (window->hWnd);									// Destroy The Window
    		window->hWnd = 0;												// Zero The Window Handle
    		return FALSE;													// Return False
    	}
    
    	if (SetPixelFormat (window->hDC, PixelFormat, &pfd) == FALSE)		// Try To Set The Pixel Format
    	{
    		// Failed
    		ReleaseDC (window->hWnd, window->hDC);							// Release Our Device Context
    		window->hDC = 0;												// Zero The Device Context
    		DestroyWindow (window->hWnd);									// Destroy The Window
    		window->hWnd = 0;												// Zero The Window Handle
    		return FALSE;													// Return False
    	}
    
    	window->hRC = wglCreateContext (window->hDC);						// Try To Get A Rendering Context
    	if (window->hRC == 0)												// Did We Get A Rendering Context?
    	{
    		// Failed
    		ReleaseDC (window->hWnd, window->hDC);							// Release Our Device Context
    		window->hDC = 0;												// Zero The Device Context
    		DestroyWindow (window->hWnd);									// Destroy The Window
    		window->hWnd = 0;												// Zero The Window Handle
    		return FALSE;													// Return False
    	}
    
    	// Make The Rendering Context Our Current Rendering Context
    	if (wglMakeCurrent (window->hDC, window->hRC) == FALSE)
    	{
    		// Failed
    		wglDeleteContext (window->hRC);									// Delete The Rendering Context
    		window->hRC = 0;												// Zero The Rendering Context
    		ReleaseDC (window->hWnd, window->hDC);							// Release Our Device Context
    		window->hDC = 0;												// Zero The Device Context
    		DestroyWindow (window->hWnd);									// Destroy The Window
    		window->hWnd = 0;												// Zero The Window Handle
    		return FALSE;													// Return False
    	}
    
    	ShowWindow (window->hWnd, SW_NORMAL);								// Make The Window Visible
    	window->isVisible = TRUE;											// Set isVisible To True
    
    	ReshapeGL (window->init.width, window->init.height);				// Reshape Our GL Window
    
    	ZeroMemory (window->keys, sizeof (Keys));							// Clear All Keys
    
    	window->lastTickCount = GetTickCount ();							// Get Tick Count
    
    	return TRUE;														// Window Creating Was A Success
    																		// Initialization Will Be Done In WM_CREATE
    }
    
    BOOL DestroyWindowGL (GL_Window* window)								// Destroy The OpenGL Window & Release Resources
    {
    	if (window->hWnd != 0)												// Does The Window Have A Handle?
    	{	
    		if (window->hDC != 0)											// Does The Window Have A Device Context?
    		{
    			wglMakeCurrent (window->hDC, 0);							// Set The Current Active Rendering Context To Zero
    			if (window->hRC != 0)										// Does The Window Have A Rendering Context?
    			{
    				wglDeleteContext (window->hRC);							// Release The Rendering Context
    				window->hRC = 0;										// Zero The Rendering Context
    
    			}
    			ReleaseDC (window->hWnd, window->hDC);						// Release The Device Context
    			window->hDC = 0;											// Zero The Device Context
    		}
    		DestroyWindow (window->hWnd);									// Destroy The Window
    		window->hWnd = 0;												// Zero The Window Handle
    	}
    
    	if (window->init.isFullScreen)										// Is Window In Fullscreen Mode
    	{
    		ChangeDisplaySettings (NULL,0);									// Switch Back To Desktop Resolution
    		ShowCursor (TRUE);												// Show The Cursor
    	}	
    	return TRUE;														// Return True
    }
    

    NeHeGL.h

    /********************
    *                   *
    *   NeHeGL Header   *
    *                   *
    **********************************************************************************
    *                                                                                *
    *	You Need To Provide The Following Functions:                                 *
    *                                                                                *
    *	BOOL Initialize (GL_Window* window, Keys* keys);                             *
    *		Performs All Your Initialization                                         *
    *		Returns TRUE If Initialization Was Successful, FALSE If Not              *
    *		'window' Is A Parameter Used In Calls To NeHeGL                          *
    *		'keys' Is A Structure Containing The Up/Down Status Of keys              *
    *                                                                                *
    *	void Deinitialize (void);                                                    *
    *		Performs All Your DeInitialization                                       *
    *                                                                                *
    *	void Update (DWORD milliseconds);                                            *
    *		Perform Motion Updates                                                   *
    *		'milliseconds' Is The Number Of Milliseconds Passed Since The Last Call  *
    *		With Whatever Accuracy GetTickCount() Provides                           *
    *                                                                                *
    *	void Draw (void);                                                            *
    *		Perform All Your Scene Drawing                                           *
    *                                                                                *
    *********************************************************************************/
    
    #ifndef GL_FRAMEWORK__INCLUDED
    #define GL_FRAMEWORK__INCLUDED
    
    #include <windows.h>								// Header File For Windows
    
    #define WM_TOGGLEFULLSCREEN (WM_USER+1)									// Application Define Message For Toggling
    
    static BOOL g_createFullScreen;											// If TRUE, Then Create Fullscreen
    
    typedef struct {									// Structure For Keyboard Stuff
    	BOOL keyDown [256];								// Holds TRUE / FALSE For Each Key
    } Keys;												// Keys
    
    typedef struct {									// Contains Information Vital To Applications
    	HINSTANCE		hInstance;						// Application Instance
    	const char*		className;						// Application ClassName
    } Application;										// Application
    
    typedef struct {									// Window Creation Info
    	Application*		application;				// Application Structure
    	char*				title;						// Window Title
    	int					width;						// Width
    	int					height;						// Height
    	int					bitsPerPixel;				// Bits Per Pixel
    	BOOL				isFullScreen;				// FullScreen?
    } GL_WindowInit;									// GL_WindowInit
    
    typedef struct {									// Contains Information Vital To A Window
    	Keys*				keys;						// Key Structure
    	HWND				hWnd;						// Window Handle
    	HDC					hDC;						// Device Context
    	HGLRC				hRC;						// Rendering Context
    	GL_WindowInit		init;						// Window Init
    	BOOL				isVisible;					// Window Visible?
    	DWORD				lastTickCount;				// Tick Counter
    } GL_Window;										// GL_Window
    
    void TerminateApplication (GL_Window* window);		// Terminate The Application
    
    void ToggleFullscreen (GL_Window* window);			// Toggle Fullscreen / Windowed Mode
    
    // These Are The Function You Must Provide
    BOOL Initialize (GL_Window* window, Keys* keys);	// Performs All Your Initialization
    
    void Deinitialize (void);							// Performs All Your DeInitialization
    
    void Update (DWORD milliseconds);					// Perform Motion Updates
    
    void Draw (void);									// Perform All Your Scene Drawing
    
    void ReshapeGL (int width, int height);									// Reshape The Window When It's Moved Or Resized
    
    BOOL CreateWindowGL (GL_Window* window);									// This Code Creates Our OpenGL Window
    
    BOOL DestroyWindowGL (GL_Window* window);								// Destroy The OpenGL Window & Release Resources
    
    #endif												// GL_FRAMEWORK__INCLUDED
    

    Physics1.h

    /**************************************************************************
    
      File: Physics1.h  
    
      Prepared by Erkin Tunca for http://nehe.gamedev.net
    
    **************************************************************************/
    
    #include <math.h>
    
    // class Vector3D		---> An object to represent a 3D vector or a 3D point in space
    class Vector3D
    {
    public:
    	float x;									// the x value of this Vector3D
    	float y;									// the y value of this Vector3D
    	float z;									// the z value of this Vector3D
    
    	Vector3D()									// Constructor to set x = y = z = 0
    	{
    		x = 0;
    		y = 0;
    		z = 0;
    	}
    
    	Vector3D(float x, float y, float z)			// Constructor that initializes this Vector3D to the intended values of x, y and z
    	{
    		this->x = x;
    		this->y = y;
    		this->z = z;
    	}
    
    	Vector3D& operator= (Vector3D v)			// operator= sets values of v to this Vector3D. example: v1 = v2 means that values of v2 are set onto v1
    	{
    		x = v.x;
    		y = v.y;
    		z = v.z;
    		return *this;
    	}
    
    	Vector3D operator+ (Vector3D v)				// operator+ is used to add two Vector3D's. operator+ returns a new Vector3D
    	{
    		return Vector3D(x + v.x, y + v.y, z + v.z);
    	}
    
    	Vector3D operator- (Vector3D v)				// operator- is used to take difference of two Vector3D's. operator- returns a new Vector3D
    	{
    		return Vector3D(x - v.x, y - v.y, z - v.z);
    	}
    
    	Vector3D operator* (float value)			// operator* is used to scale a Vector3D by a value. This value multiplies the Vector3D's x, y and z.
    	{
    		return Vector3D(x * value, y * value, z * value);
    	}
    
    	Vector3D operator/ (float value)			// operator/ is used to scale a Vector3D by a value. This value divides the Vector3D's x, y and z.
    	{
    		return Vector3D(x / value, y / value, z / value);
    	}
    
    	Vector3D& operator+= (Vector3D v)			// operator+= is used to add another Vector3D to this Vector3D.
    	{
    		x += v.x;
    		y += v.y;
    		z += v.z;
    		return *this;
    	}
    
    	Vector3D& operator-= (Vector3D v)			// operator-= is used to subtract another Vector3D from this Vector3D.
    	{
    		x -= v.x;
    		y -= v.y;
    		z -= v.z;
    		return *this;
    	}
    
    	Vector3D& operator*= (float value)			// operator*= is used to scale this Vector3D by a value.
    	{
    		x *= value;
    		y *= value;
    		z *= value;
    		return *this;
    	}
    
    	Vector3D& operator/= (float value)			// operator/= is used to scale this Vector3D by a value.
    	{
    		x /= value;
    		y /= value;
    		z /= value;
    		return *this;
    	}
    
    	Vector3D operator- ()						// operator- is used to set this Vector3D's x, y, and z to the negative of them.
    	{
    		return Vector3D(-x, -y, -z);
    	}
    
    	float length()								// length() returns the length of this Vector3D
    	{
    		return sqrt(x*x + y*y + z*z);
    	};			   		
    
    	void unitize()								// unitize() normalizes this Vector3D that its direction remains the same but its length is 1.
    	{
    		float length = this->length();
    
    		if (length == 0)
    			return;
    
    		x /= length;
    		y /= length;
    		z /= length;
    	}
    
    	Vector3D unit()								// unit() returns a new Vector3D. The returned value is a unitized version of this Vector3D.
    	{
    		float length = this->length();
    
    		if (length == 0)
    			return *this;
    
    		return Vector3D(x / length, y / length, z / length);
    	}
    
    };
    
    // class Mass			---> An object to represent a mass
    class Mass
    {
    public:
    	float m;									// The mass value
    	Vector3D pos;								// Position in space
    	Vector3D vel;								// Velocity
    	Vector3D force;								// Force applied on this mass at an instance
    
    	Mass(float m)								// Constructor
    	{
    		this->m = m;
    	}
    
    	/*
    	  void applyForce(Vector3D force) method is used to add external force to the mass. 
    	  At an instance in time, several sources of force might affect the mass. The vector sum 
    	  of these forces make up the net force applied to the mass at the instance.
    	*/
    	void applyForce(Vector3D force)
    	{
    		this->force += force;					// The external force is added to the force of the mass
    	}
    
    	/*
    	  void init() method sets the force values to zero
    	*/
    	void init()
    	{
    		force.x = 0;
    		force.y = 0;
    		force.z = 0;
    	}
    
    	/*
    	  void simulate(float dt) method calculates the new velocity and new position of 
    	  the mass according to change in time (dt). Here, a simulation method called
    	  "The Euler Method" is used. The Euler Method is not always accurate, but it is 
    	  simple. It is suitable for most of physical simulations that we know in common 
    	  computer and video games.
    	*/
    	void simulate(float dt)
    	{
    		vel += (force / m) * dt;				// Change in velocity is added to the velocity.
    												// The change is proportinal with the acceleration (force / m) and change in time
    
    		pos += vel * dt;						// Change in position is added to the position.
    												// Change in position is velocity times the change in time
    	}
    
    };
    
    // class Simulation		---> A container object for simulating masses
    class Simulation
    {
    public:
    	int numOfMasses;								// number of masses in this container
    	Mass** masses;									// masses are held by pointer to pointer. (Here Mass** represents a 1 dimensional array)
    
    	Simulation(int numOfMasses, float m)			// Constructor creates some masses with mass values m
    	{
    		this->numOfMasses = numOfMasses;
    
    		masses = new Mass*[numOfMasses];			// Create an array of pointers
    
    		for (int a = 0; a < numOfMasses; ++a)		// We will step to every pointer in the array
    			masses[a] = new Mass(m);				// Create a Mass as a pointer and put it in the array
    	}
    
    	virtual void release()							// delete the masses created
    	{
    		for (int a = 0; a < numOfMasses; ++a)		// we will delete all of them
    		{
    			delete(masses[a]);
    			masses[a] = NULL;
    		}
    
    		delete(masses);
    		masses = NULL;
    	}
    
    	Mass* getMass(int index)
    	{
    		if (index < 0 || index >= numOfMasses)		// if the index is not in the array
    			return NULL;							// then return NULL
    
    		return masses[index];						// get the mass at the index
    	}
    
    	virtual void init()								// this method will call the init() method of every mass
    	{
    		for (int a = 0; a < numOfMasses; ++a)		// We will init() every mass
    			masses[a]->init();						// call init() method of the mass
    	}
    
    	virtual void solve()							// no implementation because no forces are wanted in this basic container
    	{
    													// in advanced containers, this method will be overrided and some forces will act on masses
    	}
    
    	virtual void simulate(float dt)					// Iterate the masses by the change in time
    	{
    		for (int a = 0; a < numOfMasses; ++a)		// We will iterate every mass
    			masses[a]->simulate(dt);				// Iterate the mass and obtain new position and new velocity
    	}
    
    	virtual void operate(float dt)					// The complete procedure of simulation
    	{
    		init();										// Step 1: reset forces to zero
    		solve();									// Step 2: apply forces
    		simulate(dt);								// Step 3: iterate the masses by the change in time
    	}
    
    };
    
    /*
      class ConstantVelocity is derived from class Simulation
      It creates 1 mass with mass value 1 kg and sets its velocity to (1.0f, 0.0f, 0.0f)
      so that the mass moves in the x direction with 1 m/s velocity.
    */
    class ConstantVelocity : public Simulation
    {
    public:
    	ConstantVelocity() : Simulation(1, 1.0f)				//Constructor firstly constructs its super class with 1 mass and 1 kg
    	{
    		masses[0]->pos = Vector3D(0.0f, 0.0f, 0.0f);		//a mass was created and we set its position to the origin
    		masses[0]->vel = Vector3D(1.0f, 0.0f, 0.0f);		//we set the mass's velocity to (1.0f, 0.0f, 0.0f)
    	}
    
    };
    
    /*
      class MotionUnderGravitation is derived from class Simulation
      It creates 1 mass with mass value 1 kg and sets its velocity to (10.0f, 15.0f, 0.0f) and its position to 
      (-10.0f, 0.0f, 0.0f). The purpose of this application is to apply a gravitational force to the mass and 
      observe the path it follows. The above velocity and position provides a fine projectile path with a 
      9.81 m/s/s downward gravitational acceleration. 9.81 m/s/s is a very close value to the gravitational 
      acceleration we experience on the earth.
    */
    class MotionUnderGravitation : public Simulation
    {
    public:
    	Vector3D gravitation;													//the gravitational acceleration
    
    	MotionUnderGravitation(Vector3D gravitation) : Simulation(1, 1.0f)		//Constructor firstly constructs its super class with 1 mass and 1 kg
    	{																		//Vector3D gravitation, is the gravitational acceleration
    		this->gravitation = gravitation;									//set this class's gravitation
    		masses[0]->pos = Vector3D(-10.0f, 0.0f, 0.0f);						//set the position of the mass
    		masses[0]->vel = Vector3D(10.0f, 15.0f, 0.0f);						//set the velocity of the mass
    	}
    
    	virtual void solve()													//gravitational force will be applied therefore we need a "solve" method.
    	{
    		for (int a = 0; a < numOfMasses; ++a)								//we will apply force to all masses (actually we have 1 mass, but we can extend it in the future)
    			masses[a]->applyForce(gravitation * masses[a]->m);				//gravitational force is as F = m * g. (mass times the gravitational acceleration)
    	}
    
    };
    
    /*
      class MassConnectedWithSpring is derived from class Simulation
      It creates 1 mass with mass value 1 kg and binds the mass to an arbitrary constant point with a spring. 
      This point is refered as the connectionPos and the spring has a springConstant value to represent its 
      stiffness.
    */
    class MassConnectedWithSpring : public Simulation
    {
    public:
    	float springConstant;													//more the springConstant, stiffer the spring force
    	Vector3D connectionPos;													//the arbitrary constant point that the mass is connected
    
    	MassConnectedWithSpring(float springConstant) : Simulation(1, 1.0f)		//Constructor firstly constructs its super class with 1 mass and 1 kg
    	{
    		this->springConstant = springConstant;								//set the springConstant
    
    		connectionPos = Vector3D(0.0f, -5.0f, 0.0f);						//set the connectionPos
    
    		masses[0]->pos = connectionPos + Vector3D(10.0f, 0.0f, 0.0f);		//set the position of the mass 10 meters to the right side of the connectionPos
    		masses[0]->vel = Vector3D(0.0f, 0.0f, 0.0f);						//set the velocity of the mass to zero
    	}
    
    	virtual void solve()													//the spring force will be applied
    	{
    		for (int a = 0; a < numOfMasses; ++a)								//we will apply force to all masses (actually we have 1 mass, but we can extend it in the future)
    		{
    			Vector3D springVector = masses[a]->pos - connectionPos;			//find a vector from the position of the mass to the connectionPos
    			masses[a]->applyForce(-springVector * springConstant);			//apply the force according to the famous spring force formulation
    		}
    	}
    
    };
    

    Physics2.h

    /**************************************************************************
    
      File: Physics2.h  
    
      Prepared by Erkin Tunca for nehe.gamedev.net
    
    **************************************************************************/
    
    #include "Physics1.h"									//Physics1.h is a must for Physics2.h simulations
    
    class Spring											//An object to represent a spring with inner friction binding two masses. The spring 
    														//has a normal length (the length that the spring does not exert any force)
    {
    public:
    	Mass* mass1;										//The first mass at one tip of the spring
    	Mass* mass2;										//The second mass at the other tip of the spring
    
    	float springConstant;								//A constant to represent the stiffness of the spring
    	float springLength;									//The length that the spring does not exert any force
    	float frictionConstant;								//A constant to be used for the inner friction of the spring
    
    	Spring(Mass* mass1, Mass* mass2, 
    		float springConstant, float springLength, float frictionConstant)		//Constructor
    	{
    		this->springConstant = springConstant;									//set the springConstant
    		this->springLength = springLength;										//set the springLength
    		this->frictionConstant = frictionConstant;								//set the frictionConstant
    
    		this->mass1 = mass1;													//set mass1
    		this->mass2 = mass2;													//set mass2
    	}
    
    	void solve()																	//solve() method: the method where forces can be applied
    	{
    		Vector3D springVector = mass1->pos - mass2->pos;							//vector between the two masses
    
    		float r = springVector.length();											//distance between the two masses
    
    		Vector3D force;																//force initially has a zero value
    
    		if (r != 0)																	//to avoid a division by zero check if r is zero
    			force += (springVector / r) * (r - springLength) * (-springConstant);	//the spring force is added to the force
    
    		force += -(mass1->vel - mass2->vel) * frictionConstant;						//the friction force is added to the force
    																					//with this addition we obtain the net force of the spring
    
    		mass1->applyForce(force);													//force is applied to mass1
    		mass2->applyForce(-force);													//the opposite of force is applied to mass2
    	}
    
    };
    
    /*
      class RopeSimulation is derived from class Simulation (see Physics1.h). It simulates a rope with 
      point-like particles binded with springs. The springs have inner friction and normal length. One tip of 
      the rope is stabilized at a point in space called "Vector3D ropeConnectionPos". This point can be 
      moved externally by a method "void setRopeConnectionVel(Vector3D ropeConnectionVel)". RopeSimulation 
      creates air friction and a planer surface (or ground) with a normal in +y direction. RopeSimulation 
      implements the force applied by this surface. In the code, the surface is refered as "ground".
    */
    class RopeSimulation : public Simulation				//An object to simulate a rope interacting with a planer surface and air
    {
    public:
    	Spring** springs;									//Springs binding the masses (there shall be [numOfMasses - 1] of them)
    
    	Vector3D gravitation;								//gravitational acceleration (gravity will be applied to all masses)
    
    	Vector3D ropeConnectionPos;							//A point in space that is used to set the position of the 
    														//first mass in the system (mass with index 0)
    
    	Vector3D ropeConnectionVel;							//a variable to move the ropeConnectionPos (by this, we can swing the rope)
    
    	float groundRepulsionConstant;						//a constant to represent how much the ground shall repel the masses
    
    	float groundFrictionConstant;						//a constant of friction applied to masses by the ground
    														//(used for the sliding of rope on the ground)
    
    	float groundAbsorptionConstant;						//a constant of absorption friction applied to masses by the ground
    														//(used for vertical collisions of the rope with the ground)
    
    	float groundHeight;									//a value to represent the y position value of the ground
    														//(the ground is a planer surface facing +y direction)
    
    	float airFrictionConstant;							//a constant of air friction applied to masses
    
    	RopeSimulation(										//a long long constructor with 11 parameters starts here
    		int numOfMasses,								//1. the number of masses
    		float m,										//2. weight of each mass
    		float springConstant,							//3. how stiff the springs are
    		float springLength,								//4. the length that a spring does not exert any force
    		float springFrictionConstant,					//5. inner friction constant of spring
    		Vector3D gravitation,							//6. gravitational acceleration
    		float airFrictionConstant,						//7. air friction constant
    		float groundRepulsionConstant,					//8. ground repulsion constant
    		float groundFrictionConstant,					//9. ground friction constant
    		float groundAbsorptionConstant,					//10. ground absorption constant
    		float groundHeight								//11. height of the ground (y position)
    		) : Simulation(numOfMasses, m)					//The super class creates masses with weights m of each
    	{
    		this->gravitation = gravitation;
    
    		this->airFrictionConstant = airFrictionConstant;
    
    		this->groundFrictionConstant = groundFrictionConstant;
    		this->groundRepulsionConstant = groundRepulsionConstant;
    		this->groundAbsorptionConstant = groundAbsorptionConstant;
    		this->groundHeight = groundHeight;
    
    		for (int a = 0; a < numOfMasses; ++a)			//To set the initial positions of masses loop with for(;;)
    		{
    			masses[a]->pos.x = a * springLength;		//Set x position of masses[a] with springLength distance to its neighbor
    			masses[a]->pos.y = 0;						//Set y position as 0 so that it stand horizontal with respect to the ground
    			masses[a]->pos.z = 0;						//Set z position as 0 so that it looks simple
    		}
    
    		springs = new Spring*[numOfMasses - 1];			//create [numOfMasses - 1] pointers for springs
    														//([numOfMasses - 1] springs are necessary for numOfMasses)
    
    		for (int a = 0; a < numOfMasses - 1; ++a)			//to create each spring, start a loop
    		{
    			//Create the spring with index "a" by the mass with index "a" and another mass with index "a + 1".
    			springs[a] = new Spring(masses[a], masses[a + 1], 
    				springConstant, springLength, springFrictionConstant);
    		}
    	}
    
    	void release()										//release() is overriden because we have springs to delete
    	{
    		Simulation::release();							//Have the super class release itself
    
    		for (int a = 0; a < numOfMasses - 1; ++a)		//to delete all springs, start a loop
    		{
    			delete(springs[a]);
    			springs[a] = NULL;
    		}
    
    		delete(springs);
    		springs = NULL;
    	}
    
    	void solve()										//solve() is overriden because we have forces to be applied
    	{
    		for (int a = 0; a < numOfMasses - 1; ++a)		//apply force of all springs
    		{
    			springs[a]->solve();						//Spring with index "a" should apply its force
    		}
    
    		for (int a = 0; a < numOfMasses; ++a)				//Start a loop to apply forces which are common for all masses
    		{
    			masses[a]->applyForce(gravitation * masses[a]->m);				//The gravitational force
    
    			masses[a]->applyForce(-masses[a]->vel * airFrictionConstant);	//The air friction
    
    			if (masses[a]->pos.y < groundHeight)		//Forces from the ground are applied if a mass collides with the ground
    			{
    				Vector3D v;								//A temporary Vector3D
    
    				v = masses[a]->vel;						//get the velocity
    				v.y = 0;								//omit the velocity component in y direction
    
    				//The velocity in y direction is omited because we will apply a friction force to create 
    				//a sliding effect. Sliding is parallel to the ground. Velocity in y direction will be used
    				//in the absorption effect.
    				masses[a]->applyForce(-v * groundFrictionConstant);		//ground friction force is applied
    
    				v = masses[a]->vel;						//get the velocity
    				v.x = 0;								//omit the x and z components of the velocity
    				v.z = 0;								//we will use v in the absorption effect
    
    				//above, we obtained a velocity which is vertical to the ground and it will be used in 
    				//the absorption force
    
    				if (v.y < 0)							//let's absorb energy only when a mass collides towards the ground
    					masses[a]->applyForce(-v * groundAbsorptionConstant);		//the absorption force is applied
    
    				//The ground shall repel a mass like a spring. 
    				//By "Vector3D(0, groundRepulsionConstant, 0)" we create a vector in the plane normal direction 
    				//with a magnitude of groundRepulsionConstant.
    				//By (groundHeight - masses[a]->pos.y) we repel a mass as much as it crashes into the ground.
    				Vector3D force = Vector3D(0, groundRepulsionConstant, 0) * 
    					(groundHeight - masses[a]->pos.y);
    
    				masses[a]->applyForce(force);			//The ground repulsion force is applied
    			}
    
    		}
    
    	}
    
    	void simulate(float dt)								//simulate(float dt) is overriden because we want to simulate 
    														//the motion of the ropeConnectionPos
    	{
    		Simulation::simulate(dt);						//the super class shall simulate the masses
    
    		ropeConnectionPos += ropeConnectionVel * dt;	//iterate the positon of ropeConnectionPos
    
    		if (ropeConnectionPos.y < groundHeight)			//ropeConnectionPos shall not go under the ground
    		{
    			ropeConnectionPos.y = groundHeight;
    			ropeConnectionVel.y = 0;
    		}
    
    		masses[0]->pos = ropeConnectionPos;				//mass with index "0" shall position at ropeConnectionPos
    		masses[0]->vel = ropeConnectionVel;				//the mass's velocity is set to be equal to ropeConnectionVel
    	}
    
    	void setRopeConnectionVel(Vector3D ropeConnectionVel)	//the method to set ropeConnectionVel
    	{
    		this->ropeConnectionVel = ropeConnectionVel;
    	}
    
    };
    


  • 😃 😃 😃 👍



  • L 😃 L



  • 😃 😃 😃
    Tja, was soll man dazu noch sagen?
    Da hat er alles, was er wollte. Sogar mit kommentiertem Quelltext.
    Auf jeden Fall funktionierts! 👍



  • Jochen S. schrieb:

    😃 😃 😃
    Tja, was soll man dazu noch sagen?
    Da hat er alles, was er wollte. Sogar mit kommentiertem Quelltext.
    Auf jeden Fall funktionierts! 👍

    Aber bei ihm dann wieder nicht. Erklär du ihm ruhig, wie er das SDK "in sein C++ reinkriegt". 😃 😉



  • Ich brauchte kein SDK. Ich hab das mit dem Borland C++ Compiler 5.5 kompiliert. Ich hab nur das #include <condefs> auskommentiert und das USEUNIT weggemacht. Dann ging es. Anscheinend war das SDK schon irgendwie dabei.



  • Aber die Schritte die du eben erwähnt hast kann nicht jeder der schon 3 C++-Bücher durchgearbeitet hat. 😃



  • hey danke aber ich hab noch ein älteres Buch gelesen das hat mir gut weiter geholfen des heißst C++ programmierung lernen kann ich nur empfehlen von André Willms echt gut

    und befohr ihr nochmal was schlechtes über mich sagt muss ich mich bedanken für eure mühen und eigentlich seid ihr echt inordnung



  • kaum hat man problem 1 gelöst kommt das zweite mhh..

    naja ich wollte das mann vor einer wahl steht bsp:

    möchtest du was kaufen? (ja\nein)
    (wenn mann jetzst nein sagt sollte ein anderer text kommen als ja das geht ja über if aber egal was ich eingebe es kommt immer das nächst angegebene cout im queltext was mach ich da?)

    naja hoffentlich kann mir einer helfen ohne zu sagen das ich doch nichts gelernt hätte

    über switch gehts auch net



  • Schön das du nicht aufgibst und dir nochmal die Grundlagen anschaust 👍

    Poste doch mal dein Beispiel, ich bin sicher wir finden den Fehler gemeinsam.

    Gruß Blue-Tec



  • Ja, ein bisschen Code wäre nicht schlecht.
    Aber eventuell machst du ja einen der folgenden Fehler:

    - Semikolon hinter der If-Abfrage
    - Groß/Kleinschreibung nicht beachtet
    - anstatt == nur = geschruieben

    Das wären jetzt die häufigsten Fehler, aber ohne Code kann ich da auch nur raten.
    Kleine Anmerkung am Rande: Eigentlich könnte der Thread jetzt ins C++ - Forum verschoben werden. Da dürfte es mehr Leute geben, die sich das ansehen.

    MfG, Jochen



  • sorry hab den quellcode i-wie verloren auf meinen rechner find ich ihn nimmer naja ich wollte fürs erste nur zur übung eine art text abenteuer machen nur mit if oder vil. auch mit switch naja aber i-wie klappt es nicht wenn ich den quellcode neu geschrieben hab dan schreib ich`s mal hier rein fürs erste mal ne pause ich büffel mal ein paar bücher übers tehma und ist es eigenlich ein großer aufwand ein bild in die konsole einzufügen oder so damits wenigstens so aussieht?????



  • Eigentlich ist das kein großer Aufwand, ein Bild in der Konsole darzustellen, allerdings ist die Konsole nicht wirklich dafür geeignet. Falls es dich interessiert, hier ist ein Quelltext:

    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    int main()
    {     
        HBITMAP hBitmap = (HBITMAP)LoadImage(NULL,"Bitmap.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);  
        BITMAP bmp; 
        GetObject(hBitmap,sizeof(bmp),&bmp);  
        HWND hwnd = FindWindow("ConsoleWindowClass",NULL); 
        HDC hDC = GetDC(hwnd);    
        HDC hBitmapDC = CreateCompatibleDC(hDC);   
        SelectObject(hBitmapDC,hBitmap);    
        BitBlt(hDC,0,0,400,200,hBitmapDC,0,0,SRCCOPY);    
        DeleteObject(hBitmap);  
        ReleaseDC(hwnd,hBitmapDC);  
        ReleaseDC(hwnd,hDC); 
        getchar();
        return 0; 
    }
    

    Das Programm öffnet die bitmap "Bitmap.bmp" (muss sich in dem selben Ordner befinden, in dem sich auch das Programm befindet) und zeichnet den Inhalt der Bitmap von 0 - 400 Pixeln auf der x-achse und von 0 - 200 Pixeln auf der y-Achse An die Stelle 0/0 im Konsolenfenster. Zum Testen empfehle ich dir, eine Bitmap der Größe 400x200 zu erstellen und diese dann irgendwie auszumalen.
    Dieses Programm funktioniert nicht im Vollbildmodus. Auch wirst du merken, dass das Bild sehr leicht "kaputt" geht. (Beispielsweise durch Minimieren des Fensters).

    MfG, Jochen.



  • tja ich hab zwar den quell code nochmal "angefangen" aber jetzt hat er glaub ich ein problem mit windows

    das is der code:

    #include <cstdlib>
    #include <iostream>
    #include <string>

    using namespace std;

    int main()
    {
    string vorgeschichte, verstecken, warten;

    cout <<"Wo bin ich?? Was mach ich hier?? Ploetzlich ein Geraeusch!!(verstecken/warten)" << endl;
    cin >> vorgeschichte;
    cout <<"Schnell verstecke ich mich aber wo??(schrank/vorhang)?"
    cin >> verstecken;
    cout <<"Ich warte ab! Dann kommt ein schräg futuristischer auber witziger Kerl auf mich zu(wegrennen/reden)?" << endl;
    cin >> warten;

    if (vorgeschichte == "verstecken")
    {
    cin >> verstecken;
    system("CLS");
    }

    if (vorgeschichte == "warten")
    {
    cin >> warten;
    system("CLS");
    }

    system("PAUSE");
    return EXIT_SUCCESS;
    }

    und hier der compiler fehler

    C:\Dev-Cpp\Makefile.win [Build Error] [übung.o] Error 1


Anmelden zum Antworten