Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

DarkHunter

just a quick thing...

This topic is 6016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ok i was updating my old screensavor for my old teacher, and i added a feature, letting the hypercube go in and out (on the Z plain), you konw, go in and out. And when it does that, i found a small formula to calculate when the hypercube hits the edges. -23/75x x being the zoom its at. and that would be the edge.
  
	xma = zoomf * (-23/75);
	yma = zoomf * (-16/75);
	

	if ((xm) <= (xma) || (xm) >= -(xma) )
		{
		xmoveb = !xmoveb;
		}
	if ((ym) <= (yma) || (ym) >= -(yma) )
		{
		ymoveb = !ymoveb;
		}
  
i know i didn''t need to add xma and yma, i was just trying new things, and it wont work!!! remember zoomf = a NEGATIVE number, so that should work?? RIGHT???? but instead, my hypercube goign in and out of this small lil area, giving a shaking affect, which i hate. xmoveb and ymoveb are bool variables to show which direction they are goin on the x and y axis

Share this post


Link to post
Share on other sites
Advertisement
  
I think this might help...

screen_width = zdist * tan(22.5) * 2;
screen_height = zdist * tan(22.5) * 3/2;

___________
\ | /
\ | /
\ | /
\ | /
\|/
.

It's all trig, the dot is the view point and as long as the OpenGl angle used in you ReSizeGlWindow function is 45.0f then you have this...


_______________
| width/2 /
|z /
|d /
|i /
|s /
|t /
| /
| /
| /
| /
| /
| /
| /
|/ 45/2 degrees


and that should be it...
hope that helps...


Edited by - Shadow_0f_Light on February 21, 2002 5:31:05 AM

Share this post


Link to post
Share on other sites
took me a while to answer back, but here is what i have, and nothing is working!! sombody else compile see if you can figure out what i did wrong. And check the mistake...

  
#include <windows.h>
#include <math.h>
#define WIN32_LEAN_AND_MEAN
#include <scrnsave.h>
#include <time.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include "resource.h"

GLfloat xmax = -23/75;
GLfloat ymax = -16/75;

HGLRC hRC;
HDC hDC;
HPALETTE hPalette;
HWND hwnd;

UINT nTimerID = 101;

bool keys[256];
bool direction=TRUE;
bool xmoveb = true;
bool ymoveb = true;
bool zom = true;
bool color = true;
bool oadd;
GLfloat screen_height;
GLfloat screen_width;
GLfloat oedgef = 2.0;
GLfloat iedgef = 0.5;
GLfloat xrot;
GLfloat yrot;
GLfloat zrot;
GLfloat xm;
GLfloat ym;
GLfloat speed = 0.03f;
GLfloat zoom = -20.0;
GLfloat xmover = .6;
GLfloat ymover = .4;
GLfloat zmover = .2;
GLfloat xmove = .2;
GLfloat ymove = .3;
GLfloat zmove = .5;

void glInit()
{
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
}

void glRender()
{
if (color == true)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(xm,ym,zoom);
glRotatef(xrot,1.0f,0.0f,0.0f);
glRotatef(yrot,0.0f,1.0f,0.0f);
glBegin(GL_QUADS);
glColor3f(1.0f,0.0f,0.0f);

glVertex3f( iedgef, iedgef,-iedgef);
glVertex3f(-iedgef, iedgef,-iedgef);
glVertex3f(-oedgef, oedgef,-oedgef);
glVertex3f( oedgef, oedgef,-oedgef);
glVertex3f(-iedgef, iedgef, iedgef);
glVertex3f( iedgef, iedgef, iedgef);
glVertex3f( oedgef, oedgef, oedgef);
glVertex3f(-oedgef, oedgef, oedgef);
glVertex3f( iedgef,-iedgef, iedgef);
glVertex3f(-iedgef,-iedgef, iedgef);
glVertex3f(-oedgef,-oedgef, oedgef);
glVertex3f( oedgef,-oedgef, oedgef);
glVertex3f(-iedgef,-iedgef,-iedgef);
glVertex3f( iedgef,-iedgef,-iedgef);
glVertex3f( oedgef,-oedgef,-oedgef);
glVertex3f(-oedgef,-oedgef,-oedgef);
glColor3f(0.0f,0.0f,1.0f);
glEnd();
}

else
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer

glLoadIdentity();
glTranslatef(xm,ym,zoom);
glColor3f(1.0f,1.0f,1.0f);
glRotatef(xrot,1.0f,0.0f,0.0f);
glRotatef(yrot,0.0f,1.0f,0.0f);
}

glBegin(GL_QUADS);
glVertex3f( iedgef, iedgef,-iedgef);// Top Right Of The Quad (Top)

glVertex3f(-iedgef, iedgef,-iedgef);// Top Left Of The Quad (Top)

glVertex3f(-iedgef, iedgef, iedgef);// Bottom Left Of The Quad (Top)

glVertex3f( iedgef, iedgef, iedgef);// Bottom Right Of The Quad (Top)

glVertex3f( iedgef,-iedgef, iedgef);// Top Left Of The Quad (Bottom)

glVertex3f(-iedgef,-iedgef, iedgef);// Top Right Of The Quad (Bottom)

glVertex3f(-iedgef,-iedgef,-iedgef);// Bottom Left Of The Quad (Bottom)

glVertex3f( iedgef,-iedgef,-iedgef);// Bottom Right Of The Quad (Bottom)

glVertex3f( iedgef, iedgef, iedgef);// Top Right Of The Quad (Front)

glVertex3f(-iedgef, iedgef, iedgef);// Top Left Of The Quad (Front)

glVertex3f(-iedgef,-iedgef, iedgef);// Bottom Left Of The Quad (Front)

glVertex3f( iedgef,-iedgef, iedgef);// Bottom Right Of The Quad (Front)

glVertex3f( iedgef,-iedgef,-iedgef);// Top Right Of The Quad (Back)

glVertex3f(-iedgef,-iedgef,-iedgef);// Top Left Of The Quad (Back)

glVertex3f(-iedgef, iedgef,-iedgef);// Bottom Left Of The Quad (Back)

glVertex3f( iedgef, iedgef,-iedgef);// Bottom Right Of The Quad (Back)

glVertex3f(-iedgef, iedgef, iedgef);// Top Right Of The Quad (Left)

glVertex3f(-iedgef, iedgef,-iedgef);// Top Left Of The Quad (Left)

glVertex3f(-iedgef,-iedgef,-iedgef);// Bottom Left Of The Quad (Left)

glVertex3f(-iedgef,-iedgef, iedgef);// Bottom Right Of The Quad (Left)

glVertex3f( iedgef, iedgef,-iedgef);// Top Right Of The Quad (Right)

glVertex3f( iedgef, iedgef, iedgef);// Top Left Of The Quad (Right)

glVertex3f( iedgef,-iedgef, iedgef);// Bottom Left Of The Quad (Right)

glVertex3f( iedgef,-iedgef,-iedgef);// Bottom Right Of The Quad (Right)


glColor3f(0.0f,1.0f,0.0f);
glVertex3f( oedgef, oedgef,-oedgef);// Top Right Of The Quad (Top)

glVertex3f(-oedgef, oedgef,-oedgef);// Top Left Of The Quad (Top)

glVertex3f(-oedgef, oedgef, oedgef);// Bottom Left Of The Quad (Top)

glVertex3f( oedgef, oedgef, oedgef);// Bottom Right Of The Quad (Top)

glVertex3f( oedgef,-oedgef, oedgef);// Top Left Of The Quad (Bottom)

glVertex3f(-oedgef,-oedgef, oedgef);// Top Right Of The Quad (Bottom)

glVertex3f(-oedgef,-oedgef,-oedgef);// Bottom Left Of The Quad (Bottom)

glVertex3f( oedgef,-oedgef,-oedgef);// Bottom Right Of The Quad (Bottom)

glVertex3f( oedgef, oedgef, oedgef);// Top Right Of The Quad (Front)

glVertex3f(-oedgef, oedgef, oedgef);// Top Left Of The Quad (Front)

glVertex3f(-oedgef,-oedgef, oedgef);// Bottom Left Of The Quad (Front)

glVertex3f( oedgef,-oedgef, oedgef);// Bottom Right Of The Quad (Front)

glVertex3f( oedgef,-oedgef,-oedgef);// Top Right Of The Quad (Back)

glVertex3f(-oedgef,-oedgef,-oedgef);// Top Left Of The Quad (Back)

glVertex3f(-oedgef, oedgef,-oedgef);// Bottom Left Of The Quad (Back)

glVertex3f( oedgef, oedgef,-oedgef);// Bottom Right Of The Quad (Back)

glVertex3f(-oedgef, oedgef, oedgef);// Top Right Of The Quad (Left)

glVertex3f(-oedgef, oedgef,-oedgef);// Top Left Of The Quad (Left)

glVertex3f(-oedgef,-oedgef,-oedgef);// Bottom Left Of The Quad (Left)

glVertex3f(-oedgef,-oedgef, oedgef);// Bottom Right Of The Quad (Left)

glVertex3f( oedgef, oedgef,-oedgef);// Top Right Of The Quad (Right)

glVertex3f( oedgef, oedgef, oedgef);// Top Left Of The Quad (Right)

glVertex3f( oedgef,-oedgef, oedgef);// Bottom Left Of The Quad (Right)

glVertex3f( oedgef,-oedgef,-oedgef);// Bottom Right Of The Quad (Right)

glEnd();

glFlush();
if (oedgef >= 2.0)
{
direction = true;
}
if(oedgef <= 0.5)
{
direction = false;
}
if (direction == true)
{
oedgef-=speed;
iedgef+=speed;
}
if (direction == false)
{
oedgef+=speed;
iedgef-=speed;
}
if (xmoveb == true)
{
xm += xmove;
}
if (xmoveb == false)
{
xm -= xmove;
}
if (ymoveb == true)
{
ym += ymove;
}
if (ymoveb == false)
{
ym -= ymove;
}
if (zom == true)
{
zoom += zmove;
}
if (zom == false)
{
zoom -= zmove;
}

xrot += xmover;
yrot += ymover;
zrot += zmover;

screen_width = zoom * tan(22.5) * 2;
screen_height = zoom * tan(22.5) * 3/2;

if ( xm > screen_height || xm < -screen_height)
{
xmoveb = !xmoveb;
}
if ( ym > screen_width || ym < -screen_width)
{
ymoveb = !ymoveb;
}
if ( zoom >= -10.0 || zoom <= -50.0)
{
zom = !zom;
}

}

void glResize(int w, int h)
{
if (h==0)
{
h=1;
}
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

LRESULT WINAPI ScreenSaverChildProc(HWND hWnd,UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
static BOOL bInited = FALSE;
int nPixelFormat;

static PIXELFORMATDESCRIPTOR pfd = {sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER | PFD_DEPTH_DONTCARE, PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
0,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0};

switch(message)
{
case WM_CREATE:
hDC = GetDC(hWnd);
nPixelFormat = ChoosePixelFormat(hDC, &pfd);
SetPixelFormat(hDC, nPixelFormat, &pfd);
DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC,hRC);
glInit();
SetTimer(hWnd, nTimerID,33,NULL);
break;

case WM_DESTROY:
KillTimer(hWnd, nTimerID);
wglMakeCurrent(hDC, NULL);
wglDeleteContext(hRC);
ReleaseDC(hWnd,hDC);
PostQuitMessage(0);
break;

case WM_TIMER:
InvalidateRect(hWnd, NULL, FALSE);
break;

case WM_ERASEBKGND:
return 1;
break;

case WM_SIZE:
glResize(LOWORD(lParam), HIWORD(lParam));
break;

case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
glRender();
SwapBuffers(hDC);
EndPaint(hWnd, &ps);
break;

case WM_KEYDOWN:
keys[wParam] = TRUE;
break;
case WM_KEYUP:
keys[wParam] = FALSE;
break;

case WM_SYSCOMMAND:
case WM_SETCURSOR:
case WM_NCACTIVATE:
case WM_ACTIVATE:
case WM_ACTIVATEAPP:
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
// retVal = DefScreenSaverProc(hWnd, message, wParam, lParam);

// DefScreenSaverProc(hMainWindow, message, wParam, lParam);

// return retVal;

// break;

case WM_MOUSEMOVE://i don''t want this event to kill the screensaver..

break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

LRESULT WINAPI ScreenSaverProc(HWND hWnd,UINT message, WPARAM wParam, LPARAM lParam)
{
hwnd = hWnd;
static HWND hChild = NULL;
HINSTANCE hInst = hMainInstance;
int nMaxX = 0;
int nMaxY = 0;
int nWndSize = 0;
switch(message)
{
case WM_CREATE:
{
WNDCLASS wc;

wc.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC ;
wc.lpfnWndProc = (WNDPROC) ScreenSaverChildProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "NTDEVCLASS";

RegisterClass(&wc);

if(nMaxX == 0)
{
RECT rect;
GetClientRect(hWnd,&rect);
HDC hdc;
hdc = GetDC(hWnd);
nMaxX = rect.right;
nMaxY = rect.bottom;
nWndSize = (int) ((float)nMaxY* .35f);
::ReleaseDC(hWnd,hdc);
}

hChild = CreateWindow( wc.lpszClassName,
"Child1",
WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
0, 0,
nMaxX,nMaxY,
hWnd,
NULL,
hInst,
NULL);
}
break;

case WM_DESTROY:
KillTimer(hWnd, nTimerID);
DestroyWindow(hChild);
PostQuitMessage(0);
break;

case WM_TIMER:
break;

default:
return DefScreenSaverProc(hWnd, message, wParam, lParam);
}
return 0;
}

BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_COMMAND:

switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hDlg, TRUE);
break;
default:
break;
}
default:
break;
}
return 0;
}

BOOL WINAPI RegisterDialogClasses(HANDLE hInst)
{
return TRUE;
}


one more problem i am having, is i want the x,y,z and speed of the ''hyper rotation'' to be user set. Remember this is a ss, so i dont know how to do that!!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!