Skip to content

Commit

Permalink
Many many changes. In short, now able to render scenes entierly from …
Browse files Browse the repository at this point in the history
…erland and

receive all keyboard and mouse events within erlang.
  • Loading branch information
John Koenig committed Jul 13, 2011
1 parent a2aae2e commit 01cfa9c
Show file tree
Hide file tree
Showing 16 changed files with 1,774 additions and 130 deletions.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ SUBDIRS := packages src lib

.PHONY: subdirs $(SUBDIRS)

all clean install clobber: $(SUBDIRS) ;
all clean clobber: $(SUBDIRS) ;

makedir:
install --mode=755 -d $(INSTALL_DIR)
install --mode=755 -d $(LIB_DIR)
install --mode=755 -d $(EBIN_DIR)

install: makedir $(SUBDIRS)
install -m 644 -D plugins.cfg $(INSTALL_DIR)

$(SUBDIRS):
$(warning $(MAKECMDGOALS))
Expand Down
13 changes: 11 additions & 2 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ default: all ;
all: $(LIB_TARGETS) ;

install: all
install -m 755 $(LIB_TARGETS) $(LIB_DIR)
install -m 644 -D $(LIB_TARGETS) $(LIB_DIR)

clean:
rm -f ./*.o
Expand All @@ -25,16 +25,25 @@ clean:
clobber: clean
rm -f $(LIB_TARGETS)

OgreEvent.o: OgreEvent.cpp OgreEvent.h
$(CPP) -c -o $@ $(CFLAGS) $<

OgreObject.o: OgreObject.cpp OgreObject.h
$(CPP) -c -o $@ $(CFLAGS) $<

OgreManager.o: OgreManager.cpp OgreManager.h
$(CPP) -c -o $@ $(CFLAGS) $<

InputManager.o: InputManager.cpp InputManager.h
$(CPP) -c -o $@ $(CFLAGS) $<

YmirObject.o: YmirObject.cpp YmirObject.h
$(CPP) -c -o $@ $(CFLAGS) $<

libOgreManager.o: libOgreManager.cpp
$(CPP) -c -o $@ $(CFLAGS) $<

libOgreManager.so: CFLAGS += -fPIC -I$(INC_DIR) -I$(ERL_INTERFACE_INCLUDE) $(shell pkg-config --cflags OGRE CEGUI-OGRE OIS lua5.1)
libOgreManager.so: LFLAGS += -L$(ERL_INTERFACE_LIB) -lei -L$(LIB_DIR) $(shell pkg-config --libs OGRE CEGUI-OGRE OIS lua5.1)
libOgreManager.so: OgreManager.o InputManager.o libOgreManager.o
libOgreManager.so: OgreObject.o OgreEvent.o OgreManager.o InputManager.o libOgreManager.o
$(CPP) $(LDFLAGS) $^ $(LFLAGS) -o $@
109 changes: 109 additions & 0 deletions lib/OgreEvent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include "OgreEvent.h"

extern "C" {
#include <gen_cnode.h>
}

using namespace OIS;

bool OgreEvent::keyPressed( const KeyEvent& e ){
ei_x_buff key = {0};

ei_x_new(&key);

gen_cnode_format(&key, "~i", e.key);

gen_cnode_notify("keyPressed", &key);

ei_x_free(&key);

return true;
}

bool OgreEvent::keyReleased( const KeyEvent& e ){
ei_x_buff key = {0};

ei_x_new(&key);

gen_cnode_format(&key, "~i", e.key);

gen_cnode_notify("keyReleased", &key);

ei_x_free(&key);

return true;
}

bool OgreEvent::mouseMoved( const MouseEvent& e ){
ei_x_buff event = {0};

ei_x_new(&event);

encodeMouseEvent((MouseButtonID)0, e, &event);

gen_cnode_notify("mouseMoved", &event);

ei_x_free(&event);

return true;
}

bool OgreEvent::mousePressed( const MouseEvent& e, MouseButtonID id ){
ei_x_buff event = {0};

ei_x_new(&event);

encodeMouseEvent(id, e, &event);

gen_cnode_notify("mousePressed", &event);

ei_x_free(&event);

return true;
}

bool OgreEvent::mouseReleased( const MouseEvent& e, MouseButtonID id ){
ei_x_buff event = {0};

ei_x_new(&event);

encodeMouseEvent(id, e, &event);

gen_cnode_notify("mouseReleased", &event);

ei_x_free(&event);
return true;
}

//Exported utility functions
int OgreEvent::encodeMouseEvent( MouseButtonID id,
const MouseEvent& event,
ei_x_buff* output ){

if( ei_x_encode_tuple_header(output, 2) ||
ei_x_encode_ulong(output, id) ||
ei_x_encode_list_header(output, 3) ||

//Encode X position
ei_x_encode_tuple_header(output, 2) ||
ei_x_encode_long(output, event.state.X.abs) ||
ei_x_encode_long(output, event.state.X.rel) ||

//Encode Y position
ei_x_encode_tuple_header(output, 2) ||
ei_x_encode_long(output, event.state.Y.abs) ||
ei_x_encode_long(output, event.state.Y.rel) ||

//Encode Z position
ei_x_encode_tuple_header(output, 2) ||
ei_x_encode_long(output, event.state.Z.abs) ||
ei_x_encode_long(output, event.state.Z.rel) ||

//Encode end of list
ei_x_encode_empty_list(output) )
{
return -1;
}

return 0;
}
23 changes: 23 additions & 0 deletions lib/OgreEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef OGREEVENT_H
#define OGREEVENT_H

#include <OIS.h>

#include <gen_cnode.h>

class OgreEvent : public OIS::KeyListener,
public OIS::MouseListener {

int encodeMouseEvent( OIS::MouseButtonID id,
const OIS::MouseEvent& event,
ei_x_buff* output );
public:
bool keyPressed( const OIS::KeyEvent& e );
bool keyReleased( const OIS::KeyEvent& e );

bool mouseMoved( const OIS::MouseEvent &e );
bool mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id );
bool mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id );
};

#endif
Loading

0 comments on commit 01cfa9c

Please sign in to comment.