Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
// // Dice.m // DiceRoller // // Created by Jacques Questiaux on 2012/04/17. // Copyright (c) 2012 j.questiaux@gmail.com. All rights reserved. // #import "Dice.h" #import "d4.h" #import "d6.h" #import "d8.h" #import "d10.h" #import "d12.h" #import "d20.h" #import "d100.h" #include "btBulletDynamicsCommon.h" typedef struct { float r; float g; float b; } Color; Color faceColors [] ={ {1, 0, 0}, {0, 0, 1}, {0, 1, 0}, {1, 1, 0}, {1, 0, 1}, {0, 1, 1}, {1, 1, 1}, {0.1, 0.1, 0.1} }; Color numbers [] ={ {1, 1, 1}, {1, 1, 1}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {1, 1, 1} }; @interface Dice () { GLuint _vertexArray; GLuint _vertexBuffer; GLuint _indexBuffer; GLuint _colorBuffer; GLuint _normalBuffer; GLuint _textureBuffer; GLuint toon_vertexArray; GLuint toon_vertexBuffer; GLuint toon_indexBuffer; GLfloat *vertices; GLushort *indices; GLfloat *normals; GLfloat *colors; GLfloat *tex; int numVertices; int numIndices; int numNormals; int numColors; int numTex; btDynamicsWorld *dynamicsWorld; btRigidBody *diceRigidBody; btConvexHullShape *fallShape; btDefaultMotionState *fallMotionState; } @end @implementation Dice @synthesize up = _up; @synthesize front = _front; @synthesize right = _right; @synthesize position =_position; @synthesize direction = _direction; @synthesize modelViewMatrix = _modelViewMatrix; - (id) initWithSides:(NSUInteger)s Color: (int) c{ if(self = [super init]){ Sides = s; colorSelected = c; return self; } return nil; } - (id)initWithCoder:(NSCoder *)coder { if (self = [super init]) { Sides = [coder decodeIntegerForKey:@"Sides"]; colorSelected = [coder decodeFloatForKey:@"Color"]; return self; } return nil; } - (void)encodeWithCoder:(NSCoder *)coder { [coder encodeInteger:Sides forKey:@"Sides"]; [coder encodeFloat:colorSelected forKey:@"Color"]; } - (void) Context: (EAGLContext *) c Effect: (Effects *) e DynamicsWorld: (btDynamicsWorld *) d View: (GLKView *) v { self.right = GLKVector3Make(1, 0, 0); self.up = GLKVector3Make(0, 1, 0); self.front = GLKVector3Make(0, 0, 1); context = c; effect = e; dynamicsWorld = d; view = v; friction = 0.95f; selected = false; matrix = new btScalar[15]; [self setup]; } - (void) setup{ fallShape = new btConvexHullShape(); //too lazy to swap to a switch statement if(Sides == 4){ vertices = d4vertices; numVertices = sizeof(d4vertices)/sizeof(GLfloat); indices = d4indices; numIndices = sizeof(d4indices)/sizeof(GLushort); normals = d4normals; numNormals = sizeof(d4normals)/sizeof(GLfloat); tex = d4tex; numTex = sizeof(d4tex)/sizeof(GLfloat); for(int i = 0; i < numVertices; i+=3){ btVector3 vert = btVector3(d4PhysicsVertices[i], d4PhysicsVertices[i+1], d4PhysicsVertices[i+2]); fallShape->addPoint(vert); } } else if(Sides == 6){ vertices = d6vertices; numVertices = sizeof(d6vertices)/sizeof(GLfloat); indices = d6indices; numIndices = sizeof(d6indices)/sizeof(GLushort); normals = d6normals; numNormals = sizeof(d6normals)/sizeof(GLfloat); tex = d6tex; numTex = sizeof(d6tex)/sizeof(GLfloat); for(int i = 0; i < numVertices; i+=3){ btVector3 vert = btVector3(d6PhysicsVertices[i], d6PhysicsVertices[i+1], d6PhysicsVertices[i+2]); fallShape->addPoint(vert); } } else if(Sides == 8){ vertices = d8vertices; numVertices = sizeof(d8vertices)/sizeof(GLfloat); indices = d8indices; numIndices = sizeof(d8indices)/sizeof(GLushort); normals = d8normals; numNormals = sizeof(d8normals)/sizeof(GLfloat); tex = d8tex; numTex = sizeof(d8tex)/sizeof(GLfloat); for(int i = 0; i < numVertices; i+=3){ btVector3 vert = btVector3(d8PhysicsVertices[i], d8PhysicsVertices[i+1], d8PhysicsVertices[i+2]); fallShape->addPoint(vert); } } else if(Sides == 10){ vertices = d10vertices; numVertices = sizeof(d10vertices)/sizeof(GLfloat); indices = d10indices; numIndices = sizeof(d10indices)/sizeof(GLushort); normals = d10normals; numNormals = sizeof(d10normals)/sizeof(GLfloat); tex = d10tex; numTex = sizeof(d10tex)/sizeof(GLfloat); for(int i = 0; i < numVertices; i+=3){ btVector3 vert = btVector3(d10PhysicsVertices[i], d10PhysicsVertices[i+1], d10PhysicsVertices[i+2]); fallShape->addPoint(vert); } } else if(Sides == 100){ vertices = d100vertices; numVertices = sizeof(d100vertices)/sizeof(GLfloat); indices = d100indices; numIndices = sizeof(d100indices)/sizeof(GLushort); normals = d100normals; numNormals = sizeof(d100normals)/sizeof(GLfloat); tex = d100tex; numTex = sizeof(d100tex)/sizeof(GLfloat); for(int i = 0; i < numVertices; i+=3){ btVector3 vert = btVector3(d100PhysicsVertices[i], d100PhysicsVertices[i+1], d100PhysicsVertices[i+2]); fallShape->addPoint(vert); } } else if(Sides == 12){ vertices = d12vertices; numVertices = sizeof(d12vertices)/sizeof(GLfloat); indices = d12indices; numIndices = sizeof(d12indices)/sizeof(GLushort); normals = d12normals; numNormals = sizeof(d12normals)/sizeof(GLfloat); tex = d12tex; numTex = sizeof(d12tex)/sizeof(GLfloat); for(int i = 0; i < numVertices; i+=3){ btVector3 vert = btVector3(d12PhysicsVertices[i], d12PhysicsVertices[i+1], d12PhysicsVertices[i+2]); fallShape->addPoint(vert); } } else { vertices = d20vertices; numVertices = sizeof(d20vertices)/sizeof(GLfloat); indices = d20indices; numIndices = sizeof(d20indices)/sizeof(GLushort); normals = d20normals; numNormals = sizeof(d20normals)/sizeof(GLfloat); tex = d20tex; numTex = sizeof(d20tex)/sizeof(GLfloat); for(int i = 0; i < numVertices; i+=3){ btVector3 vert = btVector3(d20PhysicsVertices[i], d20PhysicsVertices[i+1], d20PhysicsVertices[i+2]); fallShape->addPoint(vert); } } glGenVertexArraysOES(1, &_vertexArray); glBindVertexArrayOES(_vertexArray); glGenBuffers(1, &_indexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, numIndices*sizeof(GLushort), indices, GL_STATIC_DRAW); glGenBuffers(1, &_vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); glBufferData(GL_ARRAY_BUFFER, numVertices*sizeof(GLfloat), vertices, GL_STATIC_DRAW); glEnableVertexAttribArray(effect->vertCoord); glVertexAttribPointer(effect->vertCoord, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(effect->toon_vertCoord); glVertexAttribPointer(effect->toon_vertCoord, 3, GL_FLOAT, GL_FALSE, 0, 0); glGenBuffers(1, &_normalBuffer); glBindBuffer(GL_ARRAY_BUFFER, _normalBuffer); glBufferData(GL_ARRAY_BUFFER, numNormals*sizeof(GLfloat), normals, GL_STATIC_DRAW); glEnableVertexAttribArray(effect->normal); glVertexAttribPointer(effect->normal, 3, GL_FLOAT, GL_FALSE, 0, 0); glGenBuffers(1, &_textureBuffer); glBindBuffer(GL_ARRAY_BUFFER, _textureBuffer); glBufferData(GL_ARRAY_BUFFER, numTex*sizeof(GLfloat), tex, GL_STATIC_DRAW); glEnableVertexAttribArray(effect->texCoord); glVertexAttribPointer(effect->texCoord, 2, GL_FLOAT, GL_FALSE, 0, 0); glBindVertexArrayOES(0); /*----- PHYSICS SETUP -----*/ fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(self.position.x,self.position.y,self.position.z))); //original position btScalar mass = 0.1; btVector3 fallInertia(0,0,0); fallShape->calculateLocalInertia(mass, fallInertia); btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,fallShape,fallInertia); fallRigidBodyCI.m_restitution = 0.3; diceRigidBody = new btRigidBody(fallRigidBodyCI); diceRigidBody->setDamping(0.9,0.3); //diceRigidBody->setLinearFactor(btVector3(1,1,1)); diceRigidBody->setAngularFactor(btVector3(1,1,1)); dynamicsWorld->addRigidBody(diceRigidBody); } - (void) tearDown { dynamicsWorld->removeRigidBody(diceRigidBody); delete diceRigidBody; delete fallShape; delete fallMotionState; glDeleteBuffers(1, &_vertexBuffer); glDeleteBuffers(1, &_indexBuffer); glDeleteBuffers(1, &_colorBuffer); glDeleteBuffers(1, &_normalBuffer); glDeleteBuffers(1, &_textureBuffer); delete matrix; } - (void) update: (float) timeSinceLastUpdate{ tslu = timeSinceLastUpdate; btTransform trans; diceRigidBody->getMotionState()->getWorldTransform(trans); diceRigidBody->activate(); self.position = GLKVector3Make(trans.getOrigin().getX(), trans.getOrigin().getY(), trans.getOrigin().getZ()); trans.getOpenGLMatrix(matrix); self.right = GLKVector3Make(matrix[0], matrix[1], matrix[2]); self.up = GLKVector3Make(matrix[4], matrix[5], matrix[6]); self.front = GLKVector3Make(matrix[8], matrix[9], matrix[10]); mvm = GLKMatrix4Make(self.right.x, self.right.y, self.right.z, 0, self.up.x, self.up.y, self.up.z, 0, self.front.x, self.front.y, self.front.z, 0, self.position.x, self.position.y, self.position.z, 1); } - (void) draw { [EAGLContext setCurrentContext:context]; glBindVertexArrayOES(_vertexArray); effect->modelViewMatrix = mvm; effect->numberColour = GLKVector4Make(numbers[colorSelected].r, numbers[colorSelected].g, numbers[colorSelected].b, 1); effect->faceColour = GLKVector4Make(faceColors[colorSelected].r, faceColors[colorSelected].g, faceColors[colorSelected].b, 1); if(selected){ [effect drawOutline]; glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, 0); } [effect prepareToDraw]; glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, 0); } - (void) applyForceInDirection: (GLKVector3) dir { btVector3 v = btVector3(dir.x/3, dir.y/3, dir.z/3); diceRigidBody->applyForce(v, btVector3(0, 0, 0)); btVector3 t = v.cross(btVector3(0, 0, -1)); t.normalized(); t *= 0.45f; diceRigidBody->applyTorque(t); } GLKVector3 gluProject(GLKVector3 position, GLKMatrix4 projMatrix, GLKMatrix4 modelMatrix, CGRect viewport ) { GLKVector4 in; GLKVector4 out; in = GLKVector4Make(position.x, position.y, position.z, 1.0); out = GLKMatrix4MultiplyVector4(modelMatrix, in); in = GLKMatrix4MultiplyVector4(projMatrix, out); if (in.w == 0.0) NSLog(@"W = 0 in project function\n"); in.x /= in.w; in.y /= in.w; in.z /= in.w; /* Map x, y and z to range 0-1 */ in.x = in.x * 0.5 + 0.5; in.y = in.y * 0.5 + 0.5; in.z = in.z * 0.5 + 0.5; /* Map x,y to viewport */ in.x = in.x * viewport.size.width + viewport.origin.x; in.y = in.y * viewport.size.height + viewport.origin.y; return GLKVector3Make(in.x, in.y, in.z); } - (GLKVector2) getScreenCoordOfDice { GLKVector3 out = gluProject(self.position, effect->projectionMatrix, effect->cameraMatrix, view.frame); return GLKVector2Make(out.x,view.frame.size.height - out.y); } @end
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Crypto admin access
41 min ago | 0.43 KB
+12,000$ in 2 days
CSS | 42 min ago | 0.72 KB
Free Crypto Method
CSS | 42 min ago | 0.72 KB
Documents
42 min ago | 0.43 KB
Untitled
20 hours ago | 0.68 KB
The Road Not Taken
1 day ago | 0.79 KB
OG OLDHAM CODE
3 days ago | 27.75 KB
remove current bid and bid now button from au...
PHP | 4 days ago | 0.80 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!