132 Commits
Author SHA1 Message Date
Dofensmirtsz f370b5b467 double crystal 2016-06-22 03:14:33 +02:00
Dofensmirtsz ec76b4e754 Merge branch 'developer' into FireWorld
# Conflicts:
#	worlds/worlds.json
2016-06-22 02:57:01 +02:00
Jannick van Ballegooijen 82acf0d9fc ice world 2016-06-22 02:54:12 +02:00
Dofensmirtsz f6d7695405 Fire en Earth werkend 2016-06-22 02:52:35 +02:00
kennyboy55 5de58e6f74 Remove circle 2016-06-22 02:35:34 +02:00
kennyboy55 316d6c9e14 Merge pull request #31 from CrystalPointA4/feature/loadingscreen
Feature/loadingscreen
2016-06-22 02:20:48 +02:00
Remco 80f0c33b91 Merge branch 'developer' into feature/loadingscreen
# Conflicts:
#	worlds/rock.json
2016-06-22 02:17:44 +02:00
Remco 9f455be8d6 revert commit 2016-06-22 02:00:30 +02:00
kennyboy55 5ad61e525f Merge pull request #30 from CrystalPointA4/world/Building
World/building
2016-06-22 01:54:21 +02:00
kennyboy55 df611e8e51 Bugfix 2016-06-22 01:51:58 +02:00
kennyboy55 5fc92d3f2a Merge branch 'developer' into world/Building
# Conflicts:
#	World.cpp
#	worlds/rock.json
2016-06-22 01:49:27 +02:00
Remco d1abc20f64 placed loadingscreen picture in json file of a world 2016-06-22 01:48:00 +02:00
kennyboy55 97d43a1249 Merge pull request #29 from CrystalPointA4/feature/weaponCollision
Feature/weapon collision
2016-06-22 01:45:14 +02:00
Remco cdd3b962eb texture in loadings screen 2016-06-22 01:40:53 +02:00
jancoow c9e5be2573 Merge branch 'developer' into feature/weaponCollision 2016-06-22 01:38:46 +02:00
jancoow 5b6e7b54c7 Added enemy damage 2016-06-22 01:37:47 +02:00
kennyboy55 9143204610 Merge pull request #28 from CrystalPointA4/feature/weaponCollision
Feature/weapon collision
2016-06-22 00:50:22 +02:00
kennyboy55 5f31b2e602 Merge branch 'developer' into feature/weaponCollision 2016-06-22 00:49:05 +02:00
kennyboy55 342a56fa5a Added audio 2016-06-22 00:47:02 +02:00
jancoow 27dfaf74c4 Better weapon alignment 2016-06-22 00:32:19 +02:00
Remco fea7728139 enemy hits player 2016-06-22 00:26:43 +02:00
Remco 50e2b1c7ea enemy weird xp gift fixed 2016-06-21 23:44:32 +02:00
Remco 5bff991b77 Merge branch 'developer' into feature/loadingscreen 2016-06-21 23:39:09 +02:00
Remco 9192eb7371 see couting points of loading things 2016-06-21 23:38:33 +02:00
kennyboy55 eaa6f9cd57 Hotfix rock world 2016-06-21 23:35:36 +02:00
Dofensmirtsz 6306e8abd4 Heightmap fix, texture fix, rotating crystals and enemy height to 0 2016-06-21 23:31:43 +02:00
Remco 7edbcd4d4d loadingscreen has been draw when loading a world 2016-06-21 23:28:44 +02:00
Remco d3bde622f0 menu placing right 2016-06-21 23:19:20 +02:00
Remco a407be072d Revert "Revert "Revert "added loadingscreen clas"""
This reverts commit 97448bfabf.
2016-06-21 23:12:22 +02:00
Remco 97448bfabf Revert "Revert "added loadingscreen clas""
This reverts commit 7e6514581e.
2016-06-21 23:12:02 +02:00
Remco 7e6514581e Revert "added loadingscreen clas"
This reverts commit 52ef1b4494.
2016-06-21 23:11:42 +02:00
jancoow ba0482ee0a Merge remote-tracking branch 'origin/developer' into feature/weaponCollision
Added waeponswitch to backbutton of controller

# Conflicts:
#	Enemy.cpp
#	Player.cpp
#	Weapon.cpp
#	Weapon.h
2016-06-21 23:10:58 +02:00
kennyboy55 0e99b9f719 Attempt fix rock world 2016-06-21 22:57:18 +02:00
jancoow e7163fc07c Added controller cursor in menu 2016-06-21 22:12:08 +02:00
Remco 52ef1b4494 added loadingscreen clas 2016-06-21 22:10:58 +02:00
kennyboy55 3cf6bf5857 Merge pull request #27 from CrystalPointA4/musicInclude
Music include
2016-06-21 20:03:56 +02:00
Aaldert 579a04a9b4 Merge branch 'developer' into musicInclude
# Conflicts:
#	worlds/small.json
2016-06-21 19:16:12 +02:00
Aaldert b09311d810 Merge branch 'developer' into musicInclude
# Conflicts:
#	Enemy.cpp
#	World.cpp
2016-06-21 19:06:50 +02:00
kennyboy55 d42ae6ccd3 Merge pull request #26 from CrystalPointA4/feature/weaponJSON
Feature/weapon json
2016-06-21 19:05:53 +02:00
kennyboy55 f80b513d90 Add weapon switching 2016-06-21 19:05:06 +02:00
kennyboy55 3025fecf94 Load weapons from JSON 2016-06-21 18:25:16 +02:00
Aaldert 41a81d104e Enemy stops geluid als gedood 2016-06-21 18:23:57 +02:00
Aaldert 9543dd8324 Muziek toegvoegt aan world en enemy 2016-06-21 18:15:49 +02:00
Aaldert d56625e19a MusicIncluded, crystals 2016-06-21 17:10:34 +02:00
jancoow 0431e9c230 Merge remote-tracking branch 'origin/feature/weaponJSON' into feature/weaponCollision 2016-06-21 17:07:59 +02:00
jancoow d14f045708 Added dead check 2016-06-21 17:07:19 +02:00
kennyboy55 4437acb9f2 Added missing json 2016-06-21 17:06:57 +02:00
jancoow 02a537dc60 Merge remote-tracking branch 'origin/feature/weaponJSON' into feature/weaponCollision 2016-06-21 17:01:08 +02:00
jancoow 4249e35653 Check if weapon collision point is inside enemy and do weapon damage 2016-06-21 17:00:36 +02:00
kennyboy55 ec900f7410 Added health+damage to enemy 2016-06-21 16:58:39 +02:00
kennyboy55 0a0fdfc8b1 Merge pull request #25 from CrystalPointA4/feature/Controller
Feature/controller
2016-06-21 15:44:43 +02:00
kennyboy55 4effce6fea Merge branch 'developer' into feature/Controller 2016-06-21 15:43:54 +02:00
kennyboy55 81cf7f43c0 Merge pull request #24 from CrystalPointA4/feature/normalsmoothing
normal smoothing
2016-06-21 15:42:39 +02:00
kennyboy55 58ac7d13cf Merge pull request #23 from CrystalPointA4/feature/soundsystemfix
Sound pointers worden gedelete
2016-06-21 15:42:09 +02:00
kennyboy55 c91bb5c656 attempt fix 2016-06-21 15:41:42 +02:00
kennyboy55 ed3e537a3c Fix visual studio project files 2016-06-21 15:31:12 +02:00
Jannick van Ballegooijen eaeff6ed7d normal smoothing 2016-06-21 15:28:15 +02:00
kennyboy55 942b068851 Merge branch 'developer' into feature/Controller
# Conflicts:
#	CrystalPoint.cpp
#	Player.cpp
2016-06-21 15:14:08 +02:00
Aaldert eadfea9d63 Sound pointers worden gedelete 2016-06-21 14:45:41 +02:00
kennyboy55 e848780535 Merge pull request #22 from CrystalPointA4/feature/gameplay
Feature/gameplay
2016-06-21 14:17:13 +02:00
Aaldert ea22712a45 Merge branch 'developer' into feature/gameplay
# Conflicts:
#	CrystalPoint.cpp
2016-06-21 14:06:41 +02:00
jancoow 36dc74a39e Fixed crash at startup, improved walking speed 2016-06-21 14:00:04 +02:00
kennyboy55 6096e53d94 Merge pull request #21 from CrystalPointA4/feature/Sounds
Bugfixes, added sound to portal and enemy in JSON
2016-06-21 13:53:30 +02:00
kennyboy55 8700aa90af Bugfixes, added sound to portal and enemy in JSON 2016-06-21 13:51:16 +02:00
Aaldert 35c21260e4 Hp, Lvl en Xp gameplay toegevoegt 2016-06-21 12:25:38 +02:00
jancoow 06a768a3a1 Fixed right weapon 2016-06-21 11:32:37 +02:00
jancoow 3f8623d0bf Merge remote-tracking branch 'origin/developer' into feature/Controller
Added support for second controller
# Conflicts:
#	CrystalPoint.cpp
#	CrystalPoint.h
#	CrystalPoint.vcxproj
#	CrystalPoint.vcxproj.filters
2016-06-21 11:24:55 +02:00
kennyboy55 7c4805d899 Merge pull request #18 from CrystalPointA4/feature/Menu
Feature/menu
2016-06-20 20:43:00 +02:00
kennyboy55 e42779f6c7 Fixed project files 2016-06-20 20:42:35 +02:00
kennyboy55 ce2f658b61 Merge branch 'developer' into feature/Menu 2016-06-20 20:39:00 +02:00
kennyboy55 3701918ac9 Bugfix 2016-06-20 20:38:56 +02:00
kennyboy55 d887328907 Merge pull request #19 from CrystalPointA4/feature/werkendewav
Feature/werkendewav
2016-06-20 20:37:14 +02:00
kennyboy55 8cf1b02cf7 Merge branch 'developer' into feature/werkendewav 2016-06-20 20:34:35 +02:00
kennyboy55 83557c7ba7 Added controller code 2016-06-20 20:33:28 +02:00
Janco Kock 779cf5cb91 Merge pull request #20 from CrystalPointA4/linux_refactor
Working version for linux
2016-06-20 20:11:10 +02:00
jancoow 030a136e8b Working version for linux 2016-06-20 20:00:58 +02:00
kennyboy55 da0b1f5588 Johan fix 2016-06-20 17:16:29 +02:00
Aaldert f93c09a999 rock heeft muziek 2016-06-20 15:48:57 +02:00
Aaldert 587b79044b Delete 2016-06-20 15:41:39 +02:00
Aaldert dba9c581b1 world aangepast 2016-06-20 15:33:07 +02:00
Aaldert d5406120c6 Enemy speelt cow! 2016-06-20 15:30:38 +02:00
Remco e081373a45 Merge branch 'developer' into feature/Menu
# Conflicts:
#	CrystalPoint.vcxproj.filters
#	Main.cpp
#	Skybox.cpp
#	Skybox.h
2016-06-20 15:23:55 +02:00
Remco 98f3645b6b menu pauses game, able to resume the game. exit game by pause menu 2016-06-20 15:20:12 +02:00
Aaldert 5c776e3d3a Test 2016-06-20 14:53:40 +02:00
Remco 03c06e0974 delete action pointer 2016-06-20 13:44:02 +02:00
Aaldert b7d73c9abe Test 1 2016-06-20 13:43:13 +02:00
Remco 7758f2c294 able to give button a funtion pointer, who will be called when clicked on the button 2016-06-20 13:42:28 +02:00
Remco 2e50d11e07 able to click with cursor, button detect clicking event 2016-06-20 13:29:28 +02:00
Remco 1ec3c8f346 buttons shows when ever the cursor is in the button 2016-06-20 12:50:51 +02:00
Remco 8dcee70324 button, text is placed in middle of button, plane is placed behind text 2016-06-20 12:38:16 +02:00
Remco 6cf9437620 button is draw by menu 2016-06-20 12:11:24 +02:00
kennyboy55 f84fcfa4e2 Merge pull request #17 from CrystalPointA4/worlds
Added Rock world. Updated others
2016-06-10 12:10:28 +02:00
kennyboy55 ad30824057 Added Rock world. Updated others 2016-06-10 12:09:16 +02:00
kennyboy55 04fd3ac0e3 Skybox brightness hotfix 2016-06-10 11:59:43 +02:00
kennyboy55 31c11f3e1f Merge pull request #16 from CrystalPointA4/feature/portal_logic
Feature/portal logic
2016-06-10 11:56:52 +02:00
kennyboy55 656a904a4b Merge remote-tracking branch 'origin/feature/portal_logic' into feature/portal_logic 2016-06-10 11:56:17 +02:00
kennyboy55 348b53c027 Added enemy -> brightness skybox 2016-06-10 11:55:57 +02:00
Remco 71801a30f2 player crystals refresh 2016-06-10 11:06:39 +02:00
Remco 0ca94aef4d when collected all crystals it is possible to move to the next level, by stepping in the portal 2016-06-10 10:56:54 +02:00
kennyboy55 ced3ff4462 Attempt implement menu (unresolved symbol error) 2016-06-09 17:56:37 +02:00
Remco 912a2234a3 crystals will be displayed, when not get with darker icons, when picked up crystals get colors 2016-06-09 17:47:34 +02:00
kennyboy55 0209c8b4e2 Merge pull request #14 from CrystalPointA4/feature/refactor_crystals
Feature/refactor crystals
2016-06-09 13:05:11 +02:00
kennyboy55 6bcd9b1426 Merge pull request #15 from CrystalPointA4/feature/Skybox
Feature/skybox
2016-06-09 13:04:19 +02:00
kennyboy55 579e02728a Merge branch 'developer' into feature/Skybox
# Conflicts:
#	CrystalPoint.vcxproj.filters
#	World.h
2016-06-09 13:03:28 +02:00
kennyboy55 af681b0223 Fixed color issues 2016-06-09 13:01:03 +02:00
Remco 3ed5331437 Merge branch 'developer' into feature/refactor_crystals 2016-06-09 12:41:53 +02:00
kennyboy55 0aad7262d6 Merge pull request #13 from CrystalPointA4/feature/OpenAL
Feature/OpenAL
2016-06-09 12:38:09 +02:00
Remco 9cfaf07eba optimiasted crystal, entity now has a collide methode, which will be called when an entity collison has with the player. 2016-06-09 12:35:00 +02:00
kennyboy55 9659caa1d8 Fix filters 2016-06-09 12:32:13 +02:00
kennyboy55 a4373adc25 Fix image direction / load from JSON 2016-06-09 12:22:40 +02:00
Remco 1f3188376a added new model for crystal, not possible to move through crystals 2016-06-09 12:07:27 +02:00
kennyboy55 69561794d8 Reimplemented into newer develop version 2016-06-09 12:01:24 +02:00
Aaldert 5c24a34202 Merge branch 'developer' into feature/OpenAL
# Conflicts:
#	CrystalPoint.vcxproj.filters
#	Enemy.cpp
#	Enemy.h
#	worlds/small.json
2016-06-09 11:44:45 +02:00
Remco 1164501158 added variables for crystal icons in interface class 2016-06-09 11:12:15 +02:00
kennyboy55 593b9547cf Merge pull request #12 from CrystalPointA4/crystal_capturing
Crystal capturing
2016-06-09 10:34:49 +02:00
kennyboy55 1a4339b49d Merge branch 'developer' into crystal_capturing
# Conflicts:
#	World.cpp
#	worlds/small.json
2016-06-09 10:34:33 +02:00
kennyboy55 2c624ac4c7 Merge pull request #11 from CrystalPointA4/enemy
Enemy
2016-06-09 10:27:24 +02:00
Remco 881b58138c crystal displayed on interface, with fancy gradient and the most beautifull colors for the crystal :) 2016-06-08 13:08:14 +02:00
Remco bba0a2e2a0 picking up crystal(sphere) 2016-06-08 12:41:33 +02:00
Aaldert 117010b9fe OpenAl Werkt! en Setup enzo 2016-06-05 23:49:06 +02:00
Aaldert 47b4d9570d Music Handler 2016-06-05 17:25:04 +02:00
Aaldert 0f8fd67dd3 Merge remote-tracking branch 'refs/remotes/origin/developer' into feature/OpenAL
# Conflicts:
#	CrystalPoint.vcxproj.filters
#	Enemy.h
2016-06-05 16:06:48 +02:00
Aaldert 0afbca8ffc More Generalized 2016-06-05 15:26:14 +02:00
Remco 293ceb0b9f enemy walking around world 2016-06-03 13:58:07 +02:00
Remco b827885f40 enemy collide logic in enemy and out of world 2016-06-03 13:51:54 +02:00
kennyboy55 527394f635 Merge pull request #10 from CrystalPointA4/enemy
Enemy
2016-06-03 11:31:33 +02:00
kennyboy55 95ab1879b4 Merge branch 'developer' into enemy
# Conflicts:
#	CrystalPoint.cpp
#	Entity.cpp
#	Player.cpp
#	Player.h
#	World.cpp
#	World.h
2016-06-03 11:30:19 +02:00
Remco c3fe041eb1 enemy logic added to enemy and out of world 2016-06-03 11:09:48 +02:00
Daniel f0a8330819 Werkt, maar loopt vast 2016-05-30 12:46:49 +02:00
Daniel a80fc69043 .wav file toegevoegt 2016-05-30 11:59:36 +02:00
Daniel 0c73b5a586 Settings aangepast, als het goed is zit het er nu volledig in 2016-05-30 11:58:34 +02:00
Daniel b53bcac528 OpenAL Test 2016-05-30 11:04:09 +02:00
221 changed files with 54949 additions and 784 deletions
+76
View File
@@ -0,0 +1,76 @@
#include "Button.h"
#include <string>
#include "Util.h"
#include "Vector.h"
#include "Cursor.h"
Button::Button(const std::string & text, Vec2f position, float width, float height) : Text(text,position)
{
this->width = width;
this->height = height;
this->planePosition = position;
cursorOnButton = false;
alfa = 0.5f;
background = Vec3f(10, 10, 10);
//foreground = Vec3f(255, 255, 255);
this->setColor(Vec3f(255, 255, 255));
this->position.x += width / 2 - textWidth / 2;
this->position.y += height / 2 - textHeight / 2;
}
Button::~Button()
{
/*if (action != nullptr)
delete action;*/
}
void Button::draw(void)
{
glColor4f(background.x/255.0f, background.y / 255.0f, background.z / 255.0f, alfa);
glBegin(GL_QUADS);
glVertex2f(planePosition.x, planePosition.y);
glVertex2f(planePosition.x, planePosition.y + height);
glVertex2f(planePosition.x + width, planePosition.y + height);
glVertex2f(planePosition.x + width, planePosition.y);
glEnd();
/*glColor4f(foreground.x / 255.0f, foreground.y / 255.0f, foreground.z / 255.0f, 1.0f);
Util::glutBitmapString(text, position.x, position.y+height/2+14/2);*/
Text::draw();
}
void Button::update(int x, int y)
{
cursorOnButton =
(x > planePosition.x && x < planePosition.x + width) &&
y > planePosition.y && y < planePosition.y + height;
if (cursorOnButton)
alfa = 1.0f;
else
alfa = 0.5f;
if (cursorOnButton && Cursor::getInstance()->clicked)
if(action != nullptr)
action(this);
}
void Button::addAction(action_function action)
{
this->action = action;
}
void Button::setForeground(Vec3f color)
{
this->setColor(color);
}
void Button::setBackground(Vec3f color)
{
background = color;
}
+30
View File
@@ -0,0 +1,30 @@
#pragma once
#include "Text.h"
class Button : public Text
{
private:
typedef void(*action_function)(Button* b);
float width, height;
Vec3f background;
Vec2f planePosition;
bool cursorOnButton;
float alfa;
action_function action = nullptr;
public:
Button(const std::string &text, Vec2f position, float width, float height);
~Button();
void draw();
void update(int x, int y);
void addAction(action_function action);
void setForeground(Vec3f color);
void setBackground(Vec3f color);
};
+6 -4
View File
@@ -1,15 +1,17 @@
cmake_minimum_required(VERSION 3.5)
project(CrystalPoint)
file(GLOB SOURCE_FILES
file(GLOB_RECURSE SOURCE_FILES
"*.h"
"*.cpp"
"*.cc"
)
add_executable(CrystalPoint ${SOURCE_FILES})
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} )
target_link_libraries(CrystalPoint ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall ")
find_package(OpenAL REQUIRED)
include_directories( ${OPENGL_INCLUDE_DIRS} ${GLUT_INCLUDE_DIRS} ${OPENAL_INCLUDE_DIRS} )
target_link_libraries(CrystalPoint ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${OPENAL_LIBRARY} )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -lpthread")
+42
View File
@@ -0,0 +1,42 @@
//
// Created by janco on 5/24/16.
//
#include "Controller.h"
Controller::Controller(int controllerId) {
this->controllerId = controllerId;
this->ypr = Vec3f();
this->joystick = Vec2f();
this->setConnected(false);
this->setConnected(true);
}
Controller::~Controller() { }
void Controller::rumble(int duration, int power){
// controllerhandler->rumble(controllerId, duration, power);
}
void Controller::setConnected(bool connected) {
if(connected){
this->connected = true;
}else{
this->connected = false;
this->ypr = Vec3f(0,0,0);
this->joystick = Vec2f(0,0);
this->button = false;
this->magnetSwitch = false;
this ->joystickButton = false;
}
}
bool Controller::isConnected(void) {
return connected;
}
+20
View File
@@ -0,0 +1,20 @@
#pragma once
#include "Vector.h"
class Controller{
public:
Controller(int controllerId);
~Controller();
Vec3f ypr;
Vec2f joystick;
bool button, joystickButton, magnetSwitch;
int controllerId;
void setConnected(bool connected);
bool isConnected(void);
void rumble(int duration, int power);
private:
bool connected = false;
};
+154
View File
@@ -0,0 +1,154 @@
//
// Created by janco on 5/23/16.
//
#include "ControllerHandler.h"
#include <iostream>
/*
* String split helper functions
*/
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
elems.push_back(item);
}
return elems;
}
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
split(s, delim, elems);
return elems;
}
ControllerHandler::ControllerHandler(){
readthread = std::thread(&ControllerHandler::BasestationReader, this);
};
Controller* ControllerHandler::getLeftController(void){
for (int i = 0; i < 4; i++)
{
if(controllers[i] != nullptr && controllers[i]->isConnected()){
return controllers[i];
}
}
return nullptr;
}
Controller* ControllerHandler::getRightController(void){
bool c1found = false;
for (int i = 0; i < 4; i++)
{
if(controllers[i] != nullptr && controllers[i]->isConnected()){
if(c1found){
return controllers[i];
}
c1found = true;
}
}
return nullptr;
}
void ControllerHandler::SearchBasestation(void){
basestationFound = false;
std::vector<serial::PortInfo> devices_found = serial::list_ports();
std::vector<serial::PortInfo>::iterator iter = devices_found.begin();
while( iter != devices_found.end() )
{
serial::PortInfo device = *iter++;
if(device.hardware_id == "USB VID:PID=10c4:ea60 SNR=02133"){
basestationFound = true;
baseStation = new serial::Serial(device.port, BasestationBaudrate, serial::Timeout::simpleTimeout(1000));
break;
}
}
}
void ControllerHandler::rumble(int idController, int duration, int power){
if (basestationFound)
{
char sendbuffer[16];
sprintf(sendbuffer, "1|%01d|%06d|%03d\n", idController, duration, power);
baseStation->write(sendbuffer);
}
}
/*
* Reading from basestation
*/
void ControllerHandler::BasestationReader() {
while(1){
while(!basestationFound){
SearchBasestation();
if(basestationFound){
baseStation ->write("stop\n");
baseStation ->write("clientlist\n");
}
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
}
while(baseStation->isOpen()){
std::string basestationMessage = baseStation->readline();
std::vector<std::string> basestationMessageSplit = split(basestationMessage, '|');
if(basestationMessageSplit.size() > 1){ //Valid message
std::cout << "DEBUG: Message received. Length: " << basestationMessageSplit.size() << " Type: " << basestationMessageSplit[0] << " Message: " << basestationMessage;
int messageId = std::stoi(basestationMessageSplit[0]);
switch(messageId){
//commandList[messageId](basestationMessageSplit);
case 0: commandDebug(basestationMessageSplit); break; //Debug message
case 1: commandControllerData(basestationMessageSplit); break; //Data from controller
case 2: commandControllerEvent(basestationMessageSplit); break; //Controller events
case 3: commandControllerList(basestationMessageSplit); break; //Connected controller list
}
}
}
}
}
void ControllerHandler::commandDebug(std::vector<std::string> data) {
std::cout << "DEBUG: " << data[1];
}
void ControllerHandler::commandControllerData(std::vector<std::string> data) {
if(data.size() == 10){
Controller* c = controllers[std::stoi(data[1])];
if(c != nullptr && c->isConnected()){
c->ypr.x = std::stoi(data[5])/100.0f;
c->ypr.y = std::stoi(data[6])/100.0f;
c->ypr.z = std::stoi(data[7])/100.0f;
c->joystick.x = std::stoi(data[2])/2000.0f;
c->joystick.y = std::stoi(data[3])/2000.0f;
c->joystickButton = !(data[4] == "0");
c->magnetSwitch = !(data[9] == "0");
}
}
}
void ControllerHandler::commandControllerEvent(std::vector<std::string> data) {
if(data.size() == 3){
if(data[1] == "connected"){
int controllerId = std::stoi(data[2]);
controllers[controllerId] = new Controller(controllerId);
controllers[controllerId]->setConnected(true);
}else if(data[1] == "disconnected"){
// controllers.erase(*controllers[std::stoi(data[2])]);
}
}
}
void ControllerHandler::commandControllerList(std::vector<std::string> data) {
for(unsigned int i = 1; i < data.size() - 1; i++){
int controllerId = std::stoi(data[i]);
controllers[controllerId] = new Controller(controllerId);
rumble(controllerId, 100, 100);
}
if(basestationFound)
baseStation->write("start\n");
}
+41
View File
@@ -0,0 +1,41 @@
#pragma once
//
// Created by janco on 5/23/16.
//
#define BasestationBaudrate 115200
#include <thread>
#ifdef WIN32
#include "include/serial.h"
#else
#include "lib/serial/include/serial.h"
#endif
#include "Controller.h"
class ControllerHandler{
public:
ControllerHandler();
Controller* getLeftController(void);
Controller* getRightController(void);
void rumble(int idController, int duration, int power);
private:
void SearchBasestation(void);
void BasestationReader(void);
bool basestationFound;
serial::Serial *baseStation;
std::thread readthread;
Controller* controllers[4];
//Command functions
void commandDebug(std::vector<std::string> data);
void commandControllerData(std::vector<std::string> data);
void commandControllerEvent(std::vector<std::string> data);
void commandControllerList(std::vector<std::string> data);
//void(*commandList [1])(std::vector<std::string> data);
};
+57
View File
@@ -0,0 +1,57 @@
#include "Crystal.h"
#include "Model.h"
#include "Player.h"
Crystal::Crystal(const std::string & filled, const std::string & empty, const Vec3f & position, Vec3f & rotation, const float & scale)
{
this->filled = Model::load(filled);
this->empty = Model::load(empty);
model = this->filled;
this->position = position;
this->rotation = rotation;
this->scale = scale;
this->canCollide = true;
isFilled = true;
sound_id = CrystalPoint::GetSoundSystem().LoadSound("WAVE/Crystal.wav", false);
music = CrystalPoint::GetSoundSystem().GetSound(sound_id);
music->SetPos(position, Vec3f());
crystalRot = 0;
}
Crystal::~Crystal()
{
CrystalPoint::GetSoundSystem().UnloadSound(sound_id);
if (model)
Model::unload(model);
//if isfilled, means model is model filled, so model empty has to been deleted.
//if is not filled, means model is model empty, so model filled has to been deleted.
if (isFilled)
if(empty)
Model::unload(empty);
else
if(filled)
Model::unload(filled);
}
void Crystal::draw()
{
crystalRot -= 3.0f;
rotation = Vec3f(0, crystalRot, 0);
Entity::draw();
}
void Crystal::collide()
{
if (isFilled)
{
music->Play();
Player::getInstance()->crystals++;
isFilled = false;
model = empty;
}
}
+23
View File
@@ -0,0 +1,23 @@
#pragma once
#include "Entity.h"
#include <string>
#include "CrystalPoint.h"
class Crystal :
public Entity
{
public:
Crystal(const std::string &filled, const std::string &empty,
const Vec3f &position, Vec3f &rotation, const float &scale);
~Crystal();
float crystalRot;
bool isFilled;
void draw();
void collide();
private:
int sound_id;
Sound* music;
Model* filled;
Model* empty;
};
+125 -19
View File
@@ -5,21 +5,31 @@
#include <cstring>
#include "WorldHandler.h"
#include "Player.h"
#include "Cursor.h"
#include "Menu.h"
#include "Text.h"
#include "Vector.h"
#include "Button.h"
int CrystalPoint::width = 0;
int CrystalPoint::height = 0;
SoundSystem CrystalPoint::sound_system;
bool state = false;
void CrystalPoint::init()
{
player = Player::getInstance();
worldhandler = WorldHandler::getInstance();
//cursor = Cursor::getInstance();
cursor = Cursor::getInstance();
menu = new Menu();
menuIsBuild = false;
lastFrameTime = 0;
state = true;
glClearColor(0.7, 0.7, 1.0, 1.0);
mousePosition = Vec2f(width / 2, height / 2);
glClearColor(0.7f, 0.7f, 1.0f, 1.0f);
}
@@ -37,9 +47,11 @@ void CrystalPoint::draw()
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
worldhandler->draw();
//cursor->draw();
if(!state)
menu->draw();
glutSwapBuffers();
}
@@ -51,45 +63,139 @@ void CrystalPoint::update()
float deltaTime = frameTime - lastFrameTime;
lastFrameTime = frameTime;
if (keyboardState.keys[27] && !prevKeyboardState.keys[27])
state = !state;
if (state)
{
Player* player = Player::getInstance();
if (keyboardState.special[GLUT_KEY_LEFT] && !prevKeyboardState.special[GLUT_KEY_LEFT])
worldhandler->PreviousWorld();
if (keyboardState.special[GLUT_KEY_RIGHT] && !prevKeyboardState.special[GLUT_KEY_RIGHT])
worldhandler->NextWorld();
if (keyboardState.special[GLUT_KEY_UP] && !prevKeyboardState.special[GLUT_KEY_UP])
player->NextLeftWeapon();
if (keyboardState.special[GLUT_KEY_DOWN] && !prevKeyboardState.special[GLUT_KEY_DOWN])
player->PreviousLeftWeapon();
if (keyboardState.keys[27])
exit(0);
state = false;
Player* player = Player::getInstance();
//testing code
if (keyboardState.keys['u'])
player->HpUp(1);
if (keyboardState.keys['i'])
player->HpDown(1);
if (keyboardState.keys['o'])
player->XpUp(1);
player->rotation.y += mouseOffset.x / 10.0f;
player->rotation.x += mouseOffset.y / 10.0f;
if (player->rotation.x > 90)
player->rotation.x = 90;
if (player->rotation.x < -90)
player->rotation.x = -90;
float speed = 1;
float speed = 10;
Vec3f oldPosition = player->position;
if (keyboardState.keys['a']) player->setPosition(0, deltaTime*speed, false);
if (keyboardState.keys['d']) player->setPosition(180, deltaTime*speed, false);
if (keyboardState.keys['w']) player->setPosition(90, deltaTime*speed, false);
if (keyboardState.keys['s']) player->setPosition(270, deltaTime*speed, false);
//if (keyboardState.keys['q']) player->setPosition(1, deltaTime*speed, true);
//if (keyboardState.keys['e']) player->setPosition(-1, deltaTime*speed, true);
if (keyboardState.keys['q']) player->setPosition(1, deltaTime*speed, true);
if (keyboardState.keys['e']) player->setPosition(-1, deltaTime*speed, true);
Controller *leftcontroller = controller.getLeftController();
if (leftcontroller != nullptr) {
Vec2f *leftControllerJoystick = &leftcontroller->joystick;
if (leftcontroller->joystickButton) {
controller.rumble(leftcontroller->controllerId, 100, 100);
}
if (leftControllerJoystick->y > 0.3) {
player->setPosition(270, leftControllerJoystick->y * deltaTime * 2.0f, false);
}
else if (leftControllerJoystick->y < -0.3) {
player->setPosition(90, leftControllerJoystick->y * -1 * deltaTime * 2.0f, false);
}
if (leftControllerJoystick->x > 0.3) {
player->setPosition(180, leftControllerJoystick->x * deltaTime * 2.0f, false);
}
else if (leftControllerJoystick->x < -0.3) {
player->setPosition(0, leftControllerJoystick->x * -1 * deltaTime * 2.0f, false);
}
player->leftWeapon->rotateWeapon(Vec3f(leftcontroller->ypr.y + 140, 0, -leftcontroller->ypr.z));
}
Controller *rightcontroller = controller.getRightController();
if(rightcontroller != nullptr){
Vec2f *rightControllerJoystick = &rightcontroller->joystick;
if (rightControllerJoystick->y > 0.3 || rightControllerJoystick->y < -0.3) {
player->rotation.x += rightcontroller->joystick.y/4;
}
if (rightControllerJoystick->x > 0.3 || rightControllerJoystick->x < -0.3) {
player->rotation.y += rightcontroller->joystick.x/4;
}
player->rightWeapon->rotateWeapon(Vec3f(rightcontroller->ypr.y + 140, 0, -rightcontroller->ypr.z));
}
if (player->rotation.x > 90)
player->rotation.x = 90;
if (player->rotation.x < -90)
player->rotation.x = -90;
player->position.y = worldhandler->getHeight(player->position.x, player->position.z) + 1.7f;
if (!worldhandler->isPlayerPositionValid())
player->position = oldPosition;
player->position.y = worldhandler->getHeight(player->position.x, player->position.z) + 0.7f;
/*else if (player->position.y > oldPosition.y + 1.2)
player->position = oldPosition;
*/
worldhandler->update(deltaTime);
}
else
{
if (!menuIsBuild)
{
buildMenu();
menuIsBuild = true;
}
menu->update();
cursor->update(cursor->mousePosition + mouseOffset);
}
mousePosition = mousePosition + mouseOffset;
//cursor->update(mousePosition);
mouseOffset = Vec2f(0, 0);
prevKeyboardState = keyboardState;
glutPostRedisplay();
sound_system.SetListener(player->position, Vec3f(), Vec3f());
}
void CrystalPoint::buildMenu()
{
Button* start = new Button("Resume", Vec2f(width / 2 - 50, height / 2 - 30), 100, 50);
auto toWorld = [](Button* b)
{
state = true;
};
start->addAction(toWorld);
menu->AddMenuElement(start);
Button* test = new Button("Exit", Vec2f(width / 2 - 50, height / 2 + 30), 100, 50);
test->addAction([](Button* b)
{
exit(0);
});
menu->AddMenuElement(test);
Text* t = new Text("Pause", Vec2f(width / 2 - Util::glutTextWidth("Pause") / 2, height / 2 - 75));
t->setColor(Vec3f(255, 255, 0));
menu->AddMenuElement(t);
}
+15
View File
@@ -1,8 +1,13 @@
#pragma once
class WorldHandler;
class SoundSystem;
class Player;
class Cursor;
class Menu;
#include "Vector.h"
#include "SoundSystem.h"
#include "ControllerHandler.h"
class KeyboardState
{
@@ -23,6 +28,9 @@ public:
WorldHandler* worldhandler;
Player* player;
ControllerHandler controller;
Cursor* cursor;
Menu* menu;
static int width, height;
KeyboardState keyboardState;
@@ -33,4 +41,11 @@ public:
float lastFrameTime;
static SoundSystem& GetSoundSystem() { return sound_system; }
bool menuIsBuild;
private:
static SoundSystem sound_system;
void buildMenu();
};
+53 -7
View File
@@ -89,12 +89,13 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile />
<AdditionalIncludeDirectories>freeglut/include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>lib/serial;freeglut/include; openAL/include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>freeglut/lib</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>freeglut/lib; openAL/libs/Win32</AdditionalLibraryDirectories>
<AdditionalDependencies>setupapi.lib;openal32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@@ -104,12 +105,13 @@
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile />
<AdditionalIncludeDirectories>freeglut/include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>lib/serial;freeglut/include;C:\Program Files (x86)\OpenAL 1.1 SDK\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>freeglut/lib</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>freeglut/lib;C:\Program Files (x86)\OpenAL 1.1 SDK\libs\Win32</AdditionalLibraryDirectories>
<AdditionalDependencies>setupapi.lib;openal32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -121,14 +123,15 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile />
<AdditionalIncludeDirectories>freeglut/include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>lib/serial;freeglut/include; openAL/include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>freeglut/lib</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>freeglut/lib; openAL/libs/Win32</AdditionalLibraryDirectories>
<AdditionalDependencies>setupapi.lib;openal32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -140,7 +143,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile />
<AdditionalIncludeDirectories>freeglut/include</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>lib/serial;freeglut/include;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -148,9 +151,14 @@
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>freeglut/lib</AdditionalLibraryDirectories>
<AdditionalDependencies>setupapi.lib;openal32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Button.cpp" />
<ClCompile Include="Controller.cpp" />
<ClCompile Include="ControllerHandler.cpp" />
<ClCompile Include="Crystal.cpp" />
<ClCompile Include="CrystalPoint.cpp" />
<ClCompile Include="Cursor.cpp" />
<ClCompile Include="Enemy.cpp" />
@@ -159,15 +167,32 @@
<ClCompile Include="Interface.cpp" />
<ClCompile Include="json.cpp" />
<ClCompile Include="LevelObject.cpp" />
<ClCompile Include="lib\serial\src\impl\list_ports\list_ports_win.cc" />
<ClCompile Include="lib\serial\src\impl\win.cc" />
<ClCompile Include="lib\serial\src\serial.cc" />
<ClCompile Include="LoadingScreen.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="Menu.cpp" />
<ClCompile Include="MenuElement.cpp" />
<ClCompile Include="Model.cpp" />
<ClCompile Include="Portal.cpp" />
<ClCompile Include="Sound.cpp" />
<ClCompile Include="SoundSystem.cpp" />
<ClCompile Include="Player.cpp" />
<ClCompile Include="Skybox.cpp" />
<ClCompile Include="Text.cpp" />
<ClCompile Include="Util.cpp" />
<ClCompile Include="Vector.cpp" />
<ClCompile Include="Vertex.cpp" />
<ClCompile Include="Weapon.cpp" />
<ClCompile Include="World.cpp" />
<ClCompile Include="WorldHandler.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Button.h" />
<ClInclude Include="Controller.h" />
<ClInclude Include="ControllerHandler.h" />
<ClInclude Include="Crystal.h" />
<ClInclude Include="CrystalPoint.h" />
<ClInclude Include="Cursor.h" />
<ClInclude Include="Enemy.h" />
@@ -176,21 +201,42 @@
<ClInclude Include="Interface.h" />
<ClInclude Include="json.h" />
<ClInclude Include="LevelObject.h" />
<ClInclude Include="lib\serial\include\impl\win.h" />
<ClInclude Include="lib\serial\include\serial.h" />
<ClInclude Include="lib\serial\include\v8stdint.h" />
<ClInclude Include="LoadingScreen.h" />
<ClInclude Include="Main.h" />
<ClInclude Include="Menu.h" />
<ClInclude Include="MenuElement.h" />
<ClInclude Include="Model.h" />
<ClInclude Include="Portal.h" />
<ClInclude Include="Sound.h" />
<ClInclude Include="SoundSystem.h" />
<ClInclude Include="Player.h" />
<ClInclude Include="Skybox.h" />
<ClInclude Include="stb_image.h" />
<ClInclude Include="Text.h" />
<ClInclude Include="Util.h" />
<ClInclude Include="vector.h" />
<ClInclude Include="Vertex.h" />
<ClInclude Include="Weapon.h" />
<ClInclude Include="World.h" />
<ClInclude Include="WorldHandler.h" />
</ItemGroup>
<ItemGroup>
<None Include="weapons.json" />
<None Include="worlds\fire.json" />
<None Include="worlds\ice.json" />
<None Include="worlds\rock.json" />
<None Include="worlds\small.json" />
<None Include="worlds\worlds.json" />
</ItemGroup>
<ItemGroup>
<Media Include="WAVE\Crystal.wav" />
<Media Include="WAVE\ghostEnemy.wav" />
<Media Include="WAVE\portal.wav" />
<Media Include="WAVE\world1.wav" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
+128
View File
@@ -22,6 +22,9 @@
<Filter Include="Source Files\json">
<UniqueIdentifier>{9c655946-3f99-44ea-bc97-2817656954e0}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Serial">
<UniqueIdentifier>{98128574-9e08-4c28-9372-8d50b6e1a101}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Main.cpp">
@@ -69,6 +72,60 @@
<ClCompile Include="Interface.cpp">
<Filter>Source Files\World</Filter>
</ClCompile>
<ClCompile Include="Skybox.cpp">
<Filter>Source Files\World</Filter>
</ClCompile>
<ClCompile Include="Crystal.cpp">
<Filter>Source Files\Object</Filter>
</ClCompile>
<ClCompile Include="SoundSystem.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Sound.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Crystal.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Portal.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Controller.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ControllerHandler.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="lib\serial\src\impl\list_ports\list_ports_win.cc">
<Filter>Source Files\Serial</Filter>
</ClCompile>
<ClCompile Include="lib\serial\src\impl\win.cc">
<Filter>Source Files\Serial</Filter>
</ClCompile>
<ClCompile Include="lib\serial\src\serial.cc">
<Filter>Source Files\Serial</Filter>
</ClCompile>
<ClCompile Include="Weapon.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Button.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Menu.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MenuElement.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Text.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Util.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="LoadingScreen.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="World.h">
@@ -119,6 +176,57 @@
<ClInclude Include="vector.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SoundSystem.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Sound.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Crystal.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Skybox.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Portal.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ControllerHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Controller.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="lib\serial\include\serial.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="lib\serial\include\v8stdint.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="lib\serial\include\impl\win.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Weapon.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Button.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Menu.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MenuElement.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Text.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Util.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LoadingScreen.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="worlds\worlds.json">
@@ -133,5 +241,25 @@
<None Include="worlds\small.json">
<Filter>Source Files\json</Filter>
</None>
<None Include="worlds\rock.json">
<Filter>Source Files\json</Filter>
</None>
<None Include="weapons.json">
<Filter>Source Files\json</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Media Include="WAVE\Crystal.wav">
<Filter>Resource Files</Filter>
</Media>
<Media Include="WAVE\portal.wav">
<Filter>Resource Files</Filter>
</Media>
<Media Include="WAVE\ghostEnemy.wav">
<Filter>Resource Files</Filter>
</Media>
<Media Include="WAVE\world1.wav">
<Filter>Resource Files</Filter>
</Media>
</ItemGroup>
</Project>
+23 -1
View File
@@ -1,5 +1,5 @@
#include "Cursor.h"
#include <GL\freeglut.h>
#include <GL/freeglut.h>
#include <cmath>
#include "CrystalPoint.h"
@@ -8,10 +8,13 @@ Cursor* Cursor::instance = NULL;
Cursor::Cursor()
{
enabled = false;
mousePosition = Vec2f(CrystalPoint::width / 2, CrystalPoint::height / 2);
clicked = false;
}
Cursor::~Cursor()
{
}
Cursor* Cursor::getInstance(void)
@@ -54,5 +57,24 @@ void Cursor::draw(void)
void Cursor::update(Vec2f newPosition)
{
if (newPosition.x < 0)
newPosition.x = 0;
if (newPosition.y < 0)
newPosition.y = 0;
if (newPosition.x > CrystalPoint::width)
newPosition.x = CrystalPoint::width;
if (newPosition.y > CrystalPoint::height)
newPosition.y = CrystalPoint::height;
mousePosition = newPosition;
if (clicked)
clicked = !clicked;
if (state != prev)
if(state == GLUT_UP)
clicked = true;
prev = state;
}
+6 -2
View File
@@ -8,9 +8,9 @@ private:
static Cursor* instance;
bool enabled;
Vec2f mousePosition;
public:
public:
Vec2f mousePosition;
~Cursor();
static Cursor* getInstance(void);
@@ -18,6 +18,10 @@ public:
void enable(bool enable);
bool isEnabled(void);
bool clicked;
int state, prev;
void draw(void);
void update(Vec2f newPosition);
};
+44 -14
View File
@@ -1,14 +1,15 @@
#define _USE_MATH_DEFINES
#include <cmath>
#include "Enemy.h"
#include "Model.h"
#include <iostream>
Enemy::Enemy(const std::string &fileName,
const std::string &fileMusic,
float damage,
float health,
const Vec3f &position,
Vec3f &rotation,
const Vec3f &rotation,
const float &scale)
{
model = Model::load(fileName);
@@ -19,12 +20,22 @@ Enemy::Enemy(const std::string &fileName,
target = position;
speed = 1;
radius = 10;
xp = health;
this->health = health;
this->damage = damage;
hasTarget = false;
hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound(fileMusic.c_str(), false);
music = CrystalPoint::GetSoundSystem().GetSound(hit_sound_id);
attack = false;
}
Enemy::~Enemy()
{
music->Stop();
CrystalPoint::GetSoundSystem().UnloadSound(hit_sound_id);
if (model)
Model::unload(model);
}
@@ -32,26 +43,39 @@ Enemy::~Enemy()
void Enemy::draw()
{
Entity::draw();
glPushMatrix();
}
glTranslatef(position.x, position.y, position.z);
glBegin(GL_LINE_LOOP);
for (int i = 0; i < 360; i++)
void Enemy::inEyeSight(Vec3f & TargetPosition)
{
if (position.Distance(TargetPosition) <= radius)
{
//convert degrees into radians
float degInRad = i*(M_PI / 180.0);
glVertex3f(cos(degInRad)*radius, 1*scale,sin(degInRad)*radius);
hasTarget = true;
target = TargetPosition;
}
glEnd();
else
hasTarget = false;
}
glPopMatrix();
void Enemy::collide(const Entity * entity)
{
Vec3f difference = position - entity->position; //zou misschien omgedraait moeten worden
difference.y = 0;
difference.Normalize();
difference = difference * (entity->model->radius + 0.01f);
position.x = difference.x + entity->position.x;
position.z = difference.z + entity->position.z;
}
void Enemy::update(float delta)
{
music->SetPos(position, Vec3f());
if (hasTarget)
{
if (music->IsPlaying() == false)
{
music->Play();
}
//just 2d walking
float dx, dz, length;
@@ -59,8 +83,10 @@ void Enemy::update(float delta)
dz = target.z - position.z;
length = sqrt(dx*dx + dz*dz);
if (length > 0.03)
if (length > 1)
{
attack = false;
dx /= length;
dz /= length;
@@ -70,6 +96,10 @@ void Enemy::update(float delta)
position.x += dx;
position.z += dz;
}
else
{
attack = true;
}
rotation.y = atan2f(dx, dz) * 180 / M_PI;
}
}
+13 -1
View File
@@ -3,18 +3,30 @@
#include "Entity.h"
#include <string>
#include "Vector.h"
#include "CrystalPoint.h"
class Enemy : public Entity
{
public:
Enemy(const std::string &fileName,const Vec3f &position,Vec3f &rotation,const float &scale);
Enemy(const std::string &fileName, const std::string &fileMusic, float damage, float health, const Vec3f &position, const Vec3f &rotation, const float &scale);
~Enemy();
Sound* music;
bool hasTarget;
Vec3f target;
float speed,radius;
float health;
float damage;
int xp;
bool attack;
void update(float);
void draw();
void inEyeSight(Vec3f &);
void collide(const Entity *entity);
private:
int hit_sound_id;
};
-2
View File
@@ -25,13 +25,11 @@ void Entity::draw()
{
glPushMatrix();
glTranslatef(position.x, position.y, position.z);
glRotatef(rotation.x, 1, 0, 0);
glRotatef(rotation.y, 0, 1, 0);
glRotatef(rotation.z, 0, 0, 1);
glScalef(scale, scale, scale);
//collision gaat hierdoor kapot glTranslatef(-model->center.x, 0, -model->center.z);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
+2
View File
@@ -13,6 +13,8 @@ public:
virtual void draw();
virtual void update(float elapsedTime) {};
virtual void collide() {};
Vec3f position;
Vec3f rotation;
float scale;
+41 -11
View File
@@ -1,6 +1,6 @@
#include "HeightMap.h"
#include "stb_image.h"
#include "vector.h"
#include "Vector.h"
#include "LevelObject.h"
@@ -29,28 +29,51 @@ HeightMap::HeightMap(const std::string &file, World* world)
return imgData[(x + y * width) * 4 + offset];
};
std::vector<std::vector<Vec3f>> faceNormals(width-1, std::vector<Vec3f>(height-1, Vec3f(0,1,0)));
for (int y = 0; y < height - 1; y++)
{
for (int x = 0; x < width - 1; x++)
{
int offsets[4][2] = { { 0, 0 },{ 1, 0 },{ 1, 1 },{ 0, 1 } };
Vec3f ca(0, heightAt(x, y + 1) - heightAt(x, y), 1);
Vec3f ba(1, heightAt(x + 1, y) - heightAt(x, y), 0);
Vec3f normal = ca.cross(ba);
normal.Normalize();
faceNormals[x][y] = normal;
}
}
for (int y = 0; y < height-1; y++)
{
for (int x = 0; x < width-1; x++)
{
int offsets[4][2] = { { 0, 0 },{ 1, 0 },{ 1, 1 },{ 0, 1 } };
Vec3f ca(0, heightAt(x, y + 1) - heightAt(x, y), 1);
Vec3f ba(1, heightAt(x + 1, y) - heightAt(x, y), 0);
if (valueAt(x, y, GREEN) > 0)
if (valueAt(x, y, GREEN) > 5)
{
world->addLevelObject(new LevelObject(world->getObjectFromValue(valueAt(x, y, GREEN)).first, Vec3f(x, heightAt(x, y), y), Vec3f(0, rand()%360, 0), 1, world->getObjectFromValue(valueAt(x, y, GREEN)).second));
world->addLevelObject(new LevelObject(world->getObjectFromValue(valueAt(x, y, GREEN)).first, Vec3f(x, heightAt(x, y), y), Vec3f(0, 0, 0), 1, world->getObjectFromValue(valueAt(x, y, GREEN)).second));
}
Vec3f normal = ca.cross(ba);
normal.Normalize();
for (int i = 0; i < 4; i++)
{
float h = heightAt(x + offsets[i][0], y + offsets[i][1]);
vertices.push_back(Vertex{ (float)(x + offsets[i][0]), h, (float)(y + offsets[i][1]),
int xx = x + offsets[i][0];
int yy = y + offsets[i][1];
Vec3f normal(0, 0, 0);
if(xx < width-1 && yy < height-1)
normal = normal + faceNormals[xx][yy];
if(xx > 0 && yy < height-1)
normal = normal + faceNormals[xx-1][yy];
if (xx > 0 && yy > 0)
normal = normal + faceNormals[xx-1][yy-1];
if (yy > 0 && xx < width-1)
normal = normal + faceNormals[xx][yy-1];
normal.Normalize();
float h = heightAt(xx, yy);
vertices.push_back(Vertex{ (float)(xx), h, (float)(yy),
normal.x, normal.y, normal.z,
(x + offsets[i][0]) / (float)height, (y + offsets[i][1]) / (float)width } );
(xx) / (float)height, (yy) / (float)width } );
}
}
}
@@ -127,10 +150,17 @@ float HeightMap::GetHeight(float x, float y)
float labda3 = 1 - labda1 - labda2;
Vertex z = a * labda1 + b * labda2 + c * labda3;
// Vertex z = (a * labda1) + (b * labda2) ;
return z.y;
}
int HeightMap::GetSize()
{
return height >= width ? height : width;
}
void HeightMap::SetTexture(const std::string &file)
{
int bpp, width2, height2;
+1
View File
@@ -20,6 +20,7 @@ public:
void Draw();
float GetHeight(float x, float y);
int GetSize();
void SetTexture(const std::string &file);
std::vector<Vertex> vertices;
+47 -18
View File
@@ -1,16 +1,26 @@
#include "Interface.h"
#include <GL\freeglut.h>
#include <GL/freeglut.h>
#include "CrystalPoint.h"
#include <string>
#include "Player.h"
//Prototype
void glutBitmapString(std::string str, int x, int y);
#include "Util.h"
Interface::Interface()
{
crystalWidth = 20;
crystalHeight = 50;
crystalOffset = 5;
maxCrystals = 0;
}
Interface::Interface(int maxCrystal)
{
crystalWidth = 20;
crystalHeight = 50;
crystalOffset = 5;
maxCrystals = maxCrystal;
}
@@ -50,8 +60,8 @@ void Interface::draw()
glVertex2f(250, 965);
glColor4f(1.0f, 0.5f, 0.5f, 1.0);
glVertex2f(250 + (player->health / 100 * 500), 965);
glVertex2f(250 + (player->health / 100 * 500), 980);
glVertex2f(250 + (player->health / player->maxHp * 500), 965);
glVertex2f(250 + (player->health / player->maxHp * 500), 980);
glEnd();
//XP bar
@@ -69,26 +79,45 @@ void Interface::draw()
glVertex2f(250, 935);
glColor4f(1.0f, 1.0f, 0.5f, 1.0);
glVertex2f(250 + (player->xp / 100 * 500), 935);
glVertex2f(250 + (player->xp / 100 * 500), 950);
glVertex2f(250 + (player->xp / player->maxXp * 500), 935);
glVertex2f(250 + (player->xp / player->maxXp * 500), 950);
glEnd();
//Text: level
glColor4f(1.0f, 1.0f, 0.1f, 1.0);
glutBitmapString("Level: " + std::to_string(player->level), 490, 900);
Util::glutBitmapString("Level: " + std::to_string(player->level), 490, 900);
//Text: weapons
Util::glutBitmapString(player->leftWeapon->name, 850, 900);
Util::glutBitmapString(player->rightWeapon->name, 10, 900);
for (int i = 0; i < maxCrystals; i++)
{
glBegin(GL_QUADS);
if(i < player->crystals)
glColor4f(0, 1.0f, 1.0f, 1.0f);
else
glColor4f(0, 0.4f, 0.4f, 1.0f);
glVertex2f(975 - crystalWidth / 2 , crystalOffset*i + crystalHeight*i);
glVertex2f(975 - crystalWidth , crystalHeight / 2 + crystalOffset*i + crystalHeight*i);
if (i < player->crystals)
glColor4f(0, 0.7f, 0.7f, 1.0f);
else
glColor4f(0, 0.2f, 0.2f, 1.0f);
glVertex2f(975 - crystalWidth / 2 , crystalHeight + crystalOffset*i + crystalHeight*i);
glVertex2f(975 , crystalHeight / 2 + crystalOffset*i + crystalHeight*i);
glEnd();
}
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
}
void Interface::update(float deltaTime)
{
}
void glutBitmapString(std::string str, int x, int y)
{
glRasterPos2f(x, y);
for (int i = 0; i < str.size(); i++)
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, str[i]);
}
}
+4
View File
@@ -3,9 +3,13 @@ class Interface
{
public:
Interface();
Interface(int);
~Interface();
void draw(void);
void update(float deltaTime);
int crystalWidth, crystalHeight, crystalOffset;
int maxCrystals;
};
+2
View File
@@ -7,6 +7,8 @@ LevelObject::LevelObject(const std::string &fileName, const Vec3f &position, con
{
model = Model::load(fileName);
this->position = position;
this->position.x -= model->center.x;
this->position.z -= model->center.z;
this->rotation = rotation;
this->scale = scale;
this->canCollide = hasCollision;
+71
View File
@@ -0,0 +1,71 @@
#include "stb_image.h"
#include "LoadingScreen.h"
#include "CrystalPoint.h"
#include "Util.h"
#include <ostream>
LoadingScreen::LoadingScreen()
{
points = 0;
}
LoadingScreen::~LoadingScreen()
{
}
void LoadingScreen::draw()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, CrystalPoint::width, CrystalPoint::height, 0, -10, 10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDisable(GL_COLOR_MATERIAL);
glEnable(GL_TEXTURE_2D);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBindTexture(GL_TEXTURE_2D, textureId);
glBegin(GL_QUADS);
glTexCoord2f(0, 1);
glVertex2f(0, 0);
glTexCoord2f(0, 0);
glVertex2f(0, CrystalPoint::height);
glTexCoord2f(1, 0);
glVertex2f(CrystalPoint::width, CrystalPoint::height);
glTexCoord2f(1, 1);
glVertex2f(CrystalPoint::width, 0);
glEnd();
/*glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
std::ostringstream oss;
oss << loading << points << std::endl;
Util::glutBitmapString(oss.str(),
CrystalPoint::width / 2 - Util::glutTextWidth(oss.str()),
CrystalPoint::height / 2 - 7);*/
glDisable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glutSwapBuffers();
}
void LoadingScreen::rise()
{
points++;
draw();
}
void LoadingScreen::setTexture(const std::string filename)
{
textureId = Util::loadTexture(filename);
}
+22
View File
@@ -0,0 +1,22 @@
#pragma once
#include <string>
#include <GL\freeglut.h>
class LoadingScreen
{
public:
LoadingScreen();
~LoadingScreen();
void draw();
void rise();
int points;
GLuint textureId;
void setTexture(const std::string fileName);
private:
const std::string loading = "Loaded: ";
};
+24 -2
View File
@@ -4,6 +4,11 @@
#include <stdio.h>
#include "Vector.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#include "Cursor.h"
void configureOpenGL(void);
CrystalPoint* app;
@@ -50,10 +55,23 @@ int main(int argc, char* argv[])
glutPassiveMotionFunc(mousemotion);
glutMotionFunc(mousemotion);
auto mouseclick = [](int button, int state,
int x, int y)
{
if (button == GLUT_LEFT_BUTTON)
Cursor::getInstance()->state = state;
//std::cout << "Left button is down" << std::endl;
};
glutMouseFunc(mouseclick);
CrystalPoint::height = GLUT_WINDOW_HEIGHT;
CrystalPoint::width = GLUT_WINDOW_WIDTH;
glutMainLoop();
delete app;
return 0;
}
@@ -61,9 +79,12 @@ void configureOpenGL()
{
//Init window and glut display mode
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutInitWindowSize(1440, 900);
//glutInitWindowPosition((glutGet(GLUT_SCREEN_WIDTH) / 2) - (glutGet(GLUT_WINDOW_WIDTH) / 2), (glutGet(GLUT_SCREEN_HEIGHT) / 2) - (glutGet(GLUT_WINDOW_HEIGHT) / 2));
glutCreateWindow("Crystal Point");
glutFullScreen();
//glutFullScreen();
//Depth testing
glEnable(GL_DEPTH_TEST);
@@ -91,6 +112,7 @@ void configureOpenGL()
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
//glEnable(GL_COLOR_MATERIAL);
glutSetCursor(GLUT_CURSOR_NONE);
}
+59
View File
@@ -0,0 +1,59 @@
#include <GL/freeglut.h>
#include "Menu.h"
#include "CrystalPoint.h"
Menu::Menu()
{
cursor = Cursor::getInstance();
}
Menu::~Menu()
{
}
void Menu::draw(void)
{
//Switch view to Ortho
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, CrystalPoint::width, CrystalPoint::height, 0, -10, 10);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDisable(GL_TEXTURE_2D);
glColor4f(60/255.0f, 60/255.0f, 60/255.0f, 0.8f);
glBegin(GL_QUADS);
glVertex2f(0,0);
glVertex2f(0, CrystalPoint::height);
glVertex2f(CrystalPoint::width, CrystalPoint::height);
glVertex2f(CrystalPoint::width, 0);
glEnd();
for (MenuElement* e : elements)
{
e->draw();
}
cursor->draw();
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
}
void Menu::update()
{
for (MenuElement* e : elements)
{
e->update(cursor->mousePosition.x, cursor->mousePosition.y);
}
}
void Menu::AddMenuElement(MenuElement * e)
{
elements.push_back(e);
}
+20
View File
@@ -0,0 +1,20 @@
#pragma once
#include <vector>
#include "MenuElement.h"
#include "Cursor.h"
class Menu
{
private:
std::vector<MenuElement*> elements;
Cursor* cursor;
public:
Menu();
~Menu();
void draw(void);
void update(void);
void AddMenuElement(MenuElement* e);
};
+12
View File
@@ -0,0 +1,12 @@
#include "MenuElement.h"
MenuElement::MenuElement(Vec2f position)
{
hover = false;
this->position = position;
}
MenuElement::~MenuElement()
{
}
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#include "Vector.h"
#include <string>
class MenuElement
{
protected:
bool hover;
Vec2f position;
public:
MenuElement(Vec2f position);
~MenuElement();
virtual void draw(void) {};
virtual void update(int x, int y) {};
};
+5 -7
View File
@@ -1,6 +1,5 @@
#include "Model.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#include <iostream>
@@ -8,6 +7,7 @@
#include <string>
#include <algorithm>
#include <cmath>
#include <cstring>
//Prototypes
std::vector<std::string> split(std::string str, std::string sep);
@@ -138,7 +138,7 @@ Model::Model(std::string fileName)
radius = fmax(radius, (center.x - v.x) * (center.x - v.x) + (center.z - v.z) * (center.z - v.z));
radius = sqrt(radius);
for each(ObjGroup *group in groups)
for (ObjGroup *group : groups)
{
Optimise(group);
}
@@ -148,7 +148,7 @@ void Model::Optimise(ObjGroup *t)
{
for (Face &face : t->faces)
{
for each(auto &vertex in face.vertices)
for (auto &vertex : face.vertices)
{
t->VertexArray.push_back(Vertex(vertices[vertex.position].x, vertices[vertex.position].y, vertices[vertex.position].z,
normals[vertex.normal].x, normals[vertex.normal].y, normals[vertex.normal].z,
@@ -370,6 +370,7 @@ void Model::unload(Model* model)
{
delete m.second.first;
cache.erase(cache.find(m.first));
break;
}
}
@@ -378,8 +379,5 @@ void Model::unload(Model* model)
Model::~Model(void)
{
for (auto m : cache)
{
delete m.second.first;
}
}
+1 -1
View File
@@ -70,7 +70,7 @@ private:
Model(std::string filename);
~Model(void);
public:
public:
static std::map<std::string, std::pair<Model*, int> > cache;
static Model* load(const std::string &fileName);
+169 -4
View File
@@ -3,14 +3,31 @@
#include "Player.h"
#include <GL/freeglut.h>
#include <string>
#include <iostream>
#include <fstream>
Player* Player::instance = NULL;
Player::Player()
{
speed = 10;
health = 50;
xp = 75;
level = 10;
maxHp = 100;
health = maxHp;
xp = 0;
maxXp = 100;
level = 1;
crystals = 0;
loadWeapons();
currentleftweapon = 0;
leftWeapon = leftweapons[0];
leftWeapon->rotateWeapon(Vec3f(150, 0, 60));
currentrightweapon = 0;
rightWeapon = rightweapons[0];
rightWeapon->rotateWeapon(Vec3f(150, 0, 60));
}
Player* Player::getInstance()
@@ -41,11 +58,13 @@ void Player::setCamera()
glRotatef(rotation.y, 0, 1, 0);
glTranslatef(-position.x, -position.y, -position.z);
leftWeapon->rotate(rotation);
rightWeapon->rotate(rotation);
}
void Player::setPosition(float angle, float fac, bool height)
{
fac *= speed;
if (height)
position.y += angle*fac;
else
@@ -53,4 +72,150 @@ void Player::setPosition(float angle, float fac, bool height)
position.x -= (float)cos((rotation.y + angle) / 180 * M_PI) * fac;
position.z -= (float)sin((rotation.y + angle) / 180 * M_PI) * fac;
}
leftWeapon->move(position);
rightWeapon->move(position);
}
void Player::draw() {
leftWeapon->draw();
rightWeapon->draw();
}
void Player::HpDown(int damage)
{
int newHealth = health - damage;
if (newHealth <= 0)
{
exit(0);
}
health = newHealth;
}
void Player::HpUp(int hp)
{
if (health != maxHp)
{
int newHealth = health + hp;
if (newHealth >= maxHp)
{
newHealth = maxHp;
}
health = newHealth;
}
}
void Player::XpUp(int xpUp)
{
float newXp = xp + xpUp;
if (newXp >= maxXp)
{
newXp -= maxXp;
levelUp();
}
xp = newXp;
}
void Player::levelUp()
{
level++;
maxXp += 50;
maxHp += 10;
health = maxHp;
}
void Player::loadWeapons()
{
std::string fileName = "weapons.json";
//Open world json file
std::ifstream file(fileName);
if (!file.is_open())
std::cout << "Error, can't open world file - " << fileName << "\n";
json::Value v = json::readJson(file);
file.close();
//Check file
if (v["weapons"].isNull())
std::cout << "Invalid weapons file: " << fileName << "\n";
//Load object templates
for (auto w : v["weapons"])
{
Weapon* lweapon;
Weapon* rweapon;
std::string name = w["name"].asString();
std::string fileN = w["file"].asString();
float damage = w["damage"].asFloat();
Weapon::Element e = Weapon::FIRE;
if(w["element"].asString() == "fire")
e = Weapon::FIRE;
else if (w["element"].asString() == "water")
e = Weapon::WATER;
else if (w["element"].asString() == "earth")
e = Weapon::EARTH;
else if (w["element"].asString() == "air")
e = Weapon::AIR;
else
e = Weapon::FIRE;
Vec3f leftoffset = Vec3f(w["left"]["offset"][0].asFloat(), w["left"]["offset"][1].asFloat(), w["left"]["offset"][2].asFloat());
Vec3f rightoffset = Vec3f(w["right"]["offset"][0].asFloat(), w["right"]["offset"][1].asFloat(), w["right"]["offset"][2].asFloat());
Vec3f anchor = Vec3f(w["anchor"][0].asFloat(), w["anchor"][1].asFloat(), w["anchor"][2].asFloat());
Vec3f collision = Vec3f(w["collision"][0].asFloat(), w["collision"][1].asFloat(), w["collision"][2].asFloat());
Vec2f maxRot = Vec2f(w["maxRotation"][0].asFloat(), w["maxRotation"][1].asFloat());
Vec2f minRot = Vec2f(w["minRotation"][0].asFloat(), w["minRotation"][1].asFloat());
lweapon = new Weapon(name, damage, e, fileN, 1, position, rotation, leftoffset, anchor, maxRot, minRot, collision);
rweapon = new Weapon(name, damage, e, fileN, 1, position, rotation, rightoffset, anchor, maxRot, minRot, collision);
leftweapons.push_back(lweapon);
rightweapons.push_back(rweapon);
}
}
void Player::PreviousRightWeapon()
{
currentrightweapon--;
if (currentrightweapon < 0)
currentrightweapon = (rightweapons.size() > level ? level - 1 : rightweapons.size() - 1);
rightWeapon = rightweapons[currentrightweapon];
}
void Player::NextRightWeapon(void)
{
currentrightweapon++;
if (currentrightweapon > level - 1 || currentrightweapon > rightweapons.size() - 1)
currentrightweapon = 0;
rightWeapon = rightweapons[currentrightweapon];
}
void Player::PreviousLeftWeapon(void)
{
currentleftweapon--;
if (currentleftweapon < 0)
currentleftweapon = (leftweapons.size() > level ? level - 1 : leftweapons.size() - 1);
leftWeapon = leftweapons[currentleftweapon];
}
void Player::NextLeftWeapon(void)
{
currentleftweapon++;
if (currentleftweapon > level - 1 || currentleftweapon > leftweapons.size() - 1)
currentleftweapon = 0;
leftWeapon = leftweapons[currentleftweapon];
}
+27 -5
View File
@@ -1,18 +1,30 @@
#pragma once
#include "Vector.h"
#include "Weapon.h"
#include "json.h"
class Model;
#include <vector>
class Player
{
private:
static Player* instance;
void levelUp();
std::vector<Weapon*> leftweapons;
std::vector<Weapon*> rightweapons;
void loadWeapons(void);
int currentrightweapon;
int currentleftweapon;
public:
Player();
~Player();
void setCamera();
void setPosition(float angle, float fac, bool height);
void draw(void);
static Player* getInstance(void);
static void init(void);
@@ -20,12 +32,22 @@ public:
Vec3f position;
Vec2f rotation;
Model* leftWeapon;
Model* rightWeapon;
Weapon* leftWeapon;
Weapon* rightWeapon;
float health;
float xp;
float health, maxHp;
float xp, maxXp;
int level;
int crystals;
float speed;
void HpUp(int);
void HpDown(int);
void XpUp(int);
void PreviousRightWeapon(void);
void NextRightWeapon(void);
void PreviousLeftWeapon(void);
void NextLeftWeapon(void);
};
+61
View File
@@ -0,0 +1,61 @@
#include "Portal.h"
#include "Model.h"
#include <iostream>
#include "Player.h"
#include "WorldHandler.h"
Portal::Portal(const std::string &fileName,
const Vec3f &position,
Vec3f &rotation,
const float &scale)
{
model = Model::load(fileName);
this->position = position;
this->rotation = rotation;
this->scale = scale;
this->canCollide = true;
started = false;
delay = 0;
sound_id = CrystalPoint::GetSoundSystem().LoadSound("WAVE/portal.wav", false);
music = CrystalPoint::GetSoundSystem().GetSound(sound_id);
music->SetPos(position, Vec3f());
mayEnter = false;
maxCrystals = 0;
}
Portal::~Portal()
{
// Model::unload(model);
CrystalPoint::GetSoundSystem().UnloadSound(sound_id);
}
void Portal::collide()
{
if (maxCrystals == (Player::getInstance()->crystals) && !mayEnter)
{
canCollide = false;
mayEnter = true;
}
}
bool Portal::enter(float deltaTime)
{
if (delay > 3 && started)
{
delay = 0;
return true;
}
if (delay == 0 && !started)
{
music->Play();
started = true;
}
delay += deltaTime;
return false;
}
+27
View File
@@ -0,0 +1,27 @@
#pragma once
#include "Entity.h"
#include <string>
#include "CrystalPoint.h"
class Portal :
public Entity
{
public:
Portal(const std::string &fileName,
const Vec3f &position,
Vec3f &rotation,
const float &scale);
~Portal();
bool enter(float deltaTime);
void collide();
int maxCrystals;
bool mayEnter;
private:
int sound_id;
Sound* music;
bool started;
float delay;
};
+166
View File
@@ -0,0 +1,166 @@
#include "cmath"
#include <GL/freeglut.h>
#include "Util.h"
#include "stb_image.h"
#include "Skybox.h"
#include <string>
#include <iostream>
enum{SKY_LEFT=0,SKY_BACK,SKY_RIGHT,SKY_FRONT,SKY_TOP,SKY_BOTTOM};
GLuint skybox[6];
Skybox::Skybox(const float &size, const std::string &folder)
{
this->size = size;
this->folder = folder;
brightness = 80;
targetBrightness = 80;
}
Skybox::~Skybox()
{
glDeleteTextures(6, &skybox[0]);
}
void Skybox::init()
{
skybox[SKY_LEFT] = Util::loadTexture(folder + "left.png");
skybox[SKY_BACK] = Util::loadTexture(folder + "back.png");
skybox[SKY_RIGHT] = Util::loadTexture(folder + "right.png");
skybox[SKY_FRONT] = Util::loadTexture(folder + "front.png");
skybox[SKY_TOP] = Util::loadTexture(folder + "top.png");
skybox[SKY_BOTTOM] = Util::loadTexture(folder + "bottom.png");
}
void Skybox::draw()
{
glColor4f(brightness/255, brightness/255, brightness/255, 1);
bool b1 = glIsEnabled(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glDisable(GL_COLOR_MATERIAL);
glBindTexture(GL_TEXTURE_2D, skybox[SKY_BACK]);
glBegin(GL_QUADS);
glTexCoord2f(1,1);
glVertex3f(size / 2, size / 2, size / 2);
glTexCoord2f(0,1);
glVertex3f(-size / 2, size / 2, size / 2);
glTexCoord2f(0,0);
glVertex3f(-size / 2, -size / 2, size / 2);
glTexCoord2f(1,0);
glVertex3f(size / 2, -size / 2, size / 2);
glEnd();
glBindTexture(GL_TEXTURE_2D, skybox[SKY_LEFT]);
glBegin(GL_QUADS);
//left face
glTexCoord2f(1,1);
glVertex3f(-size / 2, size / 2, size / 2);
glTexCoord2f(0,1);
glVertex3f(-size / 2, size / 2, -size / 2);
glTexCoord2f(0,0);
glVertex3f(-size / 2, -size / 2, -size / 2);
glTexCoord2f(1,0);
glVertex3f(-size / 2, -size / 2, size / 2);
glEnd();
glBindTexture(GL_TEXTURE_2D, skybox[SKY_FRONT]);
glBegin(GL_QUADS);
//front face
glTexCoord2f(0, 1);
glVertex3f(size / 2, size / 2, -size / 2);
glTexCoord2f(1, 1);
glVertex3f(-size / 2, size / 2, -size / 2);
glTexCoord2f(1, 0);
glVertex3f(-size / 2, -size / 2, -size / 2);
glTexCoord2f(0, 0);
glVertex3f(size / 2, -size / 2, -size / 2);
glEnd();
glBindTexture(GL_TEXTURE_2D, skybox[SKY_RIGHT]);
glBegin(GL_QUADS);
//right face
glTexCoord2f(1, 1);
glVertex3f(size / 2, size / 2, -size / 2);
glTexCoord2f(0,1);
glVertex3f(size / 2, size / 2, size / 2);
glTexCoord2f(0,0);
glVertex3f(size / 2, -size / 2, size / 2);
glTexCoord2f(1, 0);
glVertex3f(size / 2, -size / 2, -size / 2);
glEnd();
glBindTexture(GL_TEXTURE_2D, skybox[SKY_TOP]);
glBegin(GL_QUADS); //top face
glTexCoord2f(0,0);
glVertex3f(size / 2, size / 2, size / 2);
glTexCoord2f(0,1);
glVertex3f(-size / 2, size / 2, size / 2);
glTexCoord2f(1,1);
glVertex3f(-size / 2, size / 2, -size / 2);
glTexCoord2f(1,0);
glVertex3f(size / 2, size / 2, -size / 2);
glEnd();
glBindTexture(GL_TEXTURE_2D, skybox[SKY_BOTTOM]);
glBegin(GL_QUADS);
//bottom face
glTexCoord2f(0,1);
glVertex3f(size / 2, -size / 2, size / 2);
glTexCoord2f(0,0);
glVertex3f(-size / 2, -size / 2, size / 2);
glTexCoord2f(1,0);
glVertex3f(-size / 2, -size / 2, -size / 2);
glTexCoord2f(1,1);
glVertex3f(size / 2, -size / 2, -size / 2);
glEnd();
glEnable(GL_LIGHTING); //turn everything back, which we turned on, and turn everything off, which we have turned on.
glEnable(GL_DEPTH_TEST);
if (!b1)
glDisable(GL_TEXTURE_2D);
}
void Skybox::update(float deltaTime, int curr, int max)
{
targetBrightness = 80 + ((255 - 80) / max) * curr;
if (targetBrightness > brightness + 2)
{
brightness += 20 * deltaTime;
}
if (targetBrightness < brightness - 2)
{
brightness -= 20 * deltaTime;
}
}
GLuint Skybox::loadTexture(const std::string & fileName) //load the filename named texture
{
int width, height, bpp;
stbi_set_flip_vertically_on_load(true);
unsigned char* imgData = stbi_load(fileName.c_str(), &width, &height, &bpp, 4);
GLuint num;
glGenTextures(1, &num);
glBindTexture(GL_TEXTURE_2D, num);
glTexImage2D(GL_TEXTURE_2D,
0, //level
GL_RGBA, //internal format
width, //width
height, //height
0, //border
GL_RGBA, //data format
GL_UNSIGNED_BYTE, //data type
imgData); //data
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
stbi_image_free(imgData);
return num;
}
+21
View File
@@ -0,0 +1,21 @@
#pragma once
#include <string>
class Skybox
{
private:
float size;
std::string folder;
float brightness;
float targetBrightness;
public:
Skybox(const float &size, const std::string &folder);
~Skybox();
void init();
void draw();
void update(float deltaTime, int, int);
GLuint loadTexture(const std::string &fileName);
};
+167
View File
@@ -0,0 +1,167 @@
#include "Sound.h"
#include <iostream>
#ifdef WIN32
#include <windows.h>
#include <al.h>
#else
#include <AL/al.h>
typedef unsigned long DWORD;
typedef unsigned short WORD;
typedef unsigned int UNINT32;
typedef unsigned char BYTE;
#endif
Sound::Sound(const char* inWavPath, bool inLooping):
buffer_id(0),
source_id(0),
is_looping(inLooping)
{
const char* path = inWavPath;
FILE *fp = fopen(path, "rb"); // Open the WAVE file
if (!fp)
return; // Could not open file
// Check that the WAVE file is OK
char type[4];
fread(type, sizeof(char), 4, fp); // Reads the first bytes in the file
if (type[0] != 'R' || type[1] != 'I' || type[2] != 'F' || type[3] != 'F') // Should be "RIFF"
return; // Not RIFF
DWORD size;
fread(&size, sizeof(DWORD), 1, fp); // Continue to read the file
fread(type, sizeof(char), 4, fp); // Continue to read the file
if (type[0] != 'W' || type[1] != 'A' || type[2] != 'V' || type[3] != 'E') // This part should be "WAVE"
return; // Not WAVE
fread(type, sizeof(char), 4, fp); // Continue to read the file
if (type[0] != 'f' || type[1] != 'm' || type[2] != 't' || type[3] != ' ') // This part should be "fmt "
return; // Not fmt
// Now we know that the file is a acceptable WAVE file
// Info about the WAVE data is now read and stored
DWORD chunkSize;
fread(&chunkSize, sizeof(DWORD), 1, fp);
short formatType;
fread(&formatType, sizeof(short), 1, fp);
short channels;
fread(&channels, sizeof(short), 1, fp);
DWORD sampleRate;
fread(&sampleRate, sizeof(DWORD), 1, fp);
DWORD avgBytesPerSec;
fread(&avgBytesPerSec, sizeof(DWORD), 1, fp);
short bytesPerSample;
fread(&bytesPerSample, sizeof(short), 1, fp);
short bitsPerSample;
fread(&bitsPerSample, sizeof(short), 1, fp);
ALenum format = 0; // The audio format (bits per sample, number of channels)
if (bitsPerSample == 8)
{
if (channels == 1)
format = AL_FORMAT_MONO8;
else if (channels == 2)
format = AL_FORMAT_STEREO8;
}
else if (bitsPerSample == 16)
{
if (channels == 1)
format = AL_FORMAT_MONO16;
else if (channels == 2)
format = AL_FORMAT_STEREO16;
}
if (!format)
return; // Not valid format
fread(type, sizeof(char), 4, fp);
if (type[0] != 'd' || type[1] != 'a' || type[2] != 't' || type[3] != 'a') // This part should be "data"
return; // not data
DWORD dataSize;
fread(&dataSize, sizeof(DWORD), 1, fp); // The size of the sound data is read
// Display the info about the WAVE file
std::cout << "Chunk Size: " << chunkSize << "\n";
std::cout << "Format Type: " << formatType << "\n";
std::cout << "Channels: " << channels << "\n";
std::cout << "Sample Rate: " << sampleRate << "\n";
std::cout << "Average Bytes Per Second: " << avgBytesPerSec << "\n";
std::cout << "Bytes Per Sample: " << bytesPerSample << "\n";
std::cout << "Bits Per Sample: " << bitsPerSample << "\n";
std::cout << "Data Size: " << dataSize << "\n";
unsigned char* buf = new unsigned char[dataSize]; // Allocate memory for the sound data
std::cout << fread(buf, sizeof(BYTE), dataSize, fp) << " bytes loaded\n"; // Read the sound data and display the
fclose(fp);
alGenBuffers(1, &buffer_id); // Generate one OpenAL Buffer and link to "buffer"
alGenSources(1, &source_id); // Generate one OpenAL Source and link to "source"
if (alGetError() != AL_NO_ERROR)
return; // Error during buffer/source generation
alBufferData(buffer_id, format, buf, dataSize, sampleRate); // Store the sound data in the OpenAL Buffer
if (alGetError() != AL_NO_ERROR)
return; // Error during buffer loading
delete[] buf; // Delete the sound data buffer
}
Sound::~Sound()
{
alSourceStop(source_id);
alDeleteSources(1, &source_id); // Delete the OpenAL Source
alDeleteBuffers(1, &buffer_id); // Delete the OpenAL Buffer
}
void Sound::SetPos(const Vec3f& inPos, const Vec3f& inVel)
{
alSourcei(source_id, AL_BUFFER, buffer_id); // Link the buffer to the source
alSourcef(source_id, AL_PITCH, 1.0f); // Set the pitch of the source
alSourcef(source_id, AL_GAIN, 1.0f); // Set the gain of the source
alSourcefv(source_id, AL_POSITION, inPos.v); // Set the position of the source
alSourcefv(source_id, AL_VELOCITY, inVel.v); // Set the velocity of the source
alSourcei(source_id, AL_LOOPING, is_looping ? AL_TRUE : AL_FALSE); // Set if source is looping sound
}
void Sound::Play()
{
alSourcePlay(source_id);
int e = alGetError(); // != AL_NO_ERROR) return;
}
void Sound::Pause()
{
alSourcePause(source_id);
}
void Sound::Stop()
{
alSourceStop(source_id);
}
bool Sound::IsPlaying()
{
ALenum state;
alGetSourcei(source_id, AL_SOURCE_STATE, &state);
return (state == AL_PLAYING);
}
bool Sound::IsStopped()
{
ALenum state;
alGetSourcei(source_id, AL_SOURCE_STATE, &state);
std::cout << "MUSIC STATE: " << state << std::endl;
return (state == AL_STOPPED);
}
+24
View File
@@ -0,0 +1,24 @@
#pragma once
#include "Vector.h"
class Sound
{
public:
Sound(const char* inWavPath, bool inLooping);
~Sound();
void SetPos(const Vec3f& inPos, const Vec3f& inVel);
void Play();
void Pause();
void Stop();
bool IsPlaying();
bool IsStopped();
private:
unsigned int buffer_id;
unsigned int source_id;
bool is_looping;
};
+58
View File
@@ -0,0 +1,58 @@
#include "SoundSystem.h"
SoundSystem::SoundSystem():
device(nullptr),
context(nullptr)
{
device = alcOpenDevice(nullptr);
if (!device)
return;
context = alcCreateContext(device, nullptr);
if (!context)
return;
alcMakeContextCurrent(context);
}
SoundSystem::~SoundSystem()
{
for (auto sound : sounds)
delete sound;
alcMakeContextCurrent(nullptr);
alcDestroyContext(context);
alcCloseDevice(device);
}
void SoundSystem::SetListener(const Vec3f& inPos, const Vec3f& inVel, const Vec3f& inOri)
{
ALfloat orientation[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };
alListenerfv(AL_POSITION, inPos.v);
alListenerfv(AL_VELOCITY, inVel.v);
alListenerfv(AL_ORIENTATION, orientation);
}
unsigned int SoundSystem::LoadSound(const char* inWavPath, bool inLooping)
{
Sound* sound = new Sound(inWavPath, inLooping);
sounds.push_back(sound);
return sounds.size() - 1;
}
Sound* SoundSystem::GetSound(unsigned int inID)
{
if (inID > sounds.size())
return nullptr;
return sounds[inID];
}
void SoundSystem::UnloadSound(unsigned int inID)
{
if (inID > sounds.size())
return;
delete sounds[inID];
//sounds.erase(sounds.begin() + inID);
}
+33
View File
@@ -0,0 +1,33 @@
#pragma once
#include <vector>
#ifdef WIN32
#include <al.h>
#include <alc.h>
#else
#include <AL/al.h>
#include <AL/alc.h>
#endif
#include "Vector.h"
#include "Sound.h"
class SoundSystem
{
public:
SoundSystem();
~SoundSystem();
void SetListener(const Vec3f& inPos, const Vec3f& inVel, const Vec3f& inOri);
unsigned int LoadSound(const char* inWavPath, bool inLooping);
Sound* GetSound(unsigned int inID);
void UnloadSound(unsigned int inID);
private:
ALCdevice* device;
ALCcontext* context;
std::vector<Sound*> sounds;
};
+31
View File
@@ -0,0 +1,31 @@
#include "Text.h"
Text::Text(const std::string &text, Vec2f position) : MenuElement(position)
{
this->text = text;
color = Vec3f(50, 150, 150);
textHeight = 14;
textWidth = Util::glutTextWidth(text);
}
Text::~Text()
{
}
void Text::draw()
{
glColor4f(color.x/255.0f, color.y/255.0f, color.z/255.0f, 1.0f);
Util::glutBitmapString(text, position.x-1, position.y+textHeight);
}
void Text::update(int x, int y)
{
//Do nothing
}
void Text::setColor(Vec3f color)
{
this->color = color;
}
+23
View File
@@ -0,0 +1,23 @@
#pragma once
#include "MenuElement.h"
#include "Vector.h"
#include "Util.h"
class Text : public MenuElement
{
private:
std::string text;
Vec3f color;
protected:
int textWidth;
int textHeight;
public:
Text(const std::string &text, Vec2f position);
~Text();
virtual void draw();
virtual void update(int x, int y);
void setColor(Vec3f color);
};
+65
View File
@@ -0,0 +1,65 @@
#include "Util.h"
#include "stb_image.h"
Util::Util()
{
}
Util::~Util()
{
}
GLuint Util::loadTexture(const std::string &filename)
{
int width, height, bpp;
stbi_set_flip_vertically_on_load(true);
unsigned char* imgData = stbi_load(filename.c_str(), &width, &height, &bpp, 4);
GLuint num;
glGenTextures(1, &num);
glBindTexture(GL_TEXTURE_2D, num);
glTexImage2D(GL_TEXTURE_2D,
0, //level
GL_RGBA, //internal format
width, //width
height, //height
0, //border
GL_RGBA, //data format
GL_UNSIGNED_BYTE, //data type
imgData); //data
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
stbi_image_free(imgData);
return num;
}
void Util::glutBitmapString(std::string str, int x, int y)
{
glRasterPos2f(x, y);
for (int i = 0; i < str.size(); i++)
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, str[i]);
}
}
int Util::glutTextWidth(const std::string str)
{
int total = 0;
for (int i = 0; i < str.size(); i++)
{
total += glutBitmapWidth(GLUT_BITMAP_HELVETICA_18, str[i]);
}
return total;
}
//int Util::glutTextHeight()
//{
// return glutBitmapHeight(GLUT_BITMAP_HELVETICA_18);
//}
+16
View File
@@ -0,0 +1,16 @@
#pragma once
#include <string>
#include <GL/freeglut.h>
class Util
{
private:
Util();
~Util();
public:
static GLuint loadTexture(const std::string &filename);
static void glutBitmapString(std::string str, int x, int y);
static int glutTextWidth(const std::string str);
//static int glutTextHeight();
};
+4 -4
View File
@@ -18,22 +18,22 @@ Vertex::~Vertex()
{
}
Vertex Vertex::operator/(float &other)
Vertex Vertex::operator/(const float &other) const
{
return Vertex(x / other, y / other, z / other, normalX, normalY, normalZ, texX, texY);
}
Vertex Vertex::operator*(Vertex & other)
Vertex Vertex::operator*(const Vertex & other) const
{
return Vertex(x*other.x, y*other.y, z*other.z, normalX, normalY, normalZ, texX, texY);
}
Vertex Vertex::operator*(float & other)
Vertex Vertex::operator*(const float & other) const
{
return Vertex(x*other, y*other, z*other, normalX, normalY, normalZ, texX, texY);
}
Vertex Vertex::operator+(Vertex & other)
Vertex Vertex::operator+(const Vertex & other) const
{
return Vertex(x+other.x, y+other.y, z+other.z, normalX, normalY, normalZ, texX, texY);
}
+4 -4
View File
@@ -16,9 +16,9 @@ public:
float texX;
float texY;
Vertex operator/(float &other);
Vertex operator*(Vertex &other);
Vertex operator*(float &other);
Vertex operator+(Vertex &other);
Vertex operator/(const float &other) const;
Vertex operator*(const Vertex &other) const;
Vertex operator*(const float &other) const;
Vertex operator+(const Vertex &other) const;
};
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+93
View File
@@ -0,0 +1,93 @@
//
// Created by janco on 25-5-16.
//
#include "Weapon.h"
#include "Model.h"
#include <iostream>
#include <string>
#include <cmath>
Weapon::Weapon(std::string name, int damage, Element e, std::string modelFilename, float scale, Vec3f location, Vec2f rotation,
Vec3f offsetPlayer, Vec3f ankerPoint,
Vec2f maxRotation, Vec2f minRotation,
Vec3f collision){
weaponmodel = Model::load(modelFilename);
rotate(rotation);
move(location);
this->scale = scale;
this->name = name;
this->damage = damage;
this->element = e;
this->offsetPlayer = offsetPlayer;
this->ankerPoint = ankerPoint;
this->maxRotation = maxRotation;
this->minRotation = minRotation;
this->collision = collision;
};
Weapon::~Weapon(){
}
void Weapon::rotateWeapon(Vec3f rotation){
if(rotation.x < maxRotation.x && rotation.x > minRotation.x){
rotationWeapon.x = rotation.x;
}
if(rotation.z < maxRotation.y && rotation.z > minRotation.y){
rotationWeapon.z = rotation.z;
}
rotationWeapon.y = rotation.y;
}
void Weapon::rotate(Vec2f rotation){
this->rotation.y = -rotation.y;
}
void Weapon::move(Vec3f location){
position = location;
}
void Weapon::draw(){
if (weaponmodel != nullptr)
{
glPushMatrix();
//Player position and rotation
glTranslatef(position.x, position.y, position.z);
glRotatef(rotation.x, 1, 0, 0);
glRotatef(rotation.y, 0, 1, 0);
glRotatef(rotation.z, 0, 0, 1);
//offset from player
glTranslatef(offsetPlayer.x, offsetPlayer.y, offsetPlayer.z);
//Rotate weapon itself, from specific anker point
glTranslatef(ankerPoint.x, ankerPoint.y, ankerPoint.z);
glRotatef(rotationWeapon.z, 0, 0, 1);
glRotatef(rotationWeapon.y, 0, 1, 0);
glRotatef(rotationWeapon.x, 1, 0, 0);
glTranslatef(-ankerPoint.x, -ankerPoint.y, -ankerPoint.z);
glScalef(scale, scale, scale);
weaponmodel->draw();
//Test code for finding anker point
glColor3ub(255, 255, 0);
glTranslatef(ankerPoint.x, ankerPoint.y, ankerPoint.z);
glBegin(GL_LINES);
glVertex2f(0, 4);
glVertex2f(0, -4);
glVertex2f(4, 0);
glVertex2f(-4, 0);
glEnd();
glPopMatrix();
}
}
+40
View File
@@ -0,0 +1,40 @@
//
// Created by janco on 25-5-16.
//
#ifndef CRYSTALPOINT_WEAPON_H
#define CRYSTALPOINT_WEAPON_H
#include "Vector.h"
#include "Model.h"
#include <string>
class Weapon {
public:
enum Element {FIRE, WATER, EARTH, AIR};
Weapon(std::string name, int damage, Element element, std::string modelFilename, float scale, Vec3f location, Vec2f rotation,
Vec3f offsetPlayer, Vec3f ankerPoint,
Vec2f maxRotation, Vec2f minXRotation,
Vec3f collision);
~Weapon();
void draw();
void rotateWeapon(Vec3f rotation);
void rotate(Vec2f rotation);
void move(Vec3f location);
std::string name;
unsigned int damage;
Element element;
Model* weaponmodel;
float scale;
Vec3f position, rotation, rotationWeapon;
Vec3f offsetPlayer, ankerPoint, collision;
Vec2f maxRotation, minRotation;
};
#endif //CRYSTALPOINT_WEAPON_H
+199 -23
View File
@@ -3,18 +3,23 @@
#include "Entity.h"
#include "json.h"
#include "Model.h"
#include "CrystalPoint.h"
#include <fstream>
#include <iostream>
#include <algorithm>
#include "WorldHandler.h"
World::World(const std::string &fileName)
{
nextworld = false;
//Store player instance
player = Player::getInstance();
//Create the interface
interface = new Interface();
//Open world json file
std::ifstream file(fileName);
if(!file.is_open())
@@ -23,15 +28,27 @@ World::World(const std::string &fileName)
json::Value v = json::readJson(file);
file.close();
//Check file
if(v["world"].isNull() || v["world"]["heightmap"].isNull())
if(v["world"].isNull() || v["world"]["heightmap"].isNull() || v["world"]["skybox"].isNull())
std::cout << "Invalid world file: world - " << fileName << "\n";
if (v["world"]["object-templates"].isNull())
std::cout << "Invalid world file: object templates - " << fileName << "\n";
if (v["player"].isNull() || v["player"]["startposition"].isNull())
std::cout << "Invalid world file: player - " << fileName << "\n";
if (v["objects"].isNull())
std::cout << "Invalid world file: objects - " << fileName << "\n";
if (v["world"]["object-templates"].isNull())
std::cout << "Invalid world file: object templates - " << fileName << "\n";
if (v["enemies"].isNull())
std::cout << "Invalid world file: enemies - " << fileName << "\n";
if (v["crystal"].isNull())
std::cout << "Invalid world file: crystals - " << fileName << "\n";
if (!v["world"]["loadingscreen"].isNull())
{
ls.setTexture(v["world"]["loadingscreen"].asString());
ls.draw();
}
//Load object templates
for (auto objt : v["world"]["object-templates"])
@@ -42,19 +59,28 @@ World::World(const std::string &fileName)
cancollide = objt["collision"].asBool();
objecttemplates.push_back(std::pair<int, std::pair<std::string, bool>>(objt["color"], std::pair<std::string, bool>(objt["file"], cancollide)));
}
//Generate heightmap for this world
heightmap = new HeightMap(v["world"]["heightmap"].asString(), this);
//Load skybox
skybox = new Skybox(15000.0f, v["world"]["skybox"].asString());
skybox->init();
//Map different texture to heightmap if available
if(!v["world"]["texture"].isNull())
heightmap->SetTexture(v["world"]["texture"].asString());
//Set player starting position
player->position.x = v["player"]["startposition"][0].asFloat();
player->position.y = v["player"]["startposition"][1].asFloat();
player->position.z = v["player"]["startposition"][2].asFloat();
player->position.y = heightmap->GetHeight(player->position.x, player->position.z);
//Load and place objects into world
for (auto object : v["objects"])
@@ -84,9 +110,13 @@ World::World(const std::string &fileName)
//Create
Vec3f position(object["pos"][0].asFloat(), object["pos"][1].asFloat(), object["pos"][2].asFloat());
position.y = getHeight(position.x, position.z);
entities.push_back(new LevelObject(object["file"].asString(), position, rotation, scale, hasCollision));
}
maxEnemies = 0;
//Load and place enemies into world
for (auto e : v["enemies"])
{
@@ -108,9 +138,104 @@ World::World(const std::string &fileName)
if (e["file"].isNull())
std::cout << "Invalid world file: enemies file - " << fileName << "\n";
//Music
if (e["music"].isNull())
std::cout << "Invalid world file: enemies music - " << fileName << "\n";
//Damage
if (e["damage"].isNull())
std::cout << "Invalid world file: enemies damage - " << fileName << "\n";
//Health
if (e["health"].isNull())
std::cout << "Invalid world file: enemies health - " << fileName << "\n";
//Create
Vec3f position(e["pos"][0].asFloat(), e["pos"][1].asFloat(), e["pos"][2].asFloat());
enemies.push_back(new Enemy(e["file"].asString(), position, rotation, scale));
position.y = getHeight(position.x, position.z) + 2.0f;
maxEnemies++;
enemies.push_back(new Enemy(e["file"].asString(), e["music"].asString(), e["damage"].asFloat(), e["health"].asFloat(), position, rotation, scale));
}
maxCrystals = 0;
if (!v["crystal"].isNull())
{
std::string filled = "unknown";
std::string empty = "unknown";
if(!v["crystal"]["full texture"].isNull())
filled = v["crystal"]["full texture"].asString();
if(!v["crystal"]["empty texture"].isNull())
empty = v["crystal"]["empty texture"].asString();
if (!v["crystal"]["instances"].isNull())
{
for (auto instance : v["crystal"]["instances"])
{
Vec3f position(0, 0, 0);
Vec3f rotation(0, 0, 0);
float scale = 1.0f;
if (!instance["pos"].isNull())
{
position.x = instance["pos"][0];
position.y = instance["pos"][1];
position.z = instance["pos"][2];
}
if (!instance["rot"].isNull())
{
rotation.x = instance["rot"][0];
rotation.y = instance["rot"][1];
rotation.z = instance["rot"][2];
}
if (!instance["scale"].isNull())
scale = instance["scale"].asFloat();
position.y = getHeight(position.x, position.z);
maxCrystals++;
Crystal *c = new Crystal(filled, empty, position, rotation, scale);
entities.push_back(c);
}
interface->maxCrystals = maxCrystals;
}
}
if (!v["world"]["music"].isNull())
{
sound_id = CrystalPoint::GetSoundSystem().LoadSound(v["world"]["music"].asString().c_str(), true);
music = CrystalPoint::GetSoundSystem().GetSound(sound_id);
}
if (!v["portal"].isNull())
{
Vec3f pos(0, 0, 0);
if (!v["portal"]["pos"].isNull())
pos = Vec3f(v["portal"]["pos"][0].asFloat(),
v["portal"]["pos"][1].asFloat(),
v["portal"]["pos"][2].asFloat());
pos.y = getHeight(pos.x, pos.z);
Vec3f rot(0, 0, 0);
if (!v["portal"]["rot"].isNull())
pos = Vec3f(v["portal"]["rot"][0].asFloat(),
v["portal"]["rot"][1].asFloat(),
v["portal"]["rot"][2].asFloat());
float scale = 1.0f;
if (!v["portal"]["scale"].isNull())
scale = !v["portal"]["scale"].asFloat();
portal = new Portal(v["portal"]["file"], pos, rot, scale);
entities.push_back(portal);
portal->maxCrystals = maxCrystals;
}
}
@@ -119,6 +244,10 @@ World::World(const std::string &fileName)
World::~World()
{
delete heightmap;
music->Stop();
CrystalPoint::GetSoundSystem().UnloadSound(sound_id);
delete skybox;
delete portal;
}
std::pair<std::string, bool> World::getObjectFromValue(int val)
@@ -139,13 +268,25 @@ float World::getHeight(float x, float y)
void World::draw()
{
player->setCamera();
float lightPosition[4] = { 0, 2, 1, 0 };
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
float lightAmbient[4] = { 0.2, 0.2, 0.2, 1 };
GLfloat lightAmbient[] = { 0.05, 0.05, 0.05, 0 };
GLfloat light_diffuse[] = { 0.9, 0.9, 0.9, 0 };
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
GLfloat mat_specular[] = { 0.15, 0.15, 0.15, 0 };
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
player->setCamera();
skybox->draw();
player->draw();
heightmap->Draw();
for (auto &enemy : enemies)
@@ -159,23 +300,31 @@ void World::draw()
void World::update(float elapsedTime)
{
if (nextworld)
{
WorldHandler::getInstance()->NextWorld();
return;
}
music->SetPos(player->position, Vec3f());
if (music->IsPlaying() == false)
{
music->Play();
}
for (auto &entity : entities)
entity->update(elapsedTime);
int count = 0;
int remove = false;
for (auto &enemy : enemies)
{
//Al deze code zou in enemy moeten staan
if (enemy->position.Distance(player->position) <= enemy->radius)
{
enemy->hasTarget = true;
enemy->target.x = player->position.x;
enemy->target.z = player->position.z;
}
else
enemy->hasTarget = false;
enemy->inEyeSight(player->position);
Vec3f oldpos = enemy->position;
enemy->update(elapsedTime);
if (enemy->hasTarget)
{
@@ -183,16 +332,40 @@ void World::update(float elapsedTime)
{
if (e->canCollide && e->inObject(enemy->position))
{
Vec3f difference = e->position - enemy->position; //zou misschien omgedraait moeten worden
difference.Normalize();
difference = difference * (e->model->radius + 0.01f);
enemy->position = e->position + difference;
enemy->collide(e);
break;
}
}
}
//tot hier
if (enemy->attack)
{
remove = true;
continue;
}
enemy->position.y = getHeight(enemy->position.x, enemy->position.z);
if(!remove)
count++;
}
if (remove)
{
player->XpUp(enemies[count]->xp);
delete enemies[count];
enemies.erase(enemies.begin() + count);
player->HpUp(10);
}
skybox->update(elapsedTime, maxEnemies - enemies.size(), maxEnemies);
if (portal->mayEnter)
{
if (portal->enter(elapsedTime))
nextworld = true;
}
}
void World::addLevelObject(LevelObject* obj)
@@ -202,10 +375,13 @@ void World::addLevelObject(LevelObject* obj)
bool World::isPlayerPositionValid()
{
for (auto e : entities)
for (auto &e : entities)
{
if (e->canCollide && e->inObject(player->position))
{
e->collide();
return false;
}
}
return true;
}
+16
View File
@@ -6,6 +6,11 @@
#include "Enemy.h"
#include "LevelObject.h"
#include "Interface.h"
#include "Crystal.h"
#include "Skybox.h"
#include "CrystalPoint.h"
#include "Portal.h"
#include "LoadingScreen.h"
class Entity;
@@ -13,13 +18,23 @@ class World
{
private:
std::vector<std::pair<int, std::pair<std::string, bool>>> objecttemplates;
Sound* music;
Player* player;
HeightMap* heightmap;
Interface* interface;
Skybox* skybox;
Portal* portal;
bool nextworld;
int sound_id,maxCrystals,maxEnemies;
std::vector<Entity*> entities;
std::vector<Enemy*> enemies;
//std::vector<Crystal*> crystals;
LoadingScreen ls;
public:
World(const std::string &fileName);
~World();
@@ -30,5 +45,6 @@ public:
float getHeight(float x, float y);
void addLevelObject(LevelObject* obj);
std::pair<std::string, bool> getObjectFromValue(int i);
};
+3
View File
@@ -97,6 +97,7 @@ bool WorldHandler::isPlayerPositionValid(void)
{
if(!loadingWorld)
return world->isPlayerPositionValid();
return false;
}
float WorldHandler::getHeight(float x, float y)
@@ -125,6 +126,7 @@ void WorldHandler::NextWorld()
if (!loadingWorld)
{
ChangeWorld(worldIndex + 1);
Player::getInstance()->crystals = 0;
}
}
@@ -133,5 +135,6 @@ void WorldHandler::PreviousWorld()
if (!loadingWorld)
{
ChangeWorld(worldIndex - 1);
Player::getInstance()->crystals = 0;
}
}
+221
View File
@@ -0,0 +1,221 @@
/*!
* \file serial/impl/unix.h
* \author William Woodall <wjwwood@gmail.com>
* \author John Harrison <ash@greaterthaninfinity.com>
* \version 0.1
*
* \section LICENSE
*
* The MIT License
*
* Copyright (c) 2012 William Woodall, John Harrison
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* \section DESCRIPTION
*
* This provides a unix based pimpl for the Serial class. This implementation is
* based off termios.h and uses select for multiplexing the IO ports.
*
*/
#if !defined(_WIN32)
#ifndef SERIAL_IMPL_UNIX_H
#define SERIAL_IMPL_UNIX_H
#include <pthread.h>
#include "../serial.h"
namespace serial {
using std::size_t;
using std::string;
using std::invalid_argument;
using serial::SerialException;
using serial::IOException;
class MillisecondTimer {
public:
MillisecondTimer(const uint32_t millis);
int64_t remaining();
private:
static timespec timespec_now();
timespec expiry;
};
class serial::Serial::SerialImpl {
public:
SerialImpl (const string &port,
unsigned long baudrate,
bytesize_t bytesize,
parity_t parity,
stopbits_t stopbits,
flowcontrol_t flowcontrol);
virtual ~SerialImpl ();
void
open ();
void
close ();
bool
isOpen () const;
size_t
available ();
bool
waitReadable (uint32_t timeout);
void
waitByteTimes (size_t count);
size_t
read (uint8_t *buf, size_t size = 1);
size_t
write (const uint8_t *data, size_t length);
void
flush ();
void
flushInput ();
void
flushOutput ();
void
sendBreak (int duration);
void
setBreak (bool level);
void
setRTS (bool level);
void
setDTR (bool level);
bool
waitForChange ();
bool
getCTS ();
bool
getDSR ();
bool
getRI ();
bool
getCD ();
void
setPort (const string &port);
string
getPort () const;
void
setTimeout (Timeout &timeout);
Timeout
getTimeout () const;
void
setBaudrate (unsigned long baudrate);
unsigned long
getBaudrate () const;
void
setBytesize (bytesize_t bytesize);
bytesize_t
getBytesize () const;
void
setParity (parity_t parity);
parity_t
getParity () const;
void
setStopbits (stopbits_t stopbits);
stopbits_t
getStopbits () const;
void
setFlowcontrol (flowcontrol_t flowcontrol);
flowcontrol_t
getFlowcontrol () const;
void
readLock ();
void
readUnlock ();
void
writeLock ();
void
writeUnlock ();
protected:
void reconfigurePort ();
private:
string port_; // Path to the file descriptor
int fd_; // The current file descriptor
bool is_open_;
bool xonxoff_;
bool rtscts_;
Timeout timeout_; // Timeout for read operations
unsigned long baudrate_; // Baudrate
uint32_t byte_time_ns_; // Nanoseconds to transmit/receive a single byte
parity_t parity_; // Parity
bytesize_t bytesize_; // Size of the bytes
stopbits_t stopbits_; // Stop Bits
flowcontrol_t flowcontrol_; // Flow Control
// Mutex used to lock the read functions
pthread_mutex_t read_mutex;
// Mutex used to lock the write functions
pthread_mutex_t write_mutex;
};
}
#endif // SERIAL_IMPL_UNIX_H
#endif // !defined(_WIN32)
+207
View File
@@ -0,0 +1,207 @@
/*!
* \file serial/impl/windows.h
* \author William Woodall <wjwwood@gmail.com>
* \author John Harrison <ash@greaterthaninfinity.com>
* \version 0.1
*
* \section LICENSE
*
* The MIT License
*
* Copyright (c) 2012 William Woodall, John Harrison
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* \section DESCRIPTION
*
* This provides a windows implementation of the Serial class interface.
*
*/
#if defined(_WIN32)
#ifndef SERIAL_IMPL_WINDOWS_H
#define SERIAL_IMPL_WINDOWS_H
#include "include/serial.h"
#include "windows.h"
namespace serial {
using std::string;
using std::wstring;
using std::invalid_argument;
using serial::SerialException;
using serial::IOException;
class serial::Serial::SerialImpl {
public:
SerialImpl (const string &port,
unsigned long baudrate,
bytesize_t bytesize,
parity_t parity,
stopbits_t stopbits,
flowcontrol_t flowcontrol);
virtual ~SerialImpl ();
void
open ();
void
close ();
bool
isOpen () const;
size_t
available ();
bool
waitReadable (uint32_t timeout);
void
waitByteTimes (size_t count);
size_t
read (uint8_t *buf, size_t size = 1);
size_t
write (const uint8_t *data, size_t length);
void
flush ();
void
flushInput ();
void
flushOutput ();
void
sendBreak (int duration);
void
setBreak (bool level);
void
setRTS (bool level);
void
setDTR (bool level);
bool
waitForChange ();
bool
getCTS ();
bool
getDSR ();
bool
getRI ();
bool
getCD ();
void
setPort (const string &port);
string
getPort () const;
void
setTimeout (Timeout &timeout);
Timeout
getTimeout () const;
void
setBaudrate (unsigned long baudrate);
unsigned long
getBaudrate () const;
void
setBytesize (bytesize_t bytesize);
bytesize_t
getBytesize () const;
void
setParity (parity_t parity);
parity_t
getParity () const;
void
setStopbits (stopbits_t stopbits);
stopbits_t
getStopbits () const;
void
setFlowcontrol (flowcontrol_t flowcontrol);
flowcontrol_t
getFlowcontrol () const;
void
readLock ();
void
readUnlock ();
void
writeLock ();
void
writeUnlock ();
protected:
void reconfigurePort ();
private:
wstring port_; // Path to the file descriptor
HANDLE fd_;
bool is_open_;
Timeout timeout_; // Timeout for read operations
unsigned long baudrate_; // Baudrate
parity_t parity_; // Parity
bytesize_t bytesize_; // Size of the bytes
stopbits_t stopbits_; // Stop Bits
flowcontrol_t flowcontrol_; // Flow Control
// Mutex used to lock the read functions
HANDLE read_mutex;
// Mutex used to lock the write functions
HANDLE write_mutex;
};
}
#endif // SERIAL_IMPL_WINDOWS_H
#endif // if defined(_WIN32)
+772
View File
@@ -0,0 +1,772 @@
/*!
* \file serial/serial.h
* \author William Woodall <wjwwood@gmail.com>
* \author John Harrison <ash.gti@gmail.com>
* \version 0.1
*
* \section LICENSE
*
* The MIT License
*
* Copyright (c) 2012 William Woodall
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* \section DESCRIPTION
*
* This provides a cross platform interface for interacting with Serial Ports.
*/
#ifndef SERIAL_H
#define SERIAL_H
#include <limits>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <exception>
#include <stdexcept>
#define THROW(exceptionClass, message) throw exceptionClass(__FILE__, \
__LINE__, (message) )
namespace serial {
/*!
* Enumeration defines the possible bytesizes for the serial port.
*/
typedef enum {
fivebits = 5,
sixbits = 6,
sevenbits = 7,
eightbits = 8
} bytesize_t;
/*!
* Enumeration defines the possible parity types for the serial port.
*/
typedef enum {
parity_none = 0,
parity_odd = 1,
parity_even = 2,
parity_mark = 3,
parity_space = 4
} parity_t;
/*!
* Enumeration defines the possible stopbit types for the serial port.
*/
typedef enum {
stopbits_one = 1,
stopbits_two = 2,
stopbits_one_point_five
} stopbits_t;
/*!
* Enumeration defines the possible flowcontrol types for the serial port.
*/
typedef enum {
flowcontrol_none = 0,
flowcontrol_software,
flowcontrol_hardware
} flowcontrol_t;
/*!
* Structure for setting the timeout of the serial port, times are
* in milliseconds.
*
* In order to disable the interbyte timeout, set it to Timeout::max().
*/
struct Timeout {
#ifdef max
# undef max
#endif
static uint32_t max() {return std::numeric_limits<uint32_t>::max();}
/*!
* Convenience function to generate Timeout structs using a
* single absolute timeout.
*
* \param timeout A long that defines the time in milliseconds until a
* timeout occurs after a call to read or write is made.
*
* \return Timeout struct that represents this simple timeout provided.
*/
static Timeout simpleTimeout(uint32_t timeout) {
return Timeout(max(), timeout, 0, timeout, 0);
}
/*! Number of milliseconds between bytes received to timeout on. */
uint32_t inter_byte_timeout;
/*! A constant number of milliseconds to wait after calling read. */
uint32_t read_timeout_constant;
/*! A multiplier against the number of requested bytes to wait after
* calling read.
*/
uint32_t read_timeout_multiplier;
/*! A constant number of milliseconds to wait after calling write. */
uint32_t write_timeout_constant;
/*! A multiplier against the number of requested bytes to wait after
* calling write.
*/
uint32_t write_timeout_multiplier;
explicit Timeout (uint32_t inter_byte_timeout_=0,
uint32_t read_timeout_constant_=0,
uint32_t read_timeout_multiplier_=0,
uint32_t write_timeout_constant_=0,
uint32_t write_timeout_multiplier_=0)
: inter_byte_timeout(inter_byte_timeout_),
read_timeout_constant(read_timeout_constant_),
read_timeout_multiplier(read_timeout_multiplier_),
write_timeout_constant(write_timeout_constant_),
write_timeout_multiplier(write_timeout_multiplier_)
{}
};
/*!
* Class that provides a portable serial port interface.
*/
class Serial {
public:
/*!
* Creates a Serial object and opens the port if a port is specified,
* otherwise it remains closed until serial::Serial::open is called.
*
* \param port A std::string containing the address of the serial port,
* which would be something like 'COM1' on Windows and '/dev/ttyS0'
* on Linux.
*
* \param baudrate An unsigned 32-bit integer that represents the baudrate
*
* \param timeout A serial::Timeout struct that defines the timeout
* conditions for the serial port. \see serial::Timeout
*
* \param bytesize Size of each byte in the serial transmission of data,
* default is eightbits, possible values are: fivebits, sixbits, sevenbits,
* eightbits
*
* \param parity Method of parity, default is parity_none, possible values
* are: parity_none, parity_odd, parity_even
*
* \param stopbits Number of stop bits used, default is stopbits_one,
* possible values are: stopbits_one, stopbits_one_point_five, stopbits_two
*
* \param flowcontrol Type of flowcontrol used, default is
* flowcontrol_none, possible values are: flowcontrol_none,
* flowcontrol_software, flowcontrol_hardware
*
* \throw serial::PortNotOpenedException
* \throw serial::IOException
* \throw std::invalid_argument
*/
Serial (const std::string &port = "",
uint32_t baudrate = 9600,
Timeout timeout = Timeout(),
bytesize_t bytesize = eightbits,
parity_t parity = parity_none,
stopbits_t stopbits = stopbits_one,
flowcontrol_t flowcontrol = flowcontrol_none);
/*! Destructor */
virtual ~Serial ();
/*!
* Opens the serial port as long as the port is set and the port isn't
* already open.
*
* If the port is provided to the constructor then an explicit call to open
* is not needed.
*
* \see Serial::Serial
*
* \throw std::invalid_argument
* \throw serial::SerialException
* \throw serial::IOException
*/
void
open ();
/*! Gets the open status of the serial port.
*
* \return Returns true if the port is open, false otherwise.
*/
bool
isOpen () const;
/*! Closes the serial port. */
void
close ();
/*! Return the number of characters in the buffer. */
size_t
available ();
/*! Block until there is serial data to read or read_timeout_constant
* number of milliseconds have elapsed. The return value is true when
* the function exits with the port in a readable state, false otherwise
* (due to timeout or select interruption). */
bool
waitReadable ();
/*! Block for a period of time corresponding to the transmission time of
* count characters at present serial settings. This may be used in con-
* junction with waitReadable to read larger blocks of data from the
* port. */
void
waitByteTimes (size_t count);
/*! Read a given amount of bytes from the serial port into a given buffer.
*
* The read function will return in one of three cases:
* * The number of requested bytes was read.
* * In this case the number of bytes requested will match the size_t
* returned by read.
* * A timeout occurred, in this case the number of bytes read will not
* match the amount requested, but no exception will be thrown. One of
* two possible timeouts occurred:
* * The inter byte timeout expired, this means that number of
* milliseconds elapsed between receiving bytes from the serial port
* exceeded the inter byte timeout.
* * The total timeout expired, which is calculated by multiplying the
* read timeout multiplier by the number of requested bytes and then
* added to the read timeout constant. If that total number of
* milliseconds elapses after the initial call to read a timeout will
* occur.
* * An exception occurred, in this case an actual exception will be thrown.
*
* \param buffer An uint8_t array of at least the requested size.
* \param size A size_t defining how many bytes to be read.
*
* \return A size_t representing the number of bytes read as a result of the
* call to read.
*
* \throw serial::PortNotOpenedException
* \throw serial::SerialException
*/
size_t
read (uint8_t *buffer, size_t size);
/*! Read a given amount of bytes from the serial port into a give buffer.
*
* \param buffer A reference to a std::vector of uint8_t.
* \param size A size_t defining how many bytes to be read.
*
* \return A size_t representing the number of bytes read as a result of the
* call to read.
*
* \throw serial::PortNotOpenedException
* \throw serial::SerialException
*/
size_t
read (std::vector<uint8_t> &buffer, size_t size = 1);
/*! Read a given amount of bytes from the serial port into a give buffer.
*
* \param buffer A reference to a std::string.
* \param size A size_t defining how many bytes to be read.
*
* \return A size_t representing the number of bytes read as a result of the
* call to read.
*
* \throw serial::PortNotOpenedException
* \throw serial::SerialException
*/
size_t
read (std::string &buffer, size_t size = 1);
/*! Read a given amount of bytes from the serial port and return a string
* containing the data.
*
* \param size A size_t defining how many bytes to be read.
*
* \return A std::string containing the data read from the port.
*
* \throw serial::PortNotOpenedException
* \throw serial::SerialException
*/
std::string
read (size_t size = 1);
/*! Reads in a line or until a given delimiter has been processed.
*
* Reads from the serial port until a single line has been read.
*
* \param buffer A std::string reference used to store the data.
* \param size A maximum length of a line, defaults to 65536 (2^16)
* \param eol A string to match against for the EOL.
*
* \return A size_t representing the number of bytes read.
*
* \throw serial::PortNotOpenedException
* \throw serial::SerialException
*/
size_t
readline (std::string &buffer, size_t size = 65536, std::string eol = "\n");
/*! Reads in a line or until a given delimiter has been processed.
*
* Reads from the serial port until a single line has been read.
*
* \param size A maximum length of a line, defaults to 65536 (2^16)
* \param eol A string to match against for the EOL.
*
* \return A std::string containing the line.
*
* \throw serial::PortNotOpenedException
* \throw serial::SerialException
*/
std::string
readline (size_t size = 65536, std::string eol = "\n");
/*! Reads in multiple lines until the serial port times out.
*
* This requires a timeout > 0 before it can be run. It will read until a
* timeout occurs and return a list of strings.
*
* \param size A maximum length of combined lines, defaults to 65536 (2^16)
*
* \param eol A string to match against for the EOL.
*
* \return A vector<string> containing the lines.
*
* \throw serial::PortNotOpenedException
* \throw serial::SerialException
*/
std::vector<std::string>
readlines (size_t size = 65536, std::string eol = "\n");
/*! Write a string to the serial port.
*
* \param data A const reference containing the data to be written
* to the serial port.
*
* \param size A size_t that indicates how many bytes should be written from
* the given data buffer.
*
* \return A size_t representing the number of bytes actually written to
* the serial port.
*
* \throw serial::PortNotOpenedException
* \throw serial::SerialException
* \throw serial::IOException
*/
size_t
write (const uint8_t *data, size_t size);
/*! Write a string to the serial port.
*
* \param data A const reference containing the data to be written
* to the serial port.
*
* \return A size_t representing the number of bytes actually written to
* the serial port.
*
* \throw serial::PortNotOpenedException
* \throw serial::SerialException
* \throw serial::IOException
*/
size_t
write (const std::vector<uint8_t> &data);
/*! Write a string to the serial port.
*
* \param data A const reference containing the data to be written
* to the serial port.
*
* \return A size_t representing the number of bytes actually written to
* the serial port.
*
* \throw serial::PortNotOpenedException
* \throw serial::SerialException
* \throw serial::IOException
*/
size_t
write (const std::string &data);
/*! Sets the serial port identifier.
*
* \param port A const std::string reference containing the address of the
* serial port, which would be something like 'COM1' on Windows and
* '/dev/ttyS0' on Linux.
*
* \throw std::invalid_argument
*/
void
setPort (const std::string &port);
/*! Gets the serial port identifier.
*
* \see Serial::setPort
*
* \throw std::invalid_argument
*/
std::string
getPort () const;
/*! Sets the timeout for reads and writes using the Timeout struct.
*
* There are two timeout conditions described here:
* * The inter byte timeout:
* * The inter_byte_timeout component of serial::Timeout defines the
* maximum amount of time, in milliseconds, between receiving bytes on
* the serial port that can pass before a timeout occurs. Setting this
* to zero will prevent inter byte timeouts from occurring.
* * Total time timeout:
* * The constant and multiplier component of this timeout condition,
* for both read and write, are defined in serial::Timeout. This
* timeout occurs if the total time since the read or write call was
* made exceeds the specified time in milliseconds.
* * The limit is defined by multiplying the multiplier component by the
* number of requested bytes and adding that product to the constant
* component. In this way if you want a read call, for example, to
* timeout after exactly one second regardless of the number of bytes
* you asked for then set the read_timeout_constant component of
* serial::Timeout to 1000 and the read_timeout_multiplier to zero.
* This timeout condition can be used in conjunction with the inter
* byte timeout condition with out any problems, timeout will simply
* occur when one of the two timeout conditions is met. This allows
* users to have maximum control over the trade-off between
* responsiveness and efficiency.
*
* Read and write functions will return in one of three cases. When the
* reading or writing is complete, when a timeout occurs, or when an
* exception occurs.
*
* \param timeout A serial::Timeout struct containing the inter byte
* timeout, and the read and write timeout constants and multipliers.
*
* \see serial::Timeout
*/
void
setTimeout (Timeout &timeout);
/*! Sets the timeout for reads and writes. */
void
setTimeout (uint32_t inter_byte_timeout, uint32_t read_timeout_constant,
uint32_t read_timeout_multiplier, uint32_t write_timeout_constant,
uint32_t write_timeout_multiplier)
{
Timeout timeout(inter_byte_timeout, read_timeout_constant,
read_timeout_multiplier, write_timeout_constant,
write_timeout_multiplier);
return setTimeout(timeout);
}
/*! Gets the timeout for reads in seconds.
*
* \return A Timeout struct containing the inter_byte_timeout, and read
* and write timeout constants and multipliers.
*
* \see Serial::setTimeout
*/
Timeout
getTimeout () const;
/*! Sets the baudrate for the serial port.
*
* Possible baudrates depends on the system but some safe baudrates include:
* 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 56000,
* 57600, 115200
* Some other baudrates that are supported by some comports:
* 128000, 153600, 230400, 256000, 460800, 921600
*
* \param baudrate An integer that sets the baud rate for the serial port.
*
* \throw std::invalid_argument
*/
void
setBaudrate (uint32_t baudrate);
/*! Gets the baudrate for the serial port.
*
* \return An integer that sets the baud rate for the serial port.
*
* \see Serial::setBaudrate
*
* \throw std::invalid_argument
*/
uint32_t
getBaudrate () const;
/*! Sets the bytesize for the serial port.
*
* \param bytesize Size of each byte in the serial transmission of data,
* default is eightbits, possible values are: fivebits, sixbits, sevenbits,
* eightbits
*
* \throw std::invalid_argument
*/
void
setBytesize (bytesize_t bytesize);
/*! Gets the bytesize for the serial port.
*
* \see Serial::setBytesize
*
* \throw std::invalid_argument
*/
bytesize_t
getBytesize () const;
/*! Sets the parity for the serial port.
*
* \param parity Method of parity, default is parity_none, possible values
* are: parity_none, parity_odd, parity_even
*
* \throw std::invalid_argument
*/
void
setParity (parity_t parity);
/*! Gets the parity for the serial port.
*
* \see Serial::setParity
*
* \throw std::invalid_argument
*/
parity_t
getParity () const;
/*! Sets the stopbits for the serial port.
*
* \param stopbits Number of stop bits used, default is stopbits_one,
* possible values are: stopbits_one, stopbits_one_point_five, stopbits_two
*
* \throw std::invalid_argument
*/
void
setStopbits (stopbits_t stopbits);
/*! Gets the stopbits for the serial port.
*
* \see Serial::setStopbits
*
* \throw std::invalid_argument
*/
stopbits_t
getStopbits () const;
/*! Sets the flow control for the serial port.
*
* \param flowcontrol Type of flowcontrol used, default is flowcontrol_none,
* possible values are: flowcontrol_none, flowcontrol_software,
* flowcontrol_hardware
*
* \throw std::invalid_argument
*/
void
setFlowcontrol (flowcontrol_t flowcontrol);
/*! Gets the flow control for the serial port.
*
* \see Serial::setFlowcontrol
*
* \throw std::invalid_argument
*/
flowcontrol_t
getFlowcontrol () const;
/*! Flush the input and output buffers */
void
flush ();
/*! Flush only the input buffer */
void
flushInput ();
/*! Flush only the output buffer */
void
flushOutput ();
/*! Sends the RS-232 break signal. See tcsendbreak(3). */
void
sendBreak (int duration);
/*! Set the break condition to a given level. Defaults to true. */
void
setBreak (bool level = true);
/*! Set the RTS handshaking line to the given level. Defaults to true. */
void
setRTS (bool level = true);
/*! Set the DTR handshaking line to the given level. Defaults to true. */
void
setDTR (bool level = true);
/*!
* Blocks until CTS, DSR, RI, CD changes or something interrupts it.
*
* Can throw an exception if an error occurs while waiting.
* You can check the status of CTS, DSR, RI, and CD once this returns.
* Uses TIOCMIWAIT via ioctl if available (mostly only on Linux) with a
* resolution of less than +-1ms and as good as +-0.2ms. Otherwise a
* polling method is used which can give +-2ms.
*
* \return Returns true if one of the lines changed, false if something else
* occurred.
*
* \throw SerialException
*/
bool
waitForChange ();
/*! Returns the current status of the CTS line. */
bool
getCTS ();
/*! Returns the current status of the DSR line. */
bool
getDSR ();
/*! Returns the current status of the RI line. */
bool
getRI ();
/*! Returns the current status of the CD line. */
bool
getCD ();
private:
// Disable copy constructors
Serial(const Serial&);
Serial& operator=(const Serial&);
// Pimpl idiom, d_pointer
class SerialImpl;
SerialImpl *pimpl_;
// Scoped Lock Classes
class ScopedReadLock;
class ScopedWriteLock;
// Read common function
size_t
read_ (uint8_t *buffer, size_t size);
// Write common function
size_t
write_ (const uint8_t *data, size_t length);
};
class SerialException : public std::exception
{
// Disable copy constructors
SerialException& operator=(const SerialException&);
std::string e_what_;
public:
SerialException (const char *description) {
std::stringstream ss;
ss << "SerialException " << description << " failed.";
e_what_ = ss.str();
}
SerialException (const SerialException& other) : e_what_(other.e_what_) {}
virtual ~SerialException() throw() {}
virtual const char* what () const throw () {
return e_what_.c_str();
}
};
class IOException : public std::exception
{
// Disable copy constructors
IOException& operator=(const IOException&);
std::string file_;
int line_;
std::string e_what_;
int errno_;
public:
explicit IOException (std::string file, int line, int errnum)
: file_(file), line_(line), errno_(errnum) {
std::stringstream ss;
#if defined(_WIN32) && !defined(__MINGW32__)
char error_str [1024];
strerror_s(error_str, 1024, errnum);
#else
char * error_str = strerror(errnum);
#endif
ss << "IO Exception (" << errno_ << "): " << error_str;
ss << ", file " << file_ << ", line " << line_ << ".";
e_what_ = ss.str();
}
explicit IOException (std::string file, int line, const char * description)
: file_(file), line_(line), errno_(0) {
std::stringstream ss;
ss << "IO Exception: " << description;
ss << ", file " << file_ << ", line " << line_ << ".";
e_what_ = ss.str();
}
virtual ~IOException() throw() {}
IOException (const IOException& other) : line_(other.line_), e_what_(other.e_what_), errno_(other.errno_) {}
int getErrorNumber () { return errno_; }
virtual const char* what () const throw () {
return e_what_.c_str();
}
};
class PortNotOpenedException : public std::exception
{
// Disable copy constructors
const PortNotOpenedException& operator=(PortNotOpenedException);
std::string e_what_;
public:
PortNotOpenedException (const char * description) {
std::stringstream ss;
ss << "PortNotOpenedException " << description << " failed.";
e_what_ = ss.str();
}
PortNotOpenedException (const PortNotOpenedException& other) : e_what_(other.e_what_) {}
virtual ~PortNotOpenedException() throw() {}
virtual const char* what () const throw () {
return e_what_.c_str();
}
};
/*!
* Structure that describes a serial device.
*/
struct PortInfo {
/*! Address of the serial port (this can be passed to the constructor of Serial). */
std::string port;
/*! Human readable description of serial device if available. */
std::string description;
/*! Hardware ID (e.g. VID:PID of USB serial devices) or "n/a" if not available. */
std::string hardware_id;
};
/* Lists the serial ports available on the system
*
* Returns a vector of available serial ports, each represented
* by a serial::PortInfo data structure:
*
* \return vector of serial::PortInfo.
*/
std::vector<PortInfo>
list_ports();
} // namespace serial
#endif
+57
View File
@@ -0,0 +1,57 @@
// This header is from the v8 google project:
// http://code.google.com/p/v8/source/browse/trunk/include/v8stdint.h
// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Load definitions of standard types.
#ifndef V8STDINT_H_
#define V8STDINT_H_
#include <stddef.h>
#include <stdio.h>
#if defined(_WIN32) && !defined(__MINGW32__)
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t; // NOLINT
typedef unsigned short uint16_t; // NOLINT
typedef int int32_t;
typedef unsigned int uint32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
// intptr_t and friends are defined in crtdefs.h through stdio.h.
#else
#include <stdint.h>
#endif
#endif // V8STDINT_H_
@@ -0,0 +1,335 @@
#if defined(__linux__)
/*
* Copyright (c) 2014 Craig Lilley <cralilley@gmail.com>
* This software is made available under the terms of the MIT licence.
* A copy of the licence can be obtained from:
* http://opensource.org/licenses/MIT
*/
#include <vector>
#include <string>
#include <sstream>
#include <stdexcept>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdarg>
#include <cstdlib>
#include <glob.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "../../../include/serial.h"
using serial::PortInfo;
using std::istringstream;
using std::ifstream;
using std::getline;
using std::vector;
using std::string;
using std::cout;
using std::endl;
static vector<string> glob(const vector<string>& patterns);
static string basename(const string& path);
static string dirname(const string& path);
static bool path_exists(const string& path);
static string realpath(const string& path);
static string usb_sysfs_friendly_name(const string& sys_usb_path);
static vector<string> get_sysfs_info(const string& device_path);
static string read_line(const string& file);
static string usb_sysfs_hw_string(const string& sysfs_path);
static string format(const char* format, ...);
vector<string>
glob(const vector<string>& patterns)
{
vector<string> paths_found;
if(patterns.size() == 0)
return paths_found;
glob_t glob_results;
int glob_retval = glob(patterns[0].c_str(), 0, NULL, &glob_results);
vector<string>::const_iterator iter = patterns.begin();
while(++iter != patterns.end())
{
glob_retval = glob(iter->c_str(), GLOB_APPEND, NULL, &glob_results);
}
for(int path_index = 0; path_index < glob_results.gl_pathc; path_index++)
{
paths_found.push_back(glob_results.gl_pathv[path_index]);
}
globfree(&glob_results);
return paths_found;
}
string
basename(const string& path)
{
size_t pos = path.rfind("/");
if(pos == std::string::npos)
return path;
return string(path, pos+1, string::npos);
}
string
dirname(const string& path)
{
size_t pos = path.rfind("/");
if(pos == std::string::npos)
return path;
else if(pos == 0)
return "/";
return string(path, 0, pos);
}
bool
path_exists(const string& path)
{
struct stat sb;
if( stat(path.c_str(), &sb ) == 0 )
return true;
return false;
}
string
realpath(const string& path)
{
char* real_path = realpath(path.c_str(), NULL);
string result;
if(real_path != NULL)
{
result = real_path;
free(real_path);
}
return result;
}
string
usb_sysfs_friendly_name(const string& sys_usb_path)
{
unsigned int device_number = 0;
istringstream( read_line(sys_usb_path + "/devnum") ) >> device_number;
string manufacturer = read_line( sys_usb_path + "/manufacturer" );
string product = read_line( sys_usb_path + "/product" );
string serial = read_line( sys_usb_path + "/serial" );
if( manufacturer.empty() && product.empty() && serial.empty() )
return "";
return format("%s %s %s", manufacturer.c_str(), product.c_str(), serial.c_str() );
}
vector<string>
get_sysfs_info(const string& device_path)
{
string device_name = basename( device_path );
string friendly_name;
string hardware_id;
string sys_device_path = format( "/sys/class/tty/%s/device", device_name.c_str() );
if( device_name.compare(0,6,"ttyUSB") == 0 )
{
sys_device_path = dirname( dirname( realpath( sys_device_path ) ) );
if( path_exists( sys_device_path ) )
{
friendly_name = usb_sysfs_friendly_name( sys_device_path );
hardware_id = usb_sysfs_hw_string( sys_device_path );
}
}
else if( device_name.compare(0,6,"ttyACM") == 0 )
{
sys_device_path = dirname( realpath( sys_device_path ) );
if( path_exists( sys_device_path ) )
{
friendly_name = usb_sysfs_friendly_name( sys_device_path );
hardware_id = usb_sysfs_hw_string( sys_device_path );
}
}
else
{
// Try to read ID string of PCI device
string sys_id_path = sys_device_path + "/id";
if( path_exists( sys_id_path ) )
hardware_id = read_line( sys_id_path );
}
if( friendly_name.empty() )
friendly_name = device_name;
if( hardware_id.empty() )
hardware_id = "n/a";
vector<string> result;
result.push_back(friendly_name);
result.push_back(hardware_id);
return result;
}
string
read_line(const string& file)
{
ifstream ifs(file.c_str(), ifstream::in);
string line;
if(ifs)
{
getline(ifs, line);
}
return line;
}
string
format(const char* format, ...)
{
va_list ap;
size_t buffer_size_bytes = 256;
string result;
char* buffer = (char*)malloc(buffer_size_bytes);
if( buffer == NULL )
return result;
bool done = false;
unsigned int loop_count = 0;
while(!done)
{
va_start(ap, format);
int return_value = vsnprintf(buffer, buffer_size_bytes, format, ap);
if( return_value < 0 )
{
done = true;
}
else if( return_value >= buffer_size_bytes )
{
// Realloc and try again.
buffer_size_bytes = return_value + 1;
char* new_buffer_ptr = (char*)realloc(buffer, buffer_size_bytes);
if( new_buffer_ptr == NULL )
{
done = true;
}
else
{
buffer = new_buffer_ptr;
}
}
else
{
result = buffer;
done = true;
}
va_end(ap);
if( ++loop_count > 5 )
done = true;
}
free(buffer);
return result;
}
string
usb_sysfs_hw_string(const string& sysfs_path)
{
string serial_number = read_line( sysfs_path + "/serial" );
if( serial_number.length() > 0 )
{
serial_number = format( "SNR=%s", serial_number.c_str() );
}
string vid = read_line( sysfs_path + "/idVendor" );
string pid = read_line( sysfs_path + "/idProduct" );
return format("USB VID:PID=%s:%s %s", vid.c_str(), pid.c_str(), serial_number.c_str() );
}
vector<PortInfo>
serial::list_ports()
{
vector<PortInfo> results;
vector<string> search_globs;
search_globs.push_back("/dev/ttyACM*");
search_globs.push_back("/dev/ttyS*");
search_globs.push_back("/dev/ttyUSB*");
search_globs.push_back("/dev/tty.*");
search_globs.push_back("/dev/cu.*");
vector<string> devices_found = glob( search_globs );
vector<string>::iterator iter = devices_found.begin();
while( iter != devices_found.end() )
{
string device = *iter++;
vector<string> sysfs_info = get_sysfs_info( device );
string friendly_name = sysfs_info[0];
string hardware_id = sysfs_info[1];
PortInfo device_entry;
device_entry.port = device;
device_entry.description = friendly_name;
device_entry.hardware_id = hardware_id;
results.push_back( device_entry );
}
return results;
}
#endif // defined(__linux__)
@@ -0,0 +1,286 @@
#if defined(__APPLE__)
#include <sys/param.h>
#include <stdint.h>
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/serial/IOSerialKeys.h>
#include <IOKit/IOBSD.h>
#include <iostream>
#include <string>
#include <vector>
#include "serial/serial.h"
using serial::PortInfo;
using std::string;
using std::vector;
#define HARDWARE_ID_STRING_LENGTH 128
string cfstring_to_string( CFStringRef cfstring );
string get_device_path( io_object_t& serial_port );
string get_class_name( io_object_t& obj );
io_registry_entry_t get_parent_iousb_device( io_object_t& serial_port );
string get_string_property( io_object_t& device, const char* property );
uint16_t get_int_property( io_object_t& device, const char* property );
string rtrim(const string& str);
string
cfstring_to_string( CFStringRef cfstring )
{
char cstring[MAXPATHLEN];
string result;
if( cfstring )
{
Boolean success = CFStringGetCString( cfstring,
cstring,
sizeof(cstring),
kCFStringEncodingASCII );
if( success )
result = cstring;
}
return result;
}
string
get_device_path( io_object_t& serial_port )
{
CFTypeRef callout_path;
string device_path;
callout_path = IORegistryEntryCreateCFProperty( serial_port,
CFSTR(kIOCalloutDeviceKey),
kCFAllocatorDefault,
0 );
if (callout_path)
{
if( CFGetTypeID(callout_path) == CFStringGetTypeID() )
device_path = cfstring_to_string( static_cast<CFStringRef>(callout_path) );
CFRelease(callout_path);
}
return device_path;
}
string
get_class_name( io_object_t& obj )
{
string result;
io_name_t class_name;
kern_return_t kern_result;
kern_result = IOObjectGetClass( obj, class_name );
if( kern_result == KERN_SUCCESS )
result = class_name;
return result;
}
io_registry_entry_t
get_parent_iousb_device( io_object_t& serial_port )
{
io_object_t device = serial_port;
io_registry_entry_t parent = 0;
io_registry_entry_t result = 0;
kern_return_t kern_result = KERN_FAILURE;
string name = get_class_name(device);
// Walk the IO Registry tree looking for this devices parent IOUSBDevice.
while( name != "IOUSBDevice" )
{
kern_result = IORegistryEntryGetParentEntry( device,
kIOServicePlane,
&parent );
if(kern_result != KERN_SUCCESS)
{
result = 0;
break;
}
device = parent;
name = get_class_name(device);
}
if(kern_result == KERN_SUCCESS)
result = device;
return result;
}
string
get_string_property( io_object_t& device, const char* property )
{
string property_name;
if( device )
{
CFStringRef property_as_cfstring = CFStringCreateWithCString (
kCFAllocatorDefault,
property,
kCFStringEncodingASCII );
CFTypeRef name_as_cfstring = IORegistryEntryCreateCFProperty(
device,
property_as_cfstring,
kCFAllocatorDefault,
0 );
if( name_as_cfstring )
{
if( CFGetTypeID(name_as_cfstring) == CFStringGetTypeID() )
property_name = cfstring_to_string( static_cast<CFStringRef>(name_as_cfstring) );
CFRelease(name_as_cfstring);
}
if(property_as_cfstring)
CFRelease(property_as_cfstring);
}
return property_name;
}
uint16_t
get_int_property( io_object_t& device, const char* property )
{
uint16_t result = 0;
if( device )
{
CFStringRef property_as_cfstring = CFStringCreateWithCString (
kCFAllocatorDefault,
property,
kCFStringEncodingASCII );
CFTypeRef number = IORegistryEntryCreateCFProperty( device,
property_as_cfstring,
kCFAllocatorDefault,
0 );
if(property_as_cfstring)
CFRelease(property_as_cfstring);
if( number )
{
if( CFGetTypeID(number) == CFNumberGetTypeID() )
{
bool success = CFNumberGetValue( static_cast<CFNumberRef>(number),
kCFNumberSInt16Type,
&result );
if( !success )
result = 0;
}
CFRelease(number);
}
}
return result;
}
string rtrim(const string& str)
{
string result = str;
string whitespace = " \t\f\v\n\r";
std::size_t found = result.find_last_not_of(whitespace);
if (found != std::string::npos)
result.erase(found+1);
else
result.clear();
return result;
}
vector<PortInfo>
serial::list_ports(void)
{
vector<PortInfo> devices_found;
CFMutableDictionaryRef classes_to_match;
io_iterator_t serial_port_iterator;
io_object_t serial_port;
mach_port_t master_port;
kern_return_t kern_result;
kern_result = IOMasterPort(MACH_PORT_NULL, &master_port);
if(kern_result != KERN_SUCCESS)
return devices_found;
classes_to_match = IOServiceMatching(kIOSerialBSDServiceValue);
if (classes_to_match == NULL)
return devices_found;
CFDictionarySetValue( classes_to_match,
CFSTR(kIOSerialBSDTypeKey),
CFSTR(kIOSerialBSDAllTypes) );
kern_result = IOServiceGetMatchingServices(master_port, classes_to_match, &serial_port_iterator);
if (KERN_SUCCESS != kern_result)
return devices_found;
while ( (serial_port = IOIteratorNext(serial_port_iterator)) )
{
string device_path = get_device_path( serial_port );
io_registry_entry_t parent = get_parent_iousb_device( serial_port );
IOObjectRelease(serial_port);
if( device_path.empty() )
continue;
PortInfo port_info;
port_info.port = device_path;
port_info.description = "n/a";
port_info.hardware_id = "n/a";
string device_name = rtrim( get_string_property( parent, "USB Product Name" ) );
string vendor_name = rtrim( get_string_property( parent, "USB Vendor Name") );
string description = rtrim( vendor_name + " " + device_name );
if( !description.empty() )
port_info.description = description;
string serial_number = rtrim(get_string_property( parent, "USB Serial Number" ) );
uint16_t vendor_id = get_int_property( parent, "idVendor" );
uint16_t product_id = get_int_property( parent, "idProduct" );
if( vendor_id && product_id )
{
char cstring[HARDWARE_ID_STRING_LENGTH];
if(serial_number.empty())
serial_number = "None";
int ret = snprintf( cstring, HARDWARE_ID_STRING_LENGTH, "USB VID:PID=%04x:%04x SNR=%s",
vendor_id,
product_id,
serial_number.c_str() );
if( (ret >= 0) && (ret < HARDWARE_ID_STRING_LENGTH) )
port_info.hardware_id = cstring;
}
devices_found.push_back(port_info);
}
IOObjectRelease(serial_port_iterator);
return devices_found;
}
#endif // defined(__APPLE__)
@@ -0,0 +1,152 @@
#if defined(_WIN32)
/*
* Copyright (c) 2014 Craig Lilley <cralilley@gmail.com>
* This software is made available under the terms of the MIT licence.
* A copy of the licence can be obtained from:
* http://opensource.org/licenses/MIT
*/
#include "include/serial.h"
#include <tchar.h>
#include <windows.h>
#include <setupapi.h>
#include <initguid.h>
#include <devguid.h>
#include <cstring>
using serial::PortInfo;
using std::vector;
using std::string;
static const DWORD port_name_max_length = 256;
static const DWORD friendly_name_max_length = 256;
static const DWORD hardware_id_max_length = 256;
// Convert a wide Unicode string to an UTF8 string
std::string utf8_encode(const std::wstring &wstr)
{
int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL);
std::string strTo( size_needed, 0 );
WideCharToMultiByte (CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL);
return strTo;
}
vector<PortInfo>
serial::list_ports()
{
vector<PortInfo> devices_found;
HDEVINFO device_info_set = SetupDiGetClassDevs(
(const GUID *) &GUID_DEVCLASS_PORTS,
NULL,
NULL,
DIGCF_PRESENT);
unsigned int device_info_set_index = 0;
SP_DEVINFO_DATA device_info_data;
device_info_data.cbSize = sizeof(SP_DEVINFO_DATA);
while(SetupDiEnumDeviceInfo(device_info_set, device_info_set_index, &device_info_data))
{
device_info_set_index++;
// Get port name
HKEY hkey = SetupDiOpenDevRegKey(
device_info_set,
&device_info_data,
DICS_FLAG_GLOBAL,
0,
DIREG_DEV,
KEY_READ);
TCHAR port_name[port_name_max_length];
DWORD port_name_length = port_name_max_length;
LONG return_code = RegQueryValueEx(
hkey,
_T("PortName"),
NULL,
NULL,
(LPBYTE)port_name,
&port_name_length);
RegCloseKey(hkey);
if(return_code != EXIT_SUCCESS)
continue;
if(port_name_length > 0 && port_name_length <= port_name_max_length)
port_name[port_name_length-1] = '\0';
else
port_name[0] = '\0';
// Ignore parallel ports
if(_tcsstr(port_name, _T("LPT")) != NULL)
continue;
// Get port friendly name
TCHAR friendly_name[friendly_name_max_length];
DWORD friendly_name_actual_length = 0;
BOOL got_friendly_name = SetupDiGetDeviceRegistryProperty(
device_info_set,
&device_info_data,
SPDRP_FRIENDLYNAME,
NULL,
(PBYTE)friendly_name,
friendly_name_max_length,
&friendly_name_actual_length);
if(got_friendly_name == TRUE && friendly_name_actual_length > 0)
friendly_name[friendly_name_actual_length-1] = '\0';
else
friendly_name[0] = '\0';
// Get hardware ID
TCHAR hardware_id[hardware_id_max_length];
DWORD hardware_id_actual_length = 0;
BOOL got_hardware_id = SetupDiGetDeviceRegistryProperty(
device_info_set,
&device_info_data,
SPDRP_HARDWAREID,
NULL,
(PBYTE)hardware_id,
hardware_id_max_length,
&hardware_id_actual_length);
if(got_hardware_id == TRUE && hardware_id_actual_length > 0)
hardware_id[hardware_id_actual_length-1] = '\0';
else
hardware_id[0] = '\0';
#ifdef UNICODE
std::string portName = utf8_encode(port_name);
std::string friendlyName = utf8_encode(friendly_name);
std::string hardwareId = utf8_encode(hardware_id);
#else
std::string portName = port_name;
std::string friendlyName = friendly_name;
std::string hardwareId = hardware_id;
#endif
PortInfo port_entry;
port_entry.port = portName;
port_entry.description = friendlyName;
port_entry.hardware_id = hardwareId;
devices_found.push_back(port_entry);
}
SetupDiDestroyDeviceInfoList(device_info_set);
return devices_found;
}
#endif // #if defined(_WIN32)
File diff suppressed because it is too large Load Diff
+640
View File
@@ -0,0 +1,640 @@
#if defined(_WIN32)
/* Copyright 2012 William Woodall and John Harrison */
#include <sstream>
#include "include/impl/win.h"
using std::string;
using std::wstring;
using std::stringstream;
using std::invalid_argument;
using serial::Serial;
using serial::Timeout;
using serial::bytesize_t;
using serial::parity_t;
using serial::stopbits_t;
using serial::flowcontrol_t;
using serial::SerialException;
using serial::PortNotOpenedException;
using serial::IOException;
inline wstring
_prefix_port_if_needed(const wstring &input)
{
static wstring windows_com_port_prefix = L"\\\\.\\";
if (input.compare(windows_com_port_prefix) != 0)
{
return windows_com_port_prefix + input;
}
return input;
}
Serial::SerialImpl::SerialImpl (const string &port, unsigned long baudrate,
bytesize_t bytesize,
parity_t parity, stopbits_t stopbits,
flowcontrol_t flowcontrol)
: port_ (port.begin(), port.end()), fd_ (INVALID_HANDLE_VALUE), is_open_ (false),
baudrate_ (baudrate), parity_ (parity),
bytesize_ (bytesize), stopbits_ (stopbits), flowcontrol_ (flowcontrol)
{
read_mutex = CreateMutex(NULL, false, NULL);
write_mutex = CreateMutex(NULL, false, NULL);
if (port_.empty () == false)
open ();
}
Serial::SerialImpl::~SerialImpl ()
{
this->close();
CloseHandle(read_mutex);
CloseHandle(write_mutex);
}
void
Serial::SerialImpl::open ()
{
if (port_.empty ()) {
throw invalid_argument ("Empty port is invalid.");
}
if (is_open_ == true) {
throw SerialException ("Serial port already open.");
}
// See: https://github.com/wjwwood/serial/issues/84
wstring port_with_prefix = _prefix_port_if_needed(port_);
LPCWSTR lp_port = port_with_prefix.c_str();
fd_ = CreateFileW(lp_port,
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if (fd_ == INVALID_HANDLE_VALUE) {
DWORD errno_ = GetLastError();
stringstream ss;
switch (errno_) {
case ERROR_FILE_NOT_FOUND:
// Use this->getPort to convert to a std::string
ss << "Specified port, " << this->getPort() << ", does not exist.";
THROW (IOException, ss.str().c_str());
default:
ss << "Unknown error opening the serial port: " << errno;
THROW (IOException, ss.str().c_str());
}
}
reconfigurePort();
is_open_ = true;
}
void
Serial::SerialImpl::reconfigurePort ()
{
if (fd_ == INVALID_HANDLE_VALUE) {
// Can only operate on a valid file descriptor
THROW (IOException, "Invalid file descriptor, is the serial port open?");
}
DCB dcbSerialParams = {0};
dcbSerialParams.DCBlength=sizeof(dcbSerialParams);
if (!GetCommState(fd_, &dcbSerialParams)) {
//error getting state
THROW (IOException, "Error getting the serial port state.");
}
// setup baud rate
switch (baudrate_) {
#ifdef CBR_0
case 0: dcbSerialParams.BaudRate = CBR_0; break;
#endif
#ifdef CBR_50
case 50: dcbSerialParams.BaudRate = CBR_50; break;
#endif
#ifdef CBR_75
case 75: dcbSerialParams.BaudRate = CBR_75; break;
#endif
#ifdef CBR_110
case 110: dcbSerialParams.BaudRate = CBR_110; break;
#endif
#ifdef CBR_134
case 134: dcbSerialParams.BaudRate = CBR_134; break;
#endif
#ifdef CBR_150
case 150: dcbSerialParams.BaudRate = CBR_150; break;
#endif
#ifdef CBR_200
case 200: dcbSerialParams.BaudRate = CBR_200; break;
#endif
#ifdef CBR_300
case 300: dcbSerialParams.BaudRate = CBR_300; break;
#endif
#ifdef CBR_600
case 600: dcbSerialParams.BaudRate = CBR_600; break;
#endif
#ifdef CBR_1200
case 1200: dcbSerialParams.BaudRate = CBR_1200; break;
#endif
#ifdef CBR_1800
case 1800: dcbSerialParams.BaudRate = CBR_1800; break;
#endif
#ifdef CBR_2400
case 2400: dcbSerialParams.BaudRate = CBR_2400; break;
#endif
#ifdef CBR_4800
case 4800: dcbSerialParams.BaudRate = CBR_4800; break;
#endif
#ifdef CBR_7200
case 7200: dcbSerialParams.BaudRate = CBR_7200; break;
#endif
#ifdef CBR_9600
case 9600: dcbSerialParams.BaudRate = CBR_9600; break;
#endif
#ifdef CBR_14400
case 14400: dcbSerialParams.BaudRate = CBR_14400; break;
#endif
#ifdef CBR_19200
case 19200: dcbSerialParams.BaudRate = CBR_19200; break;
#endif
#ifdef CBR_28800
case 28800: dcbSerialParams.BaudRate = CBR_28800; break;
#endif
#ifdef CBR_57600
case 57600: dcbSerialParams.BaudRate = CBR_57600; break;
#endif
#ifdef CBR_76800
case 76800: dcbSerialParams.BaudRate = CBR_76800; break;
#endif
#ifdef CBR_38400
case 38400: dcbSerialParams.BaudRate = CBR_38400; break;
#endif
#ifdef CBR_115200
case 115200: dcbSerialParams.BaudRate = CBR_115200; break;
#endif
#ifdef CBR_128000
case 128000: dcbSerialParams.BaudRate = CBR_128000; break;
#endif
#ifdef CBR_153600
case 153600: dcbSerialParams.BaudRate = CBR_153600; break;
#endif
#ifdef CBR_230400
case 230400: dcbSerialParams.BaudRate = CBR_230400; break;
#endif
#ifdef CBR_256000
case 256000: dcbSerialParams.BaudRate = CBR_256000; break;
#endif
#ifdef CBR_460800
case 460800: dcbSerialParams.BaudRate = CBR_460800; break;
#endif
#ifdef CBR_921600
case 921600: dcbSerialParams.BaudRate = CBR_921600; break;
#endif
default:
// Try to blindly assign it
dcbSerialParams.BaudRate = baudrate_;
}
// setup char len
if (bytesize_ == eightbits)
dcbSerialParams.ByteSize = 8;
else if (bytesize_ == sevenbits)
dcbSerialParams.ByteSize = 7;
else if (bytesize_ == sixbits)
dcbSerialParams.ByteSize = 6;
else if (bytesize_ == fivebits)
dcbSerialParams.ByteSize = 5;
else
throw invalid_argument ("invalid char len");
// setup stopbits
if (stopbits_ == stopbits_one)
dcbSerialParams.StopBits = ONESTOPBIT;
else if (stopbits_ == stopbits_one_point_five)
dcbSerialParams.StopBits = ONE5STOPBITS;
else if (stopbits_ == stopbits_two)
dcbSerialParams.StopBits = TWOSTOPBITS;
else
throw invalid_argument ("invalid stop bit");
// setup parity
if (parity_ == parity_none) {
dcbSerialParams.Parity = NOPARITY;
} else if (parity_ == parity_even) {
dcbSerialParams.Parity = EVENPARITY;
} else if (parity_ == parity_odd) {
dcbSerialParams.Parity = ODDPARITY;
} else if (parity_ == parity_mark) {
dcbSerialParams.Parity = MARKPARITY;
} else if (parity_ == parity_space) {
dcbSerialParams.Parity = SPACEPARITY;
} else {
throw invalid_argument ("invalid parity");
}
// setup flowcontrol
if (flowcontrol_ == flowcontrol_none) {
dcbSerialParams.fOutxCtsFlow = false;
dcbSerialParams.fRtsControl = 0x00;
dcbSerialParams.fOutX = false;
dcbSerialParams.fInX = false;
}
if (flowcontrol_ == flowcontrol_software) {
dcbSerialParams.fOutxCtsFlow = false;
dcbSerialParams.fRtsControl = 0x00;
dcbSerialParams.fOutX = true;
dcbSerialParams.fInX = true;
}
if (flowcontrol_ == flowcontrol_hardware) {
dcbSerialParams.fOutxCtsFlow = true;
dcbSerialParams.fRtsControl = 0x03;
dcbSerialParams.fOutX = false;
dcbSerialParams.fInX = false;
}
// activate settings
if (!SetCommState(fd_, &dcbSerialParams)){
CloseHandle(fd_);
THROW (IOException, "Error setting serial port settings.");
}
// Setup timeouts
COMMTIMEOUTS timeouts = {0};
timeouts.ReadIntervalTimeout = timeout_.inter_byte_timeout;
timeouts.ReadTotalTimeoutConstant = timeout_.read_timeout_constant;
timeouts.ReadTotalTimeoutMultiplier = timeout_.read_timeout_multiplier;
timeouts.WriteTotalTimeoutConstant = timeout_.write_timeout_constant;
timeouts.WriteTotalTimeoutMultiplier = timeout_.write_timeout_multiplier;
if (!SetCommTimeouts(fd_, &timeouts)) {
THROW (IOException, "Error setting timeouts.");
}
}
void
Serial::SerialImpl::close ()
{
if (is_open_ == true) {
if (fd_ != INVALID_HANDLE_VALUE) {
int ret;
ret = CloseHandle(fd_);
if (ret == 0) {
stringstream ss;
ss << "Error while closing serial port: " << GetLastError();
THROW (IOException, ss.str().c_str());
} else {
fd_ = INVALID_HANDLE_VALUE;
}
}
is_open_ = false;
}
}
bool
Serial::SerialImpl::isOpen () const
{
return is_open_;
}
size_t
Serial::SerialImpl::available ()
{
if (!is_open_) {
return 0;
}
COMSTAT cs;
if (!ClearCommError(fd_, NULL, &cs)) {
stringstream ss;
ss << "Error while checking status of the serial port: " << GetLastError();
THROW (IOException, ss.str().c_str());
}
return static_cast<size_t>(cs.cbInQue);
}
bool
Serial::SerialImpl::waitReadable (uint32_t /*timeout*/)
{
THROW (IOException, "waitReadable is not implemented on Windows.");
return false;
}
void
Serial::SerialImpl::waitByteTimes (size_t /*count*/)
{
THROW (IOException, "waitByteTimes is not implemented on Windows.");
}
size_t
Serial::SerialImpl::read (uint8_t *buf, size_t size)
{
if (!is_open_) {
throw PortNotOpenedException ("Serial::read");
}
DWORD bytes_read;
if (!ReadFile(fd_, buf, static_cast<DWORD>(size), &bytes_read, NULL)) {
stringstream ss;
ss << "Error while reading from the serial port: " << GetLastError();
THROW (IOException, ss.str().c_str());
}
return (size_t) (bytes_read);
}
size_t
Serial::SerialImpl::write (const uint8_t *data, size_t length)
{
if (is_open_ == false) {
throw PortNotOpenedException ("Serial::write");
}
DWORD bytes_written;
if (!WriteFile(fd_, data, static_cast<DWORD>(length), &bytes_written, NULL)) {
stringstream ss;
ss << "Error while writing to the serial port: " << GetLastError();
THROW (IOException, ss.str().c_str());
}
return (size_t) (bytes_written);
}
void
Serial::SerialImpl::setPort (const string &port)
{
port_ = wstring(port.begin(), port.end());
}
string
Serial::SerialImpl::getPort () const
{
return string(port_.begin(), port_.end());
}
void
Serial::SerialImpl::setTimeout (serial::Timeout &timeout)
{
timeout_ = timeout;
if (is_open_) {
reconfigurePort ();
}
}
serial::Timeout
Serial::SerialImpl::getTimeout () const
{
return timeout_;
}
void
Serial::SerialImpl::setBaudrate (unsigned long baudrate)
{
baudrate_ = baudrate;
if (is_open_) {
reconfigurePort ();
}
}
unsigned long
Serial::SerialImpl::getBaudrate () const
{
return baudrate_;
}
void
Serial::SerialImpl::setBytesize (serial::bytesize_t bytesize)
{
bytesize_ = bytesize;
if (is_open_) {
reconfigurePort ();
}
}
serial::bytesize_t
Serial::SerialImpl::getBytesize () const
{
return bytesize_;
}
void
Serial::SerialImpl::setParity (serial::parity_t parity)
{
parity_ = parity;
if (is_open_) {
reconfigurePort ();
}
}
serial::parity_t
Serial::SerialImpl::getParity () const
{
return parity_;
}
void
Serial::SerialImpl::setStopbits (serial::stopbits_t stopbits)
{
stopbits_ = stopbits;
if (is_open_) {
reconfigurePort ();
}
}
serial::stopbits_t
Serial::SerialImpl::getStopbits () const
{
return stopbits_;
}
void
Serial::SerialImpl::setFlowcontrol (serial::flowcontrol_t flowcontrol)
{
flowcontrol_ = flowcontrol;
if (is_open_) {
reconfigurePort ();
}
}
serial::flowcontrol_t
Serial::SerialImpl::getFlowcontrol () const
{
return flowcontrol_;
}
void
Serial::SerialImpl::flush ()
{
if (is_open_ == false) {
throw PortNotOpenedException ("Serial::flush");
}
FlushFileBuffers (fd_);
}
void
Serial::SerialImpl::flushInput ()
{
THROW (IOException, "flushInput is not supported on Windows.");
}
void
Serial::SerialImpl::flushOutput ()
{
THROW (IOException, "flushOutput is not supported on Windows.");
}
void
Serial::SerialImpl::sendBreak (int /*duration*/)
{
THROW (IOException, "sendBreak is not supported on Windows.");
}
void
Serial::SerialImpl::setBreak (bool level)
{
if (is_open_ == false) {
throw PortNotOpenedException ("Serial::setBreak");
}
if (level) {
EscapeCommFunction (fd_, SETBREAK);
} else {
EscapeCommFunction (fd_, CLRBREAK);
}
}
void
Serial::SerialImpl::setRTS (bool level)
{
if (is_open_ == false) {
throw PortNotOpenedException ("Serial::setRTS");
}
if (level) {
EscapeCommFunction (fd_, SETRTS);
} else {
EscapeCommFunction (fd_, CLRRTS);
}
}
void
Serial::SerialImpl::setDTR (bool level)
{
if (is_open_ == false) {
throw PortNotOpenedException ("Serial::setDTR");
}
if (level) {
EscapeCommFunction (fd_, SETDTR);
} else {
EscapeCommFunction (fd_, CLRDTR);
}
}
bool
Serial::SerialImpl::waitForChange ()
{
if (is_open_ == false) {
throw PortNotOpenedException ("Serial::waitForChange");
}
DWORD dwCommEvent;
if (!SetCommMask(fd_, EV_CTS | EV_DSR | EV_RING | EV_RLSD)) {
// Error setting communications mask
return false;
}
if (!WaitCommEvent(fd_, &dwCommEvent, NULL)) {
// An error occurred waiting for the event.
return false;
} else {
// Event has occurred.
return true;
}
}
bool
Serial::SerialImpl::getCTS ()
{
if (is_open_ == false) {
throw PortNotOpenedException ("Serial::getCTS");
}
DWORD dwModemStatus;
if (!GetCommModemStatus(fd_, &dwModemStatus)) {
THROW (IOException, "Error getting the status of the CTS line.");
}
return (MS_CTS_ON & dwModemStatus) != 0;
}
bool
Serial::SerialImpl::getDSR ()
{
if (is_open_ == false) {
throw PortNotOpenedException ("Serial::getDSR");
}
DWORD dwModemStatus;
if (!GetCommModemStatus(fd_, &dwModemStatus)) {
THROW (IOException, "Error getting the status of the DSR line.");
}
return (MS_DSR_ON & dwModemStatus) != 0;
}
bool
Serial::SerialImpl::getRI()
{
if (is_open_ == false) {
throw PortNotOpenedException ("Serial::getRI");
}
DWORD dwModemStatus;
if (!GetCommModemStatus(fd_, &dwModemStatus)) {
THROW (IOException, "Error getting the status of the RI line.");
}
return (MS_RING_ON & dwModemStatus) != 0;
}
bool
Serial::SerialImpl::getCD()
{
if (is_open_ == false) {
throw PortNotOpenedException ("Serial::getCD");
}
DWORD dwModemStatus;
if (!GetCommModemStatus(fd_, &dwModemStatus)) {
// Error in GetCommModemStatus;
THROW (IOException, "Error getting the status of the CD line.");
}
return (MS_RLSD_ON & dwModemStatus) != 0;
}
void
Serial::SerialImpl::readLock()
{
if (WaitForSingleObject(read_mutex, INFINITE) != WAIT_OBJECT_0) {
THROW (IOException, "Error claiming read mutex.");
}
}
void
Serial::SerialImpl::readUnlock()
{
if (!ReleaseMutex(read_mutex)) {
THROW (IOException, "Error releasing read mutex.");
}
}
void
Serial::SerialImpl::writeLock()
{
if (WaitForSingleObject(write_mutex, INFINITE) != WAIT_OBJECT_0) {
THROW (IOException, "Error claiming write mutex.");
}
}
void
Serial::SerialImpl::writeUnlock()
{
if (!ReleaseMutex(write_mutex)) {
THROW (IOException, "Error releasing write mutex.");
}
}
#endif // #if defined(_WIN32)
+415
View File
@@ -0,0 +1,415 @@
/* Copyright 2012 William Woodall and John Harrison */
#include <algorithm>
#if !defined(_WIN32) && !defined(__OpenBSD__) && !defined(__FreeBSD__)
# include <alloca.h>
#endif
#if defined (__MINGW32__)
# define alloca __builtin_alloca
#endif
#ifdef _WIN32
#include "include/serial.h"
#include "include/impl/win.h"
#else
#include "../include/serial.h"
#include "../include/impl/unix.h"
#endif
using std::invalid_argument;
using std::min;
using std::numeric_limits;
using std::vector;
using std::size_t;
using std::string;
using serial::Serial;
using serial::SerialException;
using serial::IOException;
using serial::bytesize_t;
using serial::parity_t;
using serial::stopbits_t;
using serial::flowcontrol_t;
class Serial::ScopedReadLock {
public:
ScopedReadLock(SerialImpl *pimpl) : pimpl_(pimpl) {
this->pimpl_->readLock();
}
~ScopedReadLock() {
this->pimpl_->readUnlock();
}
private:
// Disable copy constructors
ScopedReadLock(const ScopedReadLock&);
const ScopedReadLock& operator=(ScopedReadLock);
SerialImpl *pimpl_;
};
class Serial::ScopedWriteLock {
public:
ScopedWriteLock(SerialImpl *pimpl) : pimpl_(pimpl) {
this->pimpl_->writeLock();
}
~ScopedWriteLock() {
this->pimpl_->writeUnlock();
}
private:
// Disable copy constructors
ScopedWriteLock(const ScopedWriteLock&);
const ScopedWriteLock& operator=(ScopedWriteLock);
SerialImpl *pimpl_;
};
Serial::Serial (const string &port, uint32_t baudrate, serial::Timeout timeout,
bytesize_t bytesize, parity_t parity, stopbits_t stopbits,
flowcontrol_t flowcontrol)
: pimpl_(new SerialImpl (port, baudrate, bytesize, parity,
stopbits, flowcontrol))
{
pimpl_->setTimeout(timeout);
}
Serial::~Serial ()
{
delete pimpl_;
}
void
Serial::open ()
{
pimpl_->open ();
}
void
Serial::close ()
{
pimpl_->close ();
}
bool
Serial::isOpen () const
{
return pimpl_->isOpen ();
}
size_t
Serial::available ()
{
return pimpl_->available ();
}
bool
Serial::waitReadable ()
{
serial::Timeout timeout(pimpl_->getTimeout ());
return pimpl_->waitReadable(timeout.read_timeout_constant);
}
void
Serial::waitByteTimes (size_t count)
{
pimpl_->waitByteTimes(count);
}
size_t
Serial::read_ (uint8_t *buffer, size_t size)
{
return this->pimpl_->read (buffer, size);
}
size_t
Serial::read (uint8_t *buffer, size_t size)
{
ScopedReadLock lock(this->pimpl_);
return this->pimpl_->read (buffer, size);
}
size_t
Serial::read (std::vector<uint8_t> &buffer, size_t size)
{
ScopedReadLock lock(this->pimpl_);
uint8_t *buffer_ = new uint8_t[size];
size_t bytes_read = this->pimpl_->read (buffer_, size);
buffer.insert (buffer.end (), buffer_, buffer_+bytes_read);
delete[] buffer_;
return bytes_read;
}
size_t
Serial::read (std::string &buffer, size_t size)
{
ScopedReadLock lock(this->pimpl_);
uint8_t *buffer_ = new uint8_t[size];
size_t bytes_read = this->pimpl_->read (buffer_, size);
buffer.append (reinterpret_cast<const char*>(buffer_), bytes_read);
delete[] buffer_;
return bytes_read;
}
string
Serial::read (size_t size)
{
std::string buffer;
this->read (buffer, size);
return buffer;
}
size_t
Serial::readline (string &buffer, size_t size, string eol)
{
ScopedReadLock lock(this->pimpl_);
size_t eol_len = eol.length ();
uint8_t *buffer_ = static_cast<uint8_t*>
(alloca (size * sizeof (uint8_t)));
size_t read_so_far = 0;
while (true)
{
size_t bytes_read = this->read_ (buffer_ + read_so_far, 1);
read_so_far += bytes_read;
if (bytes_read == 0) {
break; // Timeout occured on reading 1 byte
}
if (string (reinterpret_cast<const char*>
(buffer_ + read_so_far - eol_len), eol_len) == eol) {
break; // EOL found
}
if (read_so_far == size) {
break; // Reached the maximum read length
}
}
buffer.append(reinterpret_cast<const char*> (buffer_), read_so_far);
return read_so_far;
}
string
Serial::readline (size_t size, string eol)
{
std::string buffer;
this->readline (buffer, size, eol);
return buffer;
}
vector<string>
Serial::readlines (size_t size, string eol)
{
ScopedReadLock lock(this->pimpl_);
std::vector<std::string> lines;
size_t eol_len = eol.length ();
uint8_t *buffer_ = static_cast<uint8_t*>
(alloca (size * sizeof (uint8_t)));
size_t read_so_far = 0;
size_t start_of_line = 0;
while (read_so_far < size) {
size_t bytes_read = this->read_ (buffer_+read_so_far, 1);
read_so_far += bytes_read;
if (bytes_read == 0) {
if (start_of_line != read_so_far) {
lines.push_back (
string (reinterpret_cast<const char*> (buffer_ + start_of_line),
read_so_far - start_of_line));
}
break; // Timeout occured on reading 1 byte
}
if (string (reinterpret_cast<const char*>
(buffer_ + read_so_far - eol_len), eol_len) == eol) {
// EOL found
lines.push_back(
string(reinterpret_cast<const char*> (buffer_ + start_of_line),
read_so_far - start_of_line));
start_of_line = read_so_far;
}
if (read_so_far == size) {
if (start_of_line != read_so_far) {
lines.push_back(
string(reinterpret_cast<const char*> (buffer_ + start_of_line),
read_so_far - start_of_line));
}
break; // Reached the maximum read length
}
}
return lines;
}
size_t
Serial::write (const string &data)
{
ScopedWriteLock lock(this->pimpl_);
return this->write_ (reinterpret_cast<const uint8_t*>(data.c_str()),
data.length());
}
size_t
Serial::write (const std::vector<uint8_t> &data)
{
ScopedWriteLock lock(this->pimpl_);
return this->write_ (&data[0], data.size());
}
size_t
Serial::write (const uint8_t *data, size_t size)
{
ScopedWriteLock lock(this->pimpl_);
return this->write_(data, size);
}
size_t
Serial::write_ (const uint8_t *data, size_t length)
{
return pimpl_->write (data, length);
}
void
Serial::setPort (const string &port)
{
ScopedReadLock rlock(this->pimpl_);
ScopedWriteLock wlock(this->pimpl_);
bool was_open = pimpl_->isOpen ();
if (was_open) close();
pimpl_->setPort (port);
if (was_open) open ();
}
string
Serial::getPort () const
{
return pimpl_->getPort ();
}
void
Serial::setTimeout (serial::Timeout &timeout)
{
pimpl_->setTimeout (timeout);
}
serial::Timeout
Serial::getTimeout () const {
return pimpl_->getTimeout ();
}
void
Serial::setBaudrate (uint32_t baudrate)
{
pimpl_->setBaudrate (baudrate);
}
uint32_t
Serial::getBaudrate () const
{
return uint32_t(pimpl_->getBaudrate ());
}
void
Serial::setBytesize (bytesize_t bytesize)
{
pimpl_->setBytesize (bytesize);
}
bytesize_t
Serial::getBytesize () const
{
return pimpl_->getBytesize ();
}
void
Serial::setParity (parity_t parity)
{
pimpl_->setParity (parity);
}
parity_t
Serial::getParity () const
{
return pimpl_->getParity ();
}
void
Serial::setStopbits (stopbits_t stopbits)
{
pimpl_->setStopbits (stopbits);
}
stopbits_t
Serial::getStopbits () const
{
return pimpl_->getStopbits ();
}
void
Serial::setFlowcontrol (flowcontrol_t flowcontrol)
{
pimpl_->setFlowcontrol (flowcontrol);
}
flowcontrol_t
Serial::getFlowcontrol () const
{
return pimpl_->getFlowcontrol ();
}
void Serial::flush ()
{
ScopedReadLock rlock(this->pimpl_);
ScopedWriteLock wlock(this->pimpl_);
pimpl_->flush ();
}
void Serial::flushInput ()
{
ScopedReadLock lock(this->pimpl_);
pimpl_->flushInput ();
}
void Serial::flushOutput ()
{
ScopedWriteLock lock(this->pimpl_);
pimpl_->flushOutput ();
}
void Serial::sendBreak (int duration)
{
pimpl_->sendBreak (duration);
}
void Serial::setBreak (bool level)
{
pimpl_->setBreak (level);
}
void Serial::setRTS (bool level)
{
pimpl_->setRTS (level);
}
void Serial::setDTR (bool level)
{
pimpl_->setDTR (level);
}
bool Serial::waitForChange()
{
return pimpl_->waitForChange();
}
bool Serial::getCTS ()
{
return pimpl_->getCTS ();
}
bool Serial::getDSR ()
{
return pimpl_->getDSR ();
}
bool Serial::getRI ()
{
return pimpl_->getRI ();
}
bool Serial::getCD ()
{
return pimpl_->getCD ();
}
+113
View File
@@ -0,0 +1,113 @@
newmtl bob1:initialShadingGroup
illum 4
Kd 0.50 0.50 0.50
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl initialShadingGroup
illum 4
Kd 0.67 0.67 0.67
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert2SG
illum 4
Kd 0.20 0.32 0.50
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert5SG
illum 4
Kd 1.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert6SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert7SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert8SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert10SG
illum 4
Kd 1.00 1.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert12SG
illum 4
Kd 0.58 0.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert13SG
illum 4
Kd 0.00 1.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert14SG
illum 4
Kd 1.00 1.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert15SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd TheThing2.png
Ni 1.00
newmtl lambert16SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd SkateboardwielThing.png
Ni 1.00
newmtl lambert17SG
illum 4
Kd 0.25 0.25 0.25
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
newmtl lambert18SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd BobStoneTexture.png
Ni 1.00
Ks 0.50 0.50 0.50
newmtl pasted__lambert2SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl pasted__lambert4SG
illum 4
Kd 0.50 1.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl pasted__lambert5SG
illum 4
Kd 0.00 1.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
+9
View File
@@ -0,0 +1,9 @@
newmtl BobRock:lambert18SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd Bobhelemaal2.png
Ni 1.00
Ks 0.50 0.50 0.50
Ns 0.06
+113
View File
@@ -0,0 +1,113 @@
newmtl bob1:initialShadingGroup
illum 4
Kd 0.50 0.50 0.50
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl initialShadingGroup
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert2SG
illum 4
Kd 0.20 0.32 0.50
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert5SG
illum 4
Kd 1.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert6SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert7SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert8SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert10SG
illum 4
Kd 1.00 1.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert12SG
illum 4
Kd 0.58 0.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert13SG
illum 4
Kd 0.00 1.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert14SG
illum 4
Kd 1.00 1.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert15SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd TheThing2.png
Ni 1.00
newmtl lambert16SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd SkateboardwielThing.png
Ni 1.00
newmtl lambert17SG
illum 4
Kd 0.25 0.25 0.25
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
newmtl lambert18SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd BobStoneTexture.png
Ni 1.00
Ks 0.50 0.50 0.50
newmtl pasted__lambert2SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl pasted__lambert4SG
illum 4
Kd 0.50 1.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl pasted__lambert5SG
illum 4
Kd 0.00 1.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 599 KiB

+6
View File
@@ -0,0 +1,6 @@
newmtl initialShadingGroup
illum 4
Kd 1.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
Binary file not shown.

After

Width:  |  Height:  |  Size: 468 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 KiB

+7
View File
@@ -0,0 +1,7 @@
newmtl Monkey1:initialShadingGroup
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd tex_wendy.jpg
Ni 1.00
+99
View File
@@ -0,0 +1,99 @@
newmtl SpringIsComing:Material_007
illum 4
Kd 0.75 0.80 0.80
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree01:Material_001
illum 4
Kd 0.01 0.00 0.00
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree01:Material_004
illum 4
Kd 0.60 0.20 0.30
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree02:Material_001
illum 4
Kd 0.01 0.00 0.00
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree02:Material_004
illum 4
Kd 0.60 0.20 0.30
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree03:Material_001
illum 4
Kd 0.01 0.00 0.00
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree03:Material_004
illum 4
Kd 0.60 0.20 0.30
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree04:Material_001
illum 4
Kd 0.01 0.00 0.00
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl Tree04:Material_004
illum 4
Kd 0.60 0.20 0.30
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
newmtl initialShadingGroup
illum 4
Kd 0.34 0.34 0.34
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert2SG
illum 4
Kd 0.00 1.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert3SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd InktvisTextureRock.png
Ni 1.00
newmtl rock3:Material_016
illum 4
Kd 0.64 0.64 0.64
Ka 1.00 1.00 1.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
Ns 96.08
+7
View File
@@ -0,0 +1,7 @@
newmtl SquidRock:lambert3SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd InktvisTextureFire.png
Ni 1.00
+7
View File
@@ -0,0 +1,7 @@
newmtl Squid:lambert3SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd InktvisTextureRock.png
Ni 1.00
+7
View File
@@ -0,0 +1,7 @@
newmtl VincentRock:lambert23SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd VincentTextureFire.png
Ni 1.00
+147
View File
@@ -0,0 +1,147 @@
newmtl bob1:initialShadingGroup
illum 4
Kd 0.50 0.50 0.50
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl initialShadingGroup
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert2SG
illum 4
Kd 0.20 0.32 0.50
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert5SG
illum 4
Kd 1.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert6SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert7SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd Screenshot_1.png
Ni 1.00
newmtl lambert8SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd Screenshot_1.png
Ni 1.00
newmtl lambert10SG
illum 4
Kd 1.00 1.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert12SG
illum 4
Kd 0.58 0.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert13SG
illum 4
Kd 0.00 1.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert14SG
illum 4
Kd 1.00 1.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert15SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd TheThing2.png
Ni 1.00
newmtl lambert16SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd SkateboardwielThing.png
Ni 1.00
newmtl lambert17SG
illum 4
Kd 0.25 0.25 0.25
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
Ks 0.50 0.50 0.50
newmtl lambert18SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd BobStoneTexture.png
Ni 1.00
Ks 0.50 0.50 0.50
newmtl lambert19SG
illum 4
Kd 0.85 0.85 0.85
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert20SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 0.64 0.64 0.64
Ni 1.00
newmtl lambert21SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert22SG
illum 4
Kd 0.50 0.50 0.50
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert23SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd VincentTexture.png
Ni 1.00
newmtl pasted__lambert2SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd Screenshot_1.png
Ni 1.00
newmtl pasted__lambert4SG
illum 4
Kd 0.50 1.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl pasted__lambert5SG
illum 4
Kd 0.00 1.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

+6
View File
@@ -0,0 +1,6 @@
newmtl Cave1:pasted__lambert4SG
illum 4
Kd 0.13 0.14 0.16
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

+6
View File
@@ -0,0 +1,6 @@
newmtl lambert2SG
illum 4
Kd 1.00 1.00 1.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
File diff suppressed because it is too large Load Diff
+13
View File
@@ -0,0 +1,13 @@
newmtl Cave1:pasted__lambert4SG
illum 4
Kd 0.13 0.14 0.16
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert2SG
illum 4
Kd 0.00 0.00 0.00
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
map_Kd DragonWallAwesome.png
Ni 1.00
+509
View File
@@ -0,0 +1,509 @@
# This file uses centimeters as units for non-parametric coordinates.
mtllib DragonWall1.mtl
g default
v 31.479097 0.032439 -6.902821
v -31.479097 0.032439 -6.902821
v 31.479097 37.811227 -7.156591
v -31.479097 37.811227 -7.156591
v 31.479097 37.755655 4.670846
v -31.479097 37.765894 2.489812
v 33.071286 -0.014894 3.168986
v -31.479097 -0.027298 5.808684
v 0.000000 18.856953 6.775930
v 0.000000 37.743745 6.815244
v -0.000000 -0.032441 6.902821
v 31.479097 18.856953 6.775930
v 31.479097 19.806234 -7.035645
v -31.479097 19.806234 -7.035645
v -33.219027 18.856953 6.775930
v 15.739548 37.746344 6.649046
v 15.739548 28.301650 6.712488
v 15.739548 9.412260 6.839373
v 15.739548 -0.016573 3.526865
v 15.739548 18.854960 8.669850
v -15.739548 37.744744 6.751334
v -15.739548 28.294204 8.320270
v -15.739548 18.850288 7.202108
v -15.739548 9.405386 7.278817
v -15.739548 -0.022680 6.278613
v 33.762048 28.317519 3.336535
v 0.000000 28.303989 9.058642
v -31.479097 28.301650 6.712488
v -31.479097 9.415253 6.202581
v 0.000000 9.409420 9.521046
v 32.843955 9.428125 3.463421
v -7.869774 23.581444 7.644574
v 7.869774 23.573183 9.630958
v 7.869774 14.131984 8.590231
v -7.869774 14.108179 8.497199
v -23.609324 4.689909 6.871096
v -23.609324 14.127120 9.157310
v -23.609324 23.559216 8.028686
v -23.609324 33.005188 8.902707
v -7.869774 33.026725 6.506093
v 7.869774 33.018276 7.046262
v 23.609324 33.028606 6.385878
v 23.609324 23.583752 6.460023
v 23.609324 14.134605 6.807655
v 23.609324 4.714278 5.313189
v 7.869774 4.689909 6.871096
v -7.869774 4.679063 9.179434
v 34.217941 19.089080 3.398532
v -34.325875 33.612990 -1.033724
v -31.479097 28.808740 -7.096119
v -31.479097 23.952114 -0.326363
v -31.479097 14.375229 -0.116500
v -31.479097 9.919341 -6.969232
v -33.938226 5.088499 0.159210
v 34.829148 32.894605 -1.722389
v 31.479097 28.808740 -7.096119
v 31.479097 24.009146 -1.913821
v 32.610234 14.557205 -1.725438
v 31.479097 9.919341 -6.969232
v 33.671430 5.250531 -1.145710
v 7.869774 37.746344 6.649046
v 7.869774 28.272630 9.815706
v 7.869774 18.875384 6.480806
v 7.869774 9.403860 8.626516
v 7.869774 -0.024507 5.214843
v 23.261588 37.750794 5.703650
v 24.750799 28.322892 4.173673
v 23.609324 18.851017 8.038712
v 24.291751 9.425791 4.793524
v 24.405418 -0.015655 3.342998
v -7.857922 37.746344 6.649046
v -7.869774 28.316095 7.602681
v -7.869774 18.846561 7.440290
v -7.869774 9.397081 9.059896
v -7.869774 -0.032441 6.902821
v -23.609324 -0.029871 6.355752
v -23.609324 9.412749 6.585387
v -24.479289 18.828812 8.575101
v -23.609324 28.268887 9.373000
v -23.609324 37.756119 4.569429
v -31.479097 33.033772 4.601150
v -15.739548 33.017513 7.661214
v 0.000000 33.011427 8.732246
v 15.739548 33.023997 6.680767
v 32.620573 33.036587 4.003690
v 32.620573 23.587235 5.056233
v 15.739548 23.576169 7.827765
v 0.000000 23.575834 8.213789
v -15.739548 23.575492 7.553615
v -32.349062 23.579301 6.744209
v -32.349062 14.136103 6.489256
v -15.739548 14.117970 7.871304
v 0.000000 14.129481 8.385483
v 15.739548 14.131662 7.879160
v 32.161526 14.142540 5.119675
v 32.957620 4.706616 3.316203
v 15.739548 4.697844 5.183119
v 0.000000 4.685021 8.433733
v -15.739548 4.708207 5.701237
v -31.479097 4.693977 6.005632
vt 0.003508 0.474197
vt 0.003720 0.304675
vt 0.173029 0.474409
vt 0.173241 0.304887
vt 0.190029 0.096736
vt 0.173010 0.823395
vt 0.002961 0.827333
vt 0.991265 0.897972
vt 0.002961 0.996854
vt 0.172483 0.996854
vt 0.003932 0.135154
vt 0.173453 0.135366
vt 0.003296 0.643718
vt 0.172818 0.643930
vt 0.590647 0.497354
vt 0.590647 0.096736
vt 0.590647 0.897972
vt 0.088057 0.643824
vt 0.190029 0.497354
vt 0.092237 0.474308
vt 0.092449 0.304786
vt 0.991265 0.497354
vt 0.088693 0.135260
vt 0.390338 0.096736
vt 0.390338 0.297045
vt 0.390338 0.697663
vt 0.390338 0.897972
vt 0.390338 0.497354
vt 0.790956 0.096736
vt 0.790956 0.297045
vt 0.790956 0.497354
vt 0.790956 0.697663
vt 0.790956 0.897972
vt 0.130437 0.643877
vt 0.190029 0.297045
vt 0.590647 0.297045
vt 0.991265 0.297045
vt 0.131073 0.135313
vt 0.991265 0.697663
vt 0.046312 0.135207
vt 0.590647 0.697663
vt 0.045677 0.643771
vt 0.190029 0.697663
vt 0.690802 0.397199
vt 0.490493 0.397199
vt 0.490493 0.597508
vt 0.690802 0.597508
vt 0.891111 0.797817
vt 0.891111 0.597508
vt 0.891111 0.397199
vt 0.891111 0.196890
vt 0.690802 0.196890
vt 0.490493 0.196890
vt 0.290184 0.196890
vt 0.290184 0.397199
vt 0.290184 0.597508
vt 0.290184 0.797817
vt 0.490493 0.797817
vt 0.690802 0.797817
vt 0.089079 0.602372
vt 0.154625 0.230024
vt 0.132845 0.304837
vt 0.111298 0.222081
vt 0.068335 0.216153
vt 0.048085 0.304731
vt 0.026672 0.213355
vt 0.150972 0.562173
vt 0.132633 0.474358
vt 0.111101 0.558042
vt 0.068688 0.560019
vt 0.047873 0.474252
vt 0.026927 0.568374
vt 0.130103 0.827333
vt 0.172483 0.827333
vt 0.045342 0.827333
vt 0.087722 0.827333
vt 0.190029 0.897972
vt 0.130629 0.823395
vt 0.991265 0.096736
vt 0.045869 0.823395
vt 0.088249 0.823395
vt 0.003488 0.823395
vt 0.003488 0.653873
vt 0.173010 0.653873
vt 0.490493 0.096736
vt 0.067059 0.823395
vt 0.490493 0.297045
vt 0.490493 0.497354
vt 0.490493 0.697663
vt 0.066532 0.827333
vt 0.490493 0.897972
vt 0.294609 0.096736
vt 0.025615 0.823395
vt 0.290184 0.297045
vt 0.290184 0.497354
vt 0.290184 0.697663
vt 0.024152 0.827333
vt 0.290184 0.897972
vt 0.690651 0.096736
vt 0.109407 0.823395
vt 0.690802 0.297045
vt 0.690802 0.497354
vt 0.690802 0.697663
vt 0.108912 0.827333
vt 0.690802 0.897972
vt 0.151293 0.827333
vt 0.891111 0.897972
vt 0.891111 0.697663
vt 0.891111 0.497354
vt 0.891111 0.297045
vt 0.891111 0.096736
vt 0.151820 0.823395
vt 0.991265 0.196890
vt 0.152263 0.135340
vt 0.790956 0.196890
vt 0.590647 0.196890
vt 0.390338 0.196890
vt 0.151627 0.643904
vt 0.190029 0.196890
vt 0.109247 0.643851
vt 0.190029 0.397199
vt 0.390338 0.397199
vt 0.590647 0.397199
vt 0.790956 0.397199
vt 0.991265 0.397199
vt 0.109883 0.135287
vt 0.991265 0.597508
vt 0.067502 0.135234
vt 0.790956 0.597508
vt 0.590647 0.597508
vt 0.390338 0.597508
vt 0.066867 0.643798
vt 0.190029 0.597508
vt 0.024486 0.643745
vt 0.190029 0.797817
vt 0.390338 0.797817
vt 0.590647 0.797817
vt 0.790956 0.797817
vt 0.991265 0.797817
vt 0.025122 0.135181
vn 0.020668 -0.006359 -0.999766
vn -0.027113 -0.006730 -0.999610
vn -0.029610 -0.008886 -0.999522
vn -0.018928 0.582161 -0.812853
vn 0.018016 0.582415 -0.812692
vn 0.023788 -0.008855 -0.999678
vn -0.035951 0.998946 0.028539
vn -0.005927 0.999621 0.026889
vn -0.001724 0.998900 0.046871
vn -0.000099 0.999594 0.028507
vn -0.001066 0.999450 0.033146
vn 0.000239 0.999616 0.027720
vn 0.001383 0.999481 0.032180
vn 0.002838 0.999623 0.027315
vn 0.023608 0.999075 0.035929
vn 0.321404 0.009046 0.946899
vn 0.110315 0.035313 0.993269
vn 0.162658 -0.287097 0.943990
vn 0.033801 -0.998996 0.029409
vn 0.000533 -0.999771 0.021368
vn 0.002117 -0.999772 0.021246
vn 0.005055 -0.999808 0.018948
vn 0.004850 -0.999488 0.031631
vn -0.001233 -0.999714 0.023866
vn -0.005046 -0.999505 0.031049
vn -0.000854 -0.999738 0.022885
vn -0.035927 -0.998989 0.027020
vn -0.024015 -0.532076 -0.846356
vn 0.019313 -0.540765 -0.840952
vn -0.991482 -0.122312 -0.044749
vn -0.897928 0.012500 0.439965
vn -0.894575 0.167584 0.414309
vn -0.801506 0.141204 0.581076
vn 0.989720 0.036899 -0.138174
vn 0.165553 -0.113456 0.979653
vn -0.058512 0.164315 0.984671
vn 0.042469 0.059133 0.997346
vn 0.045935 0.008850 0.998905
vn 0.106547 -0.157211 0.981801
vn -0.026154 -0.085747 0.995974
vn -0.103022 0.084266 0.991103
vn -0.049959 0.130769 0.990153
vn -0.136659 0.069647 0.988167
vn 0.049676 -0.020355 0.998558
vn 0.991902 -0.032619 0.122745
vn 0.983991 0.037132 -0.174309
vn -0.030035 -0.005291 -0.999535
vn 0.024103 -0.006156 -0.999691
vn -0.994879 0.090637 -0.044724
vn -0.832236 -0.103331 0.544707
vn -0.900561 -0.189709 0.391152
vn 0.205618 0.141269 0.968382
vn 0.114354 0.198929 0.973319
vn 0.033116 -0.190324 0.981163
vn 0.015462 0.158566 0.987227
vn 0.110222 -0.188450 0.975878
vn 0.014253 -0.046187 0.998831
vn 0.156558 -0.170027 0.972924
vn 0.161772 -0.255237 0.953249
vn 0.166367 0.319661 0.932812
vn 0.194003 0.199631 0.960474
vn 0.024099 -0.115882 0.992971
vn -0.143572 0.288295 0.946717
vn -0.038624 0.118202 0.992238
vn -0.066326 -0.069376 0.995383
vn -0.037925 -0.104006 0.993853
vn -0.013212 -0.055146 0.998391
vn 0.716275 0.075177 0.693757
vn -0.030135 0.181445 0.982939
vn 0.128242 0.267820 0.954896
vn -0.041887 0.145090 0.988531
vn -0.711577 0.286281 0.641640
vn -0.701297 -0.029712 0.712249
vn 0.139225 -0.261755 0.955040
vn -0.104466 -0.180682 0.977978
vn 0.189812 -0.320573 0.928011
vn 0.712014 -0.004752 0.702150
vn 0.508499 -0.218956 0.832759
vn 0.476244 0.196654 0.857041
vn -0.001261 -0.032857 0.999459
vn 0.028390 0.094182 0.995150
vn -0.123244 -0.237082 0.963641
vn -0.076397 -0.099868 0.992063
vn -0.006115 0.280804 0.959746
vn -0.112554 -0.075206 0.990795
vn -0.064545 -0.230261 0.970986
vn -0.081762 -0.070291 0.994170
vn 0.148438 0.162087 0.975548
vn 0.041915 0.006711 0.999099
vn 0.895551 0.046444 0.442529
vn 0.142393 0.007242 0.989784
vn 0.852500 -0.090421 0.514847
vn 0.178792 -0.150608 0.972291
vn 0.093487 -0.330005 0.939338
vn 0.990864 -0.012272 -0.134309
vn 0.965078 -0.124817 -0.230316
vn -0.998266 -0.058861 -0.000783
vn -0.999945 0.007754 0.007012
vn 0.100111 -0.010887 0.994917
vn -0.125087 -0.227456 0.965721
s 1
g pCube1
usemtl lambert2SG
f 13/20/1 14/21/2 50/62/3 4/4/4 3/3/5 56/68/6
f 3/83/5 4/84/4 6/6/7 80/112/8 21/78/9 71/100/10 10/81/11 61/86/12 16/80/13 66/93/14 5/82/15
f 12/19/16 68/95/17 44/56/18
f 7/7/19 70/97/20 19/75/21 65/90/22 11/76/23 75/104/24 25/73/25 76/106/26 8/74/27 2/10/28 1/9/29
f 51/63/30 15/23/31 90/126/32 28/38/33
f 5/14/15 55/67/34 3/3/5
f 5/5/15 66/92/14 42/54/35
f 35/47/36 23/31/37 92/129/38
f 7/77/19 45/57/39 70/98/20
f 32/44/40 27/36/41 72/101/42
f 35/47/36 74/103/43 30/41/44
f 48/60/45 58/70/46 13/20/1
f 1/1/29 2/2/28 53/65/47 14/21/2 13/20/1 59/71/48
f 15/23/31 52/64/49 29/40/50 91/128/51
f 17/25/52 62/87/53 33/45/54
f 34/46/55 94/131/56 20/28/57
f 34/46/55 64/89/58 18/26/59
f 12/19/16 43/55/60 68/95/17
f 33/45/54 20/28/57 87/122/61
f 23/31/37 32/44/40 89/124/62
f 39/51/63 80/111/8 6/79/7
f 78/109/64 38/50/65 15/22/31
f 37/49/66 78/109/64 15/22/31
f 76/107/26 36/48/67 8/8/27
f 5/5/15 42/54/35 85/119/68
f 83/116/69 41/53/70 10/16/11
f 40/52/71 83/116/69 10/16/11
f 81/113/72 39/51/63 6/79/7
f 36/48/67 100/139/73 8/8/27
f 11/17/23 98/137/74 47/59/75
f 11/17/23 46/58/76 98/137/74
f 96/135/77 45/57/39 7/77/19
f 19/27/21 46/58/76 65/91/22
f 12/19/16 44/56/18 95/133/78
f 86/121/79 43/55/60 12/19/16
f 41/53/70 16/24/13 61/85/12
f 71/99/10 40/52/71 10/16/11
f 15/22/31 38/50/65 90/125/32
f 91/127/51 37/49/66 15/22/31
f 11/17/23 47/59/75 75/105/24
f 9/15/80 32/44/40 73/102/81
f 9/15/80 88/123/82 32/44/40
f 33/45/54 88/123/82 9/15/80
f 33/45/54 63/88/83 20/28/57
f 34/46/55 20/28/57 63/88/83
f 93/130/84 34/46/55 9/15/80
f 35/47/36 93/130/84 9/15/80
f 9/15/80 73/102/81 35/47/36
f 25/33/25 99/138/85 36/48/67
f 36/48/67 77/108/86 29/39/50
f 77/108/86 37/49/66 29/39/50
f 37/49/66 92/129/38 23/31/37
f 23/31/37 89/124/62 38/50/65
f 28/37/33 38/50/65 79/110/87
f 28/37/33 79/110/87 39/51/63
f 39/51/63 82/115/88 21/29/9
f 82/115/88 40/52/71 21/29/9
f 40/52/71 72/101/42 27/36/41
f 17/25/52 41/53/70 62/87/53
f 41/53/70 84/117/89 16/24/13
f 42/54/35 16/24/13 84/117/89
f 26/35/90 42/54/35 67/94/91
f 26/35/90 67/94/91 43/55/60
f 20/28/57 43/55/60 87/122/61
f 44/56/18 20/28/57 94/131/56
f 31/43/92 44/56/18 69/96/93
f 31/43/92 69/96/93 45/57/39
f 19/27/21 45/57/39 97/136/94
f 19/27/21 97/136/94 46/58/76
f 64/89/58 46/58/76 18/26/59
f 47/59/75 30/41/44 74/103/43
f 25/33/25 47/59/75 99/138/85
f 55/67/34 56/68/6 3/3/5
f 12/18/16 48/60/45 26/34/90 86/120/79
f 31/42/92 48/60/45 12/18/16 95/132/78
f 7/13/19 1/1/29 60/72/95
f 58/70/46 59/71/48 13/20/1
f 57/69/96 48/60/45 13/20/1
f 50/62/3 51/63/30 28/38/33 49/61/97
f 54/66/98 8/11/27 100/140/73 29/40/50
f 53/65/47 54/66/98 29/40/50 52/64/49
f 6/12/7 49/61/97 28/38/33 81/114/72
f 4/4/4 49/61/97 6/12/7
f 50/62/3 49/61/97 4/4/4
f 14/21/2 51/63/30 50/62/3
f 14/21/2 15/23/31 51/63/30
f 14/21/2 52/64/49 15/23/31
f 53/65/47 52/64/49 14/21/2
f 2/2/28 54/66/98 53/65/47
f 2/2/28 8/11/27 54/66/98
f 26/34/90 55/67/34 5/14/15 85/118/68
f 56/68/6 57/69/96 13/20/1
f 26/34/90 57/69/96 56/68/6 55/67/34
f 26/34/90 48/60/45 57/69/96
f 31/42/92 58/70/46 48/60/45
f 59/71/48 60/72/95 1/1/29
f 31/42/92 60/72/95 59/71/48 58/70/46
f 7/13/19 60/72/95 31/42/92 96/134/77
f 41/53/70 61/85/12 10/16/11
f 62/87/53 41/53/70 27/36/41
f 33/45/54 62/87/53 27/36/41
f 9/15/80 63/88/83 33/45/54
f 34/46/55 63/88/83 9/15/80
f 30/41/44 64/89/58 34/46/55
f 30/41/44 46/58/76 64/89/58
f 65/91/22 46/58/76 11/17/23
f 42/54/35 66/92/14 16/24/13
f 67/94/91 42/54/35 17/25/52
f 43/55/60 67/94/91 17/25/52
f 68/95/17 43/55/60 20/28/57
f 44/56/18 68/95/17 20/28/57
f 69/96/93 44/56/18 18/26/59
f 45/57/39 69/96/93 18/26/59
f 70/98/20 45/57/39 19/27/21
f 21/29/9 40/52/71 71/99/10
f 22/30/99 72/101/42 40/52/71
f 32/44/40 72/101/42 22/30/99
f 73/102/81 32/44/40 23/31/37
f 35/47/36 73/102/81 23/31/37
f 24/32/100 74/103/43 35/47/36
f 47/59/75 74/103/43 24/32/100
f 75/105/24 47/59/75 25/33/25
f 25/33/25 36/48/67 76/107/26
f 24/32/100 77/108/86 36/48/67
f 24/32/100 37/49/66 77/108/86
f 37/49/66 23/31/37 78/109/64
f 23/31/37 38/50/65 78/109/64
f 79/110/87 38/50/65 22/30/99
f 39/51/63 79/110/87 22/30/99
f 39/51/63 21/29/9 80/111/8
f 28/37/33 39/51/63 81/113/72
f 22/30/99 82/115/88 39/51/63
f 22/30/99 40/52/71 82/115/88
f 40/52/71 27/36/41 83/116/69
f 27/36/41 41/53/70 83/116/69
f 17/25/52 84/117/89 41/53/70
f 42/54/35 84/117/89 17/25/52
f 85/119/68 42/54/35 26/35/90
f 26/35/90 43/55/60 86/121/79
f 87/122/61 43/55/60 17/25/52
f 33/45/54 87/122/61 17/25/52
f 33/45/54 27/36/41 88/123/82
f 32/44/40 88/123/82 27/36/41
f 89/124/62 32/44/40 22/30/99
f 38/50/65 89/124/62 22/30/99
f 90/125/32 38/50/65 28/37/33
f 29/39/50 37/49/66 91/127/51
f 24/32/100 92/129/38 37/49/66
f 35/47/36 92/129/38 24/32/100
f 35/47/36 30/41/44 93/130/84
f 30/41/44 34/46/55 93/130/84
f 18/26/59 94/131/56 34/46/55
f 44/56/18 94/131/56 18/26/59
f 95/133/78 44/56/18 31/43/92
f 31/43/92 45/57/39 96/135/77
f 97/136/94 45/57/39 18/26/59
f 46/58/76 97/136/94 18/26/59
f 98/137/74 46/58/76 30/41/44
f 47/59/75 98/137/74 30/41/44
f 99/138/85 47/59/75 24/32/100
f 36/48/67 99/138/85 24/32/100
f 36/48/67 29/39/50 100/139/73
Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

+12
View File
@@ -0,0 +1,12 @@
newmtl Cave1:pasted__lambert4SG
illum 4
Kd 0.13 0.14 0.16
Ka 0.00 0.00 0.00
Tf 1.00 1.00 1.00
Ni 1.00
newmtl lambert2SG
illum 4
Kd 0.50 0.50 0.50
Ka 0.00 0.00 0.00
Tf 0.00 0.00 0.00
Ni 1.00
File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More