Advertisement
2_2002-2004 Games #126921

G3DMazeRoom

This application was a part of my university assignment to create a room with a table in it. On the table is a 3D maze. The user can walk around the room, then jump onto the table and walk around the maze. This code has the following: 1. Creating a 3D environment. 2. Smooth motion camera movement. 3. Perspective animation to 'jump onto the table'. 4. Dynamically generate a 3D maze based on an array. 5. Collision detection around the room, table and 3D maze. 6. Some basic 3D lighting. 7. Texturing. The code makes use of Java3D, so please make sure you install that as well or it wont run. This was tested on the OpenGL implementation of Java3D. There is also a supporting documentation explaining the program and concepts. It is ideal for anyone studying Java3D or simply wants to have some fun ... Enjoy. Remember, if you're doing a similar assignment at college/university ... be original in your code! Oh yeah, to run it type: java G3DMazeRoom

AI

AI 요약: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

소스 코드
original-source
Upload
//---------------------------------------------------------------------------
#ifndef urandH
#define urandH
#include <vector.h>
//---------------------------------------------------------------------------
class urand
{
  public:
    urand();
    urand(double start, double end, double increment = 1);
    explicit urand(vector<int> NumList);
    explicit urand(vector<double> NumList);
    double Rand();
    void prime(double start, double end, double increment = 1);
    void prime(vector<int> NumList);
    void prime(vector<double> NumList);
    void reset();
  private:
    vector<double> RandNums;
    int iter;
    void error();
    void shuffle();
};
#endif
//---------------------------------------------------------------------------
#include "urand.h"
#include <stdlib.h>
#include <vector.h>
#include <iostream.h>
#include <conio.h>
//---------------------------------------------------------------------------
urand::urand()
{
  prime(0,0);
}
/******************************************************************************/
urand::urand(double start, double end, double increment)
{
  prime(start, end, increment);
}
/******************************************************************************/
urand::urand(vector<int> NumList)
{
  prime(NumList);
}
/******************************************************************************/
urand::urand(vector<double> NumList)
{
  prime(NumList);
}
/******************************************************************************/
double urand::Rand()
{
  if(iter >= RandNums.size())
    reset();
  iter++;
  return(RandNums[iter-1]);
}
/******************************************************************************/
void urand::prime(double start, double end, double increment)
{
  if(end < start || increment <= 0)
  {
    error();
    return;
  }
  randomize();
  iter = 0;
  RandNums.clear();
  for(double i = start; i <= end; i+=increment)
    RandNums.push_back(i);
  shuffle();
}
/******************************************************************************/
void urand::prime(vector<int> NumList)
{
  if(NumList.size() == 0)
    prime(0,0);
  else
  {
    RandNums.clear();
    for(int i = 0; i < NumList.size(); i++)
      RandNums.push_back(NumList[i]);
  }
  shuffle();
}
/******************************************************************************/
void urand::prime(vector<double> NumList)
{
  if(NumList.size() == 0)
    prime(0,0);
  else
    RandNums = NumList;
  shuffle();
}
/******************************************************************************/
void urand::reset()
{
  iter = 0;
  shuffle();
}
/******************************************************************************/
void urand::error()
{
  cout << "Invalid use of urand object.\n";
  getch();
}
/******************************************************************************/
void urand::shuffle()
{
  randomize();
  int RandPos;
  double dummy;
  for(int i = 0; i < RandNums.size(); i++)
  {
    RandPos = rand()%RandNums.size();
    dummy = RandNums[i];
    RandNums[i] = RandNums[RandPos];
    RandNums[RandPos] = dummy;
  }
}
/*
//Example Code
int main(int argc, char* argv[])
{
  urand x(0, 15);
  for(int i = 0; i < 16; i++)
    cout << x.Rand() << " ";
  cout << endl << endl;
  x.prime(5, 9);
  for(int i = 0; i < 5; i++)
    cout << x.Rand() << " ";
  cout << endl << endl;
  cout << x.Rand() << " " << x.Rand() << " " << x.Rand() << " ";
  x.reset();
  cout << x.Rand() << " " << x.Rand() << " " << x.Rand() << " ";
  cout << endl << endl;
  x.prime(4, 5, .1);
  for(int i = 0; i < 11; i++)
    cout << x.Rand() << " ";
  cout << endl << endl;
  vector<int> nums(10);
  for(int i = 0; i < 10; i++)
    nums[i] = i*i;
  x.prime(nums);
  for(int i = 0; i < 10; i++)
    cout << x.Rand() << " ";
  cout << endl << endl;
  getch();
  return 0;
}
*/
원본 댓글 (3)
Wayback Machine에서 복구됨