【3D技术宅公社】XR数字艺术论坛  XR技术讨论 XR互动电影 定格动画

 找回密码
 立即注册

QQ登录

只需一步,快速开始

调查问卷
论坛即将给大家带来全新的技术服务,面向三围图形学、游戏、动画的全新服务论坛升级为UTF8版本后,中文用户名和用户密码中有中文的都无法登陆,请发邮件到324007255(at)QQ.com联系手动修改密码

3D技术论坛将以计算机图形学为核心,面向教育 推出国内的三维教育引擎该项目在持续研发当中,感谢大家的关注。

查看: 3638|回复: 0

[HGE引擎] HGE1.6自带例题简单分析

[复制链接]
发表于 2006-11-2 10:42:54 | 显示全部楼层 |阅读模式

HGE的例题是从02开始的,其实都很简单。

tutorial02

/*

** Haaf's Game Engine 1.6

** Copyright (C) 2003-2006, Relish Games

** hge.relishgames.com

**

** hge_tut02 - Using input, sound and rendering

*/

// Copy the files "particles.png" and "menu.wav"

// from the folder "precompiled" to the folder with

// executable file. Also copy hge.dll and bass.dll

// to the same folder.

#include "..\..\include\hge.h"

HGE *hge=0;

// Quad is the basic primitive in HGE

// used for rendering graphics.

// Quad contains 4 vertices, numbered

// 0 to 3 clockwise.

hgeQuad quad;

// Handle for a sound effect

HEFFECT snd;

// Some "gameplay" variables and constants

float x=100.0f, y=100.0f; //起始位置

float dx=0.0f, dy=0.0f;

const float speed=90; //速度

const float friction=0.98f; //摩擦系数

// This function plays collision sound with

// parameters based on sprite position and speed

void boom() {

int pan=int((x-400)/4);

float pitch=(dx*dx+dy*dy)*0.0005f+0.2f;

hge->Effect_PlayEx(snd,100,pan,pitch); //根据位置的特效音乐

}

bool FrameFunc()

{

// Get the time elapsed since last call of FrameFunc().

// This will help us to synchronize on different

// machines and video modes.

float dt=hge->Timer_GetDelta();

// Process keys

// 键盘响应

if (hge->Input_GetKeyState(HGEK_ESCAPE)) return true;

if (hge->Input_GetKeyState(HGEK_LEFT)) dx-=speed*dt;

if (hge->Input_GetKeyState(HGEK_RIGHT)) dx+=speed*dt;

if (hge->Input_GetKeyState(HGEK_UP)) dy-=speed*dt;

if (hge->Input_GetKeyState(HGEK_DOWN)) dy+=speed*dt;

// Do some movement calculations and collision detection

// 这里的16像素差距应该是球体的半径

dx*=friction; dy*=friction; x+=dx; y+=dy;

if(x>784) {x=784-(x-784);dx=-dx;boom();}

if(x<16) {x=16+16-x;dx=-dx;boom();}

if(y>584) {y=584-(y-584);dy=-dy;boom();}

if(y<16) {y=16+16-y;dy=-dy;boom();}

// Set up quad's screen coordinates

// 确定位置

quad.v[0].x=x-16; quad.v[0].y=y-16;

quad.v[1].x=x+16; quad.v[1].y=y-16;

quad.v[2].x=x+16; quad.v[2].y=y+16;

quad.v[3].x=x-16; quad.v[3].y=y+16;

// Continue execution

return false;

}

// This function will be called by HGE when

// the application window should be redrawn.

// Put your rendering code here.

bool RenderFunc()

{

// Begin rendering quads.

// This function must be called

// before any actual rendering.

// HGE渲染开始

hge->Gfx_BeginScene();

// Clear screen with black color

// HGE清屏

hge->Gfx_Clear(0);

// Render quads here. This time just

// one of them will serve our needs.

hge->Gfx_RenderQuad(&quad);

// End rendering and update the screen

// HGE渲染结束

hge->Gfx_EndScene();

// RenderFunc should always return false

return false;

}

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)

{

// Get HGE interface

hge = hgeCreate(HGE_VERSION);

// Set up log file, frame function, render function and window title

hge->System_SetState(HGE_LOGFILE, "hge_tut06.log");

hge->System_SetState(HGE_FRAMEFUNC, FrameFunc); //

hge->System_SetState(HGE_RENDERFUNC, RenderFunc); //渲染

hge->System_SetState(HGE_TITLE, "HGE Tutorial 02 - Using input, sound and rendering");//标题

// Set up video mode

hge->System_SetState(HGE_WINDOWED, true); //窗口

hge->System_SetState(HGE_SCREENWIDTH, 800); //长

hge->System_SetState(HGE_SCREENHEIGHT, 600); //宽

hge->System_SetState(HGE_SCREENBPP, 32); //色深

if(hge->System_Initiate())

{

// Load sound and texture

// 声音和纹理

snd=hge->Effect_Load("menu.wav");

quad.tex=hge->Texture_Load("particles.png");

if(!snd && !quad.tex)

{

// If one of the data files is not found, display

// an error message and shutdown.

MessageBox(NULL, "Can't load MENU.WAV or PARTICLES.PNG", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);

hge->System_Shutdown();

hge->Release();

return 0;

}

// Set up quad which we will use for rendering sprite

quad.blend=BLEND_ALPHAADD | BLEND_COLORMUL | BLEND_ZWRITE;

for(int i=0;i<4;i++)

{

// Set up z-coordinate of vertices

quad.v.z=0.5f;

// Set up color. The format of DWORD col is 0xAARRGGBB

quad.v.col=0xFFFFA000;

}

// Set up quad's texture coordinates.

// 0,0 means top left corner and 1,1 -

// bottom right corner of the texture.

// 设置纹理坐标

quad.v[0].tx=96.0/128.0; quad.v[0].ty=64.0/128.0;

quad.v[1].tx=128.0/128.0; quad.v[1].ty=64.0/128.0;

quad.v[2].tx=128.0/128.0; quad.v[2].ty=96.0/128.0;

quad.v[3].tx=96.0/128.0; quad.v[3].ty=96.0/128.0;

// Let's rock now!

hge->System_Start();

// Free loaded texture and sound

hge->Texture_Free(quad.tex);

hge->Effect_Free(snd);

}

else MessageBox(NULL, hge->System_GetErrorMessage(), "Error", MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);

// Clean up and shutdown

hge->System_Shutdown();

hge->Release();

return 0;

}

[此贴子已经被AnnO于2006-11-2 13:46:18编辑过]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|3D数字艺术论坛 ( 沪ICP备14023054号 )

GMT+8, 2025-2-6 07:11

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表