Hehe, just some knowledge on how to create 3D terrain.... errr... This is the easiest way MOST games do it if you'd like to know. It uses a heightmap.... and this is taken directly from my own 3D game engine.
/*
Terrain Class for 3D Engine
Author : Gotens84
Date : December 23, 2001
Desc : Terrain.cpp --- Terrain Definitions
version : .1
*/
#include "Terrain.h"
#include "TextureCV.h"
extern CTextureCV Tex;
void CTerrain::InitTerrain()
{
heightMapTexture = Tex.LoadBMP("data/gfx/heightMap.bmp",&heightMapInfo);
Tex.SetupNormTex("data/gfx/ heightMap.bmp",heightMapInfo,heightMap,heightMapTexture);
for(int z = 0; z <MAP_Z; z++)
{
for(int x = 0; x < MAP_X; x++)
{
terrain[x][z][0]=float(x)*MAP_SCALE;
terrain[x][z][1]=(float)heightMapTexture[(z*MAP_Z+x)*3];
terrain[x][z][2]=-float(z)*MAP_SCALE;
}
}
}
void CTerrain::DrawTerrain()
{
for(int z=0; z<MAP_Z-1;z++)
{
// glEnable(GL_TEXTURE_2D);
// glBindTexture(GL_TEXTURE_2D,heightMap);
glEnable(GL_CULL_FACE);
glFrontFace(GL_CCW);
glBegin(GL_TRIANGLE_STRIP);
for(int x=0; x<MAP_X-1;x++)
{
glColor3f(terrain[x][z][1]/255.0f,terrain[x][z][1]/ 255.0f,terrain[x][z][1]/255.0f);
glTexCoord2f(0.0f,0.0f);
glVertex3f(terrain[x][z][0],terrain[x][z][1],terrain[x][z][2]);
glTexCoord2f(1.0f,0.0f);
glColor3f(terrain[x+1][z][1]/255.0f,terrain[x+1][z][1]/ 255.0f,terrain[x+1][z][1]/255.0f);
glVertex3f(terrain[x+1][z][0],terrain[x+1][z][1],terrain[x+1 ][z][2]);
glTexCoord2f(0.0f,1.0f);
glColor3f(terrain[x][z+1][1]/255.0f,terrain[x][z+1][1]/ 255.0f,terrain[x][z+1][1]/255.0f);
glVertex3f(terrain[x][z+1][0],terrain[x][z+1][1],terrain[x][ z+1][2]);
glTexCoord2f(1.0f,1.0f);
glColor3f(terrain[x+1][z+1][1]/255.0f,terrain[x+1][z+1][1]/ 255.0f,terrain[x+1][z+1][1]/255.0f);
glVertex3f(terrain[x+1][z+1][0],terrain[x+1][z+1][1],terrain [x+1][z+1][2]);
}
glEnd();
glDisable(GL_CULL_FACE);
// glDisable(GL_TEXTURE_2D);
}
}
Simple HUH?! Well, if byond 3D ever does take off check this C++ code out ;)
1
2
ID:193421
Jan 15 2002, 8:35 pm
|
|
In response to English
|
|
I think I'll go live under a rock and wait for it to dissappear, I'm only doing basic DOS programs (AND I MEAN BASIC) with C++, using only cin, cout, if() else, and a few sting options...
|
In response to Nadrew
|
|
It does look a little complicated at first, but when you do all the math it works out. =)
|
In response to Goten84
|
|
Oh, you have no idea how much it makes my head hurt, I feel like a newbie again!
|
In response to Nadrew
|
|
Nadrew wrote:
Oh, you have no idea how much it makes my head hurt, I feel like a newbie again! If you really want to be freaked out by code, try looking through the source for POV-Ray sometime. My first foray into customizing that worked with height field code very similar to what Goten84 showed, only much more complex. (I didn't have to write it; I only wrote in some routines to change the way triangle smoothing was done.) Lummox JR |
In response to Lummox JR
|
|
Ack! This is like telling a newbie to DM to look though one of Gazoot's "advanced" libraries.
|
The code isn't THAT hard, I bet If I wanted to, I could skim through my OpenGL docs and figure this one out soon :) If you know what all the command mean, you wouldn't have that many problems reading the code :)
|
In response to Nadrew
|
|
Well when newbies start off in BYOND, they don't have a clue what the code does, or how to use it... Same with C++. If you spent a good week looking at some great tutorials, you'd be a C++ guru too (College courses wouldn't hurt too ^_^, I know I'm going to take some!)
|
In response to Dreq
|
|
Yep, at first structs and pointers look kind of scary but they're no big deal once you work with them a little bit. I'd imagine the same thing would happen with this code, although it is a little more complicated than the concept of structs and pointers :p
The scariest things in languages are when new operators get thrown in. When a new function is added, it's usually no problem, just look it up and see what it does. I've never used the : operator in C++ yet so that adds to my confusion :p The most advanced operator I've used is the -> operator. Isn't -> used to access a variable in a struct from the pointer to the struct? Basically, tree -> num_apples would replace (*tree).num_apples Wait a minute...that doesn't look right, now I'm confusing myself :p |
In response to English
|
|
English wrote:
Yep, at first structs and pointers look kind of scary but they're no big deal once you work with them a little bit. I'd imagine the same thing would happen with this code, although it is a little more complicated than the concept of structs and pointers :p -> is the exact same as . (Atleast in C), except due to conflict between the updates both have been left in(oh yeah, and backwards compatability). I think, anyways. Its been a long time since Ive done any work in C(1+ year(s)) Alathon |
In response to Alathon
|
|
You sure? I'm pretty sure they're different. You use them to get the same result but I think the -> is a shortcut when your using pointers to structs. I forgot that was in C, ehgahd, I only know four languages (well ok, HTML isn't a real language, too bad :p) and I'm getting them mixed up already. I think I'll hold off on trying to learn anymore.
|
In response to English
|
|
Actually, I have more complex code. I didn't that that was complex tho, I mean, all it's doing is using arrays. ;) Actually, what would really be nice is if this BYOND Forum put up a code free section where people can place all their code to whatever program they make. I'm all for Open Source and wouldn't mind sharing my codes with other people.
|
In response to Goten84
|
|
@_@.
If that were VB I could probably figure it out one way or another. My favorite 3d Engine for VB is TrueVision, but I`m afraid I`m kinda a newbie at vb too, so I couldnt do much |
In response to Goten84
|
|
I just looked the code over again and it doesn't look as scary as I thought at first. I suppose one of the reasons it's kind of intimidating is because we can't see all the macro string replacements and other function definitions so it seems more confusing than it really is.
|
In response to English
|
|
Sorry about that....
HERE'S THE TERRAIN CLASS ------------------------ #include <windows.h> #include <math.h> #define MAP_X 32 #define MAP_Z 32 #define MAP_SCALE 32.0f class CTerrain { private: float g_terrain[MAP_X * MAP_Z][3]; float terrain[MAP_X][MAP_Z][3]; public: void InitTerrain(); void DrawTerrain(); float GetHeight(float x, float z); // TERRAIN //-------- unsigned int heightMap; unsigned char* heightMapTexture; BITMAPINFOHEADER heightMapInfo; }; ----------------------------------------------------------- HERE'S THE TEXTURE CLASS ----------------------------------------------------------- #ifndef __TEXTURE_H #define __TEXTURE_H /* Window Interface Class for 3D Engine Author : Gotens84 Date : December 15, 2001 Desc : TextureCV.h --- Texture Class version : .9 */ // UNIVERSAL BITMAP ID #define BITMAP_ID 0x4D42 // HEADERS #include <windows.h> #include <stdio.h> #include <gl/gl.h> #include <gl/glu.h> // STRUCTURE FOR THE TGAFILE //----------------------------------------------- typedef struct { unsigned char imageTypeCode; short int imageWidth; short int imageHeight; unsigned char bitCount; unsigned char *imageData; }TGAFILE; typedef struct tagTARGAFILEHEADER { unsigned char imageIDLength; // number of characters in identification field; // 0 denotes no identification field is included unsigned char colorMapType; // type of color map; always 0 unsigned char imageTypeCode; // uncompressed RGB is 2; // uncompressed grayscale is 3; short int colorMapOrigin; // origin of color map (lo-hi); always 0 short int colorMapLength; // length of color map (lo-hi); always 0 short int colorMapEntrySize; // color map entry size (lo-hi); always 0 short int imageXOrigin; short int imageYOrigin; short int imageWidth; short int imageHeight; unsigned char bitCount; unsigned char imageDescriptor; }TARGAFILEHEADER; //----------------------------------------------- //-->END OF TARGA FILE STRUCTURES class CTextureCV { public: //----------------------------------------------------------------------------------------------------- unsigned char *LoadBMP(char *filename,BITMAPINFOHEADER *bitmapInfoHeader); // Load Bitmap // int WriteBMP(char *filename,int width,int height,unsigned char *imageData); // Write Bitmap //----------------------------------------------------------------------------------------------------- int LoadTGA(char *filename,TGAFILE *tgafile); // Load TGA // int WriteTGA(char *filename,short int width,short int height, unsigned char* imageData); //Write TGA //----------------------------------------------------------------------------------------------------- public: void SetupTextureNorm(char *filename,GLuint &texture); // Setup Norm Texture void SetupNormTex(char *filename,BITMAPINFOHEADER bitmapInfoHeader,GLuint &texture,unsigned char* bitmapData); // Setup Norm v2 // void SetupClampTexture(char *filename,unsigned int &texture); // Setup Clamp Texture // void SetupRepeatTexture(char *filename,unsigned int &texture); // Setup Repeat Texture // void SetupEvnTexture(char *filename,unsigned int &texture); // Setup Environment Texture // void SetupLightMapTexture(char *filename,unsigned int &texture); // Setup LightMap Texture //----------------------------------------------------------------------------------------------------- BITMAPINFOHEADER bitmapInfoHeader; // bitmap info header for CV class unsigned char* bitmapData; // bitmap data unsigned int testpic; // test picture variable //----------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------- //-->END OF CLASS }; #endif // __TEXTURE_H |
In response to Goten84
|
|
It really really hurts to think. All I know is very basic C++ in DOS that I learned from tutorials and "C++ For Dummies "! The title explains it all.. Maybe some day Ill move up to the next book ... "More C++ For Dummies".. and I think ther is one more after that for programming in Windows.
|
In response to Wall04
|
|
I started C++ when I was a sophmore in school, now I'm like going to college and I've been programming in C++ for a years now. Sometimes it seems like I'll never know enough, there's just so much C++ can do you'd be amazed.
|
In response to Goten84
|
|
Goten84 wrote:
I started C++ when I was a sophmore in school, now I'm like going to college and I've been programming in C++ for a years now. Sometimes it seems like I'll never know enough, there's just so much C++ can do you'd be amazed. What do you think would be better.. Going to College or taking some Information Technology course if you wanted to get a job in the game making industry? or in any programming company? |
In response to Wall04
|
|
Going to college since now these days people are looking for degrees. ;)
|
1
2
I think I'll take a few more classes and read some more books before I even try to understand that :p
Actually, I've never dealt with graphics or anything visual outside of beyond so I think I should tackle 2D C++ programming before I move to 3D.