jump to navigation

Why must implement Object.Hashcode along with Object.Equals October 26, 2009

Posted by metalickl in Software Insights.
Tags: ,
add a comment

I’ve heard of this advice over and over from various sources, and never been able to fully understand why. Until recently (few weeks ago), I was working with various java.util.Collection classes, there were a few connection made relating to this.

Whenever you get an Objects from hash based collections, such as HashMap, with a String or Integer key, you could simply say map.get(“key”) or map.get(new String(“key”)). This is because Strings or Integers are logical equivalent, which is a greater set than traditional identity equivalence (==). This allows greater flexibility to retrieve stored content from our little hash locker by playing the Keymaker, and constructing a key that is identical to the original one (in our case, a new String with the same characters).

But you cannot do this with entity objects. By default implementation, their Object.equals(Object o) simply returns this==o. This means you can never retrieve the stored content with any other object beside the one you’ve used in Map.put(Object key, Object value).

Hash based collections simply uses the hash code to identify a smaller, refined group of stored objects from the larger collection. If you’ve modified Object.equals to allow both identity and logical equivalence, but not Object.hashcode. Then try to search the collection with the logically equivalent key (same colour, same groove, but just not the key you’ve used the first time!), then obviously the hash based collection, who relies only on Object.hashcode to refine the search will have no idea that this Type is also logically equivalent. In this case, its attempt to refine the collection fails with false precondition.

—–

May be off topic, but then you would think an easy way to implement equals (for both identity and logical equivalence) along with hashcode would be simply compare the string representation of the 2 Objects (including instance members in some way or the other) and just output the hashcode of the string representation of the Object. This saves you the time (mostly brain power) to implement the non-trivial hash functions. This is acceptable, but not performance efficient or easy to read.

This is why it’s always nice to override Object.toString() ;)

—–

Btw, Object serialization does preserve identity equivalence, IF:

  1. Both a and b are written as and subsequently read from as parts of the same stream. Here’s a quote from ObjectInputStream documentation: “Graphs of objects are restored correctly using a reference sharing mechanism.”
  2. Class of a and b does not override readResolve() that has the potential of changing how references are restored back; neither do classes that hold a and b.

For all other cases, object identity will NOT be preserved.

A fresh start October 18, 2009

Posted by metalickl in Life.
add a comment

Haven’t been blogging at all for the past two years. Time for a fresh start. So much have changed and it’s also a time to change the focus of the blog. I will be posting more interesting things in software engineering and music.

Next iPhone update could leave you with an iBrick September 24, 2007

Posted by metalickl in Gadegets Insights, Hardware Insights, PDA and Mobile Insights.
2 comments

Apple: Next iPhone update could break unlocked phones

Apple issued a statement Monday afternoon warning users of unlocked iPhones that the next software update it ships will probably break their phones.

It’s not clear how many people have unlocked their iPhone to run on networks other than AT&T’s, but there has definitely been some interest among early adopters who want no part of AT&T’s network. Most of those folks were always operating under the assumption that Apple might relock their iPhones with future software updates, but were they expecting Apple to actually disable the phone?

Hacked your iPhone? The next software update from Apple could break your phone.

(Credit: CNET Networks)

“Apple has discovered that many of the unauthorized iPhone unlocking programs available on the Internet cause irreparable damage to the iPhone’s software, which will likely result in the modified iPhone becoming permanently inoperable when a future Apple-supplied iPhone software update is installed,” the company said in a statement issued after the close of the stock market. “Apple strongly discourages users from installing unauthorized unlocking programs on their iPhones. Users who make unauthorized modifications to the software on their iPhone violate their iPhone software license agreement and void their warranty. The permanent inability to use an iPhone due to installing unlocking software is not covered under the iPhone’s warranty.”

This is not going to sit well with the fringe early adopter who, having already suffered through the price cut debacle, now faces the prospect of a dead iPhone. The probable solution, as discussed earlier today by our new friends at iPhone Atlas, involves restoring the iPhone to the factory default settings before installing the new update. The next update will be released later this week to allow iPhone owners to access the new Wi-Fi Music Store introduced earlier this month.

That assumes, I guess, that the iPhone hackers will probably find some way around the new update next week, and that’s probably not that much of a stretch. But it seems Apple is hell-bent on making sure too many people don’t make unauthorized modifications to its iBaby, which in some ways, makes sense to me. This is a brand new product, and even Apple may not totally be aware of the problems that could arise from willy-nilly hacking.

So, be forewarned: if you hacked your iPhone, you might want to hold off on installing this week’s update unless you’re willing to go back to using AT&T’s network.

Update: The Unofficial Apple Weblog thinks that doing a factory restore might not be enough to reverse the unlocking process. They’ve posted a detailed, step-by-step process for “re-locking” your iPhone that might make you wince unless you’re handy with code. Check it out here, but TUAW warns this is still in the early testing stages.

from cnet news: http://www.news.com/8301-13579_3-9783713-37.html

Microsoft offers downgrade from Vista to XP September 22, 2007

Posted by metalickl in Software Insights, Software Insights@Windows Vista.
add a comment

It’s no shock that Windows Vista isn’t, shall we say, universally loved, and it’s also unsurprising that a plethora of businesses have voiced their preference to keep on runnin’ their operations on Windows XP. Presumably in response, Microsoft is “quietly allowing PC makers to offer a downgrade option to buyers that get machines with the new operating system but want to switch to Windows XP,” but the program only applies to Vista Business and Ultimate editions. The likes of Fujitsu, HP, Lenovo and Dell all have processes in place to ensure that customers have the ability to downgrade if they so choose, and while some firms are still selling their PCs with XP pre-installed, debates are already swirling around how long that tactic can remain in place.

Microsoft presents source code to China August 9, 2007

Posted by metalickl in IT Industries.
add a comment

From ChinaTechNews.com:

Microsoft (MSFT) has announced further plans to open Vista source code in China.

Microsoft has reportedly signed a new government security program source code agreement with China Information Technology Security Certification Center, allowing CNITSEC and other approved institutions to look over the source code and relevant technical data of Microsoft’s products, including Windows Vista, Windows XP, Office, Windows CE and etcetera, so as to improve their evaluation on the security of Microsoft products. The agreement is an important part of the MOU signed between National Development and Reform Commission and Microsoft in April 2006.

Microsoft’s Government Security Program helps government departments and international organizations evaluate the security of Microsoft products. CNITSEC previously signed an agreement with Microsoft on security source code in February 2003 and was authorized to check over the company’s major source code and technical data.

Microsoft’s move should bring good results in the promotion of information and enhancement of mutual trust between China and the United States

 ——

From CCTV.cn

本报北京8月7日电(记者杨谷)微软操作系统的安全性一直受到怀疑。日前,微软公司和我有关机构签约,将新款操作系统视窗Vista等软件的源代码提供给我国查看。    根据微软与中国信息安全产品测评认证中心签署的新一期政府安全计划源代码协议,中国信息安全产品测评认证中心和相关被授权机构可以查

看包括视窗Vista、视窗XP、Office2003、视窗CE等软件的源代码及相关技术信息,从而提高对微软产品的安全分析和测评能力。上一期的政府安全计划源代码协议签署于2003年,随着微软产品的不断更新换代,双方决定签署新一期的政府安全计划源代码协议。

    微软的各种软件在我国拥有广大的用户,不少关键部门采用了微软产品作为信息系统的核心,因此其安全性备受关注。中国信息安全产品测评认证中心主任王海生表示,今后将加深对微软产品安全性的了解和研究分析,不断提高有效控制安全风险的能力,履行“信息海关”的职责。

——————————

E-Insight, 2007

Norwegian hacker crack iPhone just one week after its release July 6, 2007

Posted by metalickl in Gadegets Insights, IT Industries, PDA and Mobile Insights, Software Insights.
add a comment

According to a post on his blog, a well-known Norwegian hacker has figured out a way to bypass restrictions on the iPhone that forces people to activate on the AT&T network. Now the iPhone might be worth buying.Digital Journal — Jon Lech Johansen, a 23-year-old famous for his hacking of consumer electronics, says he has cracked the iPhone. In a post on his blog on July 3 (titled “iPhone Independence Day”), Johansen said: “I’ve found a way to activate a brand new unactivated iPhone without giving any of your money or personal information to AT&T NSA. The iPhone does not have phone capability, but the iPod and WiFi work. Stay tuned!”

Johansen’s blog, titled “So Sue Me” provides source code and software for hackers to activate an iPhone for iPod+WiFi use.

Hackers and coders have been working around the clock to crack the iPhone’s security restrictions since its launch a week ago.Apple is in a long-term contract with AT&T, meaning anyone who wants an iPhone must activate it through the wireless carrier.

Mark Siegel, a spokesman for AT&T said it was “necessary” to activate the iPhone on his company’s network to “ensure optimum performance.”

Despite what AT&T’s spin doctors have said, anyone in the tech world knows the wireless provider has what can only be described as a horribly slow Edge network, and many Apple fans want to use the phone without activating on AT&T.

The hack is important for an iPhone owner who wants to travel abroad and use the Internet or the phone’s music without having to pay AT&T to activate the phone.

As hackers continue to dig through code, cracks will also (likely) eventually lead to a way for the iPhone to work on another network. The phone comes locked, and a crack is (of course) against AT&T and Apple’s contract.

No doubt, few crackers actually care about that.

Johansen is practically a god in the underground tech world, most well-known as “DVD Jon” for reversing the code on DVDs that protect them from being pirated.

On his blog, Johansen warns the “application will not do anything unless you understand the magic numbers as well as add the hosts entry,” and you will need software installed on your computer. 

by Christopher Hogg

——————————

E-Insight, 2007

sometimes i feel like a great chef July 5, 2007

Posted by metalickl in IT Industries.
add a comment

sometimes i feel like a great chef by F.S.J. (Fake Steve Jobs)

sometimes i feel like a great chef
who has devoted his entire life
to monastic study of the art of cooking
& gathered the finest ingredients
& built the most advanced kitchen
& prepared the most exquisite meal
so perfect so delicious so extraordinary
more astounding than any meal ever created
yet each day i stand in my window
& watch ninety-seven percent of the world
walk past my restaurant
into the mcdonald’s
across the street.

——————————

E-Insight, 2007

Install a Mac OS X Tiger on your PC June 28, 2007

Posted by metalickl in Software Insights.
1 comment so far

How to install a Mac OS X Tiger on your own PC, originally by vinceqz

Here my man installed Mac OS X 10.4.8 on one of his notebooks. It’s actually quite simple when you doing it, you only need a dvd and computer. haha

Well if you want duo system (install OS X in addition to your xp), just make an additional drive, 15G should be enough. If you want single system, you can install straight away.

check for hardware compatiability: http://wiki.osx86project.org/wiki/index.php/Main_Page

First step: the most important step… Download Mac OS X JaS 10.4.8 AMD Intel. You can find the file through eMule or BT, here is a link to the seed for BT: http://www.sendspace.com/file/lpt3jg

Good, now burn a dvd from the image file you’ve just downloaded.

Now, for duo system users. You should do a disc partition, an application called Partition Magic, or Acronis disk Director Suite 10 should do the trick. But remember, the disc format for the OS X must be “FAT 32 LogicalnotNTF“, remember!!! After you install the system, you then need to change “FAT 32 Logical” to “FAT 32 Primary“, remember!!! SO that OS X can start properly.

put the dvd into computer, restart and you will see…





here you select the language, you can choose chinese.
 
 
 
After choosing which driver you will install OS X, e.g. D:\ or E:\, you will be asked to format the disc into Mac OS Extended (Journled)
 
 
 
Very simple.
 
 
 
If you have Intel CPU, choose the file for Intel CPU!!!!!

 
Skip…
 
 

The total instalation time is about 30 minutes or so, you can rest aside and listen to some music or watch some tv.
 
 
 
 
 
 
 
 
 
Haha, you are done. Here is a comparison with MacBook pro.
 
 
 
 
 
 
 
 
 

——————————

E-Insight, 2007

Things to look for when select a cellphone June 27, 2007

Posted by metalickl in Gadegets Insights, PDA and Mobile Insights.
1 comment so far

Things to look for when select a cellphone

Many of you will be going on holidays overseas this summer, and consider buying a cellphone, digital camera, mp4 and etcetera. Here I would give you some suggestions in picking a cell phone, as the last gift I can give you before we say goodbye.

The integration of camera, mp3 into cellphone is almost an inevitable procedure of any phone behind the glass display case. Sony Ericsson has just released w610i is one of the delegates of these popular walkman/digital cam phones, though it is not the type of phones I would select.

For professionals, businessmen, many of the functions such as push-email from the highly successful Blackberry, schedule/calendar, notepad, internet and etcetera are equally important to entertainment functions. PDA (personal digital assistants), those that lack the function of mobile phone, but would serve all the above needs are dying out. The future belongs to the decedents of PDA’s, which combines the functions of pocket pc and mobile phone. Such phones are called Smartphones. The obvious choice comes to mind would be an iPhone, which is coming out in just 4 days (June 29th). Other choices includes Blackberry phones, the latest is Blackberry 8300 (Curve), but slightly too expensive both to purchase and to maintain (the service that is).

 Windows Mobile 6 Symbian Blackberry

The secret to Smartphones’ power lies within its integrated firmware, which includes an OS (operation system); so that one can update its software at convenience, e.g. install/uninstall softwares, games. You can do absolutely anything you do on a computer, read pdf books, listen to mp3’s, watch optimized movie clips, play games and ectcetera.

 FExploerer on Symbian Smartmovie on Symbian

Some popular phones, like Nokia 3250, an excellent smartphone with Symbian 9.0 has a problem that dust can get inside the space under the glass screen. Motorola also have some great phones, the new Razr looks slick, but the drawback is its short battery duration and it’s not a smartphone so that you are limited in installing applications. Some additional aspects you should look out for is that the phone should be at least tri-band or quad-band GSM phone, it specifies the frequency it supports so that it will work in Canada. Other things I would personally look in a phone are the size of its screen, talking time, wifi/Bluetooth support, battery duration (this is most important), signal and its ability to resist dust/water/impact.   

Long story short, buy a phone, buy a smartphone. If the phone was a man, than its OS (symbian/Microsoft/linux) is its brain so that it can accept new applications that would serve other purposes than a simple mobile phone. The screen is its face and the battery duration whos how long it lasts without sleep, haha. Good luck finding your phone.

——————————

E-Insight, 2007

How to setup OpenGL in Win32 environment June 3, 2007

Posted by metalickl in Software Insights.
2 comments

How to setup OpenGL in Win32 environment

Because of different computer games have different qualifications in terms of graphics, compatibility, hardware and operation, so their programming are done differently, especially there is quite a few distinctive platforms and different companies also have their own preferences. Some popular platforms are Microsoft’s XBOX, Sony’s PlayStation, Nitendo’s Wii etcetera. When you want to play a specific game, you need to know which platform it runs on. For example, you need to own a Playstation to play its games.

There is one more platform, perhaps the most well known of all, is PC. Although the performance of PC is not as superb as those specialized gaming platforms, it still holds a great market share in gaming entertainment. Most of PC is based on Win32, and runs Windows. Many popular PC games are developed with DirectX because it is introduced by Microsoft and contains all the graphic displays, operations and controls. If you want to develop these kinds of games, you need to download a very large SDK (free) library. Today, I will describe another graphic engine, OpenGL.

OpenGL (Open Graphics Library) is a standard for a cross-platform graphics development. Some of the games developed by OpenGL are Doom3, Quake, and etcetera. Strictly speaking, OpenGL can be developed for any platform, and you don’t need to download a SDK, (if you have Visual Studio) because Microsoft cooperated with SGI, so it provides the running library.

Ok, you can now see the code attached; ‘I’ copied it from the Microsoft website. When you run it, you will see a little red light flashing and spinning.

You should have Visual Studio C++, start a new Win32 Project, and use any name you wish. Under Application Settings, choose Windows Application and Empty Project. When the project is initialized, you will see a folder called Source Files. Right Click it and choose Add New Items, choose Code in the popped up window. Then choose C++ File(.cpp), give a name, and hit ‘ok’.

Copy & paste the code included as followed. Then run it.

Source Code:

// MyOpenGL.cpp : Defines the entry point for the application.
//

#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0×0501 // Change this to the appropriate value to target other versions of Windows.
#endif

#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers

#include < windows.h >
#include < GL/gl.h >
#include < GL/glu.h >
#include < gl/glaux.h >
#include < math.h >

#pragma comment( lib, “opengl32.lib” )
#pragma comment( lib, “glu32.lib” )
#pragma comment( lib, “glaux.lib” )

/* Windows globals, defines, and prototypes */
TCHAR szAppName[]=L”Win OpenGL”;
HWND ghWnd;
HDC ghDC;
HGLRC ghRC;
#define SWAPBUFFERS SwapBuffers(ghDC)
#define BLACK_INDEX 0
#define RED_INDEX 13
#define GREEN_INDEX 14
#define BLUE_INDEX 16
#define WIDTH 600
#define HEIGHT 450
LONG WINAPI MainWndProc (HWND, UINT, WPARAM, LPARAM);
BOOL bSetupPixelFormat(HDC);
/* OpenGL globals, defines, and prototypes */

GLfloat LightAmbient[]= { 1.0f, 0.0f, 0.0f, 1.0f };
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat LightPosition[]= { 0.50f, .50f, -6.0f, 1.0f };
GLfloat Lightspecular[] = { 0.5f, 0.5f, 0.5f, 1.0f };

GLfloat LightAmbient1[]= { 1.0f, 1.0f, 0.0f, 1.0f };


GLvoid resize(GLsizei, GLsizei);
GLvoid initializeGL(GLsizei, GLsizei);
GLvoid drawScene(GLvoid);
GLfloat yrot=0.0f;
GLfloat xrot=0.0f;
GLfloat zrot=0.0f;

/*Win32 code*/
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
WNDCLASS wndclass;
/* Register the frame class */
wndclass.style = 0;
wndclass.lpfnWndProc = (WNDPROC)MainWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (hInstance, szAppName);
wndclass.hCursor = LoadCursor (NULL,IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wndclass.lpszMenuName = szAppName;
wndclass.lpszClassName = szAppName;
if (!RegisterClass (&wndclass) )
return FALSE;
/* Create the frame */
ghWnd = CreateWindow (szAppName,
L”OpenGL Sample”,
WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
CW_USEDEFAULT,
CW_USEDEFAULT,
WIDTH,
HEIGHT,
NULL,
NULL,
hInstance,
NULL);

/* make sure window was created */
if (!ghWnd)
return FALSE;

/* show and update main window */
ShowWindow (ghWnd, nCmdShow);

UpdateWindow (ghWnd);

/* animation loop */
while (1) {
/*
* Process all pending messages
*/

while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE)
{
if (GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} else {
return TRUE;
}
}
drawScene();
}
}

/* main window procedure */
LONG WINAPI MainWndProc (
HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
LONG lRet = 1;
PAINTSTRUCT ps;
RECT rect;

switch (uMsg) {

case WM_CREATE:
ghDC = GetDC(hWnd);
if (!bSetupPixelFormat(ghDC))
PostQuitMessage (0);

ghRC = wglCreateContext(ghDC);
wglMakeCurrent(ghDC, ghRC);
GetClientRect(hWnd, &rect);
initializeGL(rect.right, rect.bottom);
break;

case WM_PAINT:
BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;

case WM_SIZE:
GetClientRect(hWnd, &rect);
resize(rect.right, rect.bottom);
break;

case WM_CLOSE:
if (ghRC)
wglDeleteContext(ghRC);
if (ghDC)
ReleaseDC(hWnd, ghDC);
ghRC = 0;
ghDC = 0;

DestroyWindow (hWnd);
break;

case WM_DESTROY:
if (ghRC)
wglDeleteContext(ghRC);
if (ghDC)
ReleaseDC(hWnd, ghDC);

PostQuitMessage (0);
break;

case WM_KEYDOWN:
switch (wParam) {
case VK_LEFT:
zrot+=1.0f; break;
case VK_RIGHT:
zrot-=1.0f;break;
case VK_UP:
xrot+=1.0f;break;
case VK_DOWN:
xrot-=1.0f;break;
}
default:
lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
break;
}
return lRet;
}
BOOL bSetupPixelFormat(HDC hdc)
{
PIXELFORMATDE***OR pfd, *ppfd;
int pixelformat;
ppfd = &pfd;

ppfd->nSize = sizeof(PIXELFORMATDE***OR);
ppfd->nVersion = 1;
ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER;
ppfd->dwLayerMask = PFD_MAIN_PLANE;
ppfd->iPixelType = PFD_TYPE_COLORINDEX;
ppfd->cColorBits = 8;
ppfd->cDepthBits = 16;
ppfd->cAccumBits = 0;
ppfd->cStencilBits = 0;

pixelformat = ChoosePixelFormat(hdc, ppfd);
SetPixelFormat(hdc, pixelformat, ppfd);
return TRUE;
}
/* OpenGL code */GLvoid resize( GLsizei width, GLsizei height )
{
GLfloat aspect;
glViewport( 0, 0, width, height );

aspect = (GLfloat) width / height;

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 45.0, aspect, 3.0, 7.0 );
glMatrixMode( GL_MODELVIEW );
}
//construct the basic objects, and put them in a list
GLvoid createObjects()
{
GLUquadricObj *quadObjBody;
GLUquadricObj *quadObjNet;
GLUquadricObj *quadObjTop;
GLUquadricObj *quadObjUp;
GLUquadricObj *quadObjDown1;
GLUquadricObj *quadObjDown2;
GLUquadricObj *quadObjHandle;
GLUquadricObj *quadObjHead;

glNewList(1, GL_COMPILE);
glPushMatrix();
glScalef(0.7,0.7,0.7);
//draw the handle
glPushMatrix();
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient1);
glTranslatef(0.0f,.0f,-1.4f);
quadObjHandle = gluNewQuadric ();
gluQuadricDrawStyle (quadObjHandle, GLU_SILHOUETTE);
gluCylinder(quadObjHandle,0.02,0.02,0.5f,32,32);
quadObjHead = gluNewQuadric ();
gluSphere (quadObjHead, 0.05f, 64, 64);
glPopMatrix();
//draw the top
glPushMatrix();
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient1);
glTranslatef(0.0f,.0f,-1.05f);
quadObjUp = gluNewQuadric ();
gluQuadricDrawStyle (quadObjUp, GLU_SILHOUETTE);
gluCylinder(quadObjUp,0.25,0.3,0.1,32,32);

quadObjTop = gluNewQuadric();
gluQuadricDrawStyle (quadObjTop, GLU_LINE);
gluDisk(quadObjTop,0.02f,0.25,10,10);
glPopMatrix();
//draw the body
glPushMatrix();
glScalef(1.0,1.0,.80);
quadObjNet = gluNewQuadric ();
gluQuadricDrawStyle (quadObjNet, GLU_LINE);
gluSphere (quadObjNet, 1.205f, 8, 64);
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
quadObjBody = gluNewQuadric ();
gluSphere (quadObjBody, 1.20f, 64, 64);
glPopMatrix();
//draw the bottom
glPushMatrix();
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient1);
glTranslatef(0.0f,.0f,0.95f);
quadObjDown1 = gluNewQuadric ();
gluQuadricDrawStyle (quadObjDown1, GLU_SILHOUETTE);
gluCylinder(quadObjDown1,0.25,0.3,0.2,32,32);
quadObjDown2 = gluNewQuadric ();
gluQuadricDrawStyle (quadObjDown2, GLU_SILHOUETTE);
gluCylinder(quadObjDown2,0.15,0.2,0.3,32,32);

glPopMatrix();

glPopMatrix();
glEndList();


}
//initial, lighting, enable something
GLvoid initializeGL(GLsizei width, GLsizei height)
{
GLfloat aspect;

glClearIndex( (GLfloat)BLACK_INDEX);

glShadeModel(GL_SMOOTH); //make the color smoothly
glClearColor( 0.50, 0.50, 0.50, 1.0 ); //set the screen clear color
glClearDepth(.0f); //set the depth of buffer
glEnable(GL_DEPTH_TEST); //allow depth test
glDepthFunc(GL_GREATER); //the type of depth test
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, Lightspecular);
glLightfv(GL_LIGHT0, GL_POSITION,LightPosition);
glEnable(GL_LIGHT0);

glEnable(GL_NORMALIZE);
glFrontFace(GL_FRONT_AND_BACK);
glMatrixMode( GL_PROJECTION );
aspect = (GLfloat) width / height;

gluPerspective( 45.0, aspect, 5.0f, 10.0f );
glMatrixMode( GL_MODELVIEW );

createObjects();
}
//move
GLvoid drawScene(GLvoid)
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity(); glPushMatrix();
glTranslatef(0.0f,0.0f,-4.0f);
glRotatef(xrot,1.0f,0.0f,0.0f);
glRotatef(zrot,0.0f,0.0f,1.0f);
glPushMatrix();
glRotatef(yrot,0.0f,1.0f,0.0f);
glPushMatrix();
glRotatef(90,1.0f,.0f,.0f);
glCallList(1);
glPopMatrix();
glPopMatrix();
glPopMatrix();

if(abs(yrot – 360.0f) < 0.01)
yrot=0.0f;
yrot+=0.5f;

glFlush();
SWAPBUFFERS;
}
 

please excuse me for any spelling/grammar errors, I don’t proof read.

——————————

E-Insight, 2007