more stuff

This commit is contained in:
Cary Sandvig 2000-11-17 23:43:52 +00:00
parent 7785f82e1b
commit 97385fd149
2 changed files with 217 additions and 1 deletions

View File

@ -20,6 +20,8 @@ ConfigureFn(deadrec) {
static PT_Node smiley;
static RenderRelation* my_arc;
static LPoint3f my_pos;
static LVector3f my_vel;
string hostname = deadrec.GetString("deadrec-rec", "localhost");
int hostport = deadrec.GetInt("deadrec-rec-port", 0xdead);
@ -27,6 +29,35 @@ static QueuedConnectionManager cm;
PT(Connection) conn;
ConnectionWriter* writer;
enum TelemetryToken { T_End, T_Pos, T_Vel, T_Num };
static inline NetDatagram& add_pos(NetDatagram& d) {
d.add_uint8(T_Pos);
d.add_float64(my_pos[0]);
d.add_float64(my_pos[1]);
d.add_float64(my_pos[2]);
return d;
}
static inline NetDatagram& add_vel(NetDatagram& d) {
d.add_uint8(T_Vel);
d.add_float64(my_vel[0]);
d.add_float64(my_vel[1]);
d.add_float64(my_vel[2]);
return d;
}
static inline void send(NetDatagram& d) {
d.add_uint8(T_End);
writer->send(d, conn);
}
static void event_frame(CPT_Event) {
// send deadrec data
NetDatagram d;
send(add_pos(d));
}
static void deadrec_setup(void) {
static bool done = false;
if (done)
@ -53,8 +84,103 @@ static void deadrec_setup(void) {
writer = new ConnectionWriter(&cm, 0);
}
// the various motion generators
void update_smiley(void) {
LMatrix4f mat = LMatrix4f::translate_mat(my_pos);
my_arc->set_transition(new TransformTransition(mat));
}
enum MotionType { M_None, M_Line, M_Box, M_Circle, M_Random };
PT(AutonomousLerp) curr_lerp;
MotionType curr_type;
static void run_line(void) {
class MyPosFunctor : public LPoint3fLerpFunctor {
public:
MyPosFunctor(LPoint3f start, LPoint3f end) : LPoint3fLerpFunctor(start,
end) {}
MyPosFunctor(const MyPosFunctor& p) : LPoint3fLerpFunctor(p) {}
virtual ~MyPosFunctor(void) {}
virtual void operator()(float t) {
LPoint3f p = interpolate(t);
my_vel = p - my_pos;
my_pos = p;
update_smiley();
}
public:
// type stuff
static TypeHandle get_class_type(void) { return _type_handle; }
static void init_type(void) {
LPoint3fLerpFunctor::init_type();
register_type(_type_handle, "MyPosFunctor",
LPoint3fLerpFunctor::get_class_type());
}
virtual TypeHandle get_type(void) const { return get_class_type(); }
virtual TypeHandle force_init_type(void) {
init_type();
return get_class_type();
}
private:
static TypeHandle _type_handle;
};
static TypeHandle MyPosFunctor::_type_handle;
static bool inited = false;
static bool where = false;
if (!inited) {
MyPosFunctor::init_type();
inited = true;
}
if (where) {
MyPosFunctor func(my_pos, LPoint3f:rfu(10., 0., 0.));
curr_lerp = new AutonomousLerp(func, 5., new NoBlendType(), event_handler);
curr_lerp->set_end_event("lerp_done");
curr_lerp->start();
} else {
MyPosFunctor func(my_pos, LPoint3f:rfu(-10., 0., 0.));
curr_lerp = new AutonomousLerp(func, 5., new NoBlendType(), event_handler);
curr_lerp->set_end_event("lerp_done");
curr_lerp->start();
}
where = !where;
}
static void handle_lerp(void) {
curr_lerp = (AutonomousLerp*)0L;
switch (curr_type) {
case M_None:
break;
case M_Line:
run_line();
break;
case M_Box:
break;
case M_Circle:
break;
case M_Random:
break;
default:
deadrec_cat->error() << "unknown motion type (" << curr_type << ")"
<< endl;
}
}
static void event_lerp(CPT_Event) {
handle_lerp();
}
static void event_1(CPT_Event) {
curr_lerp = M_Line;
handle_lerp();
}
static void deadrec_keys(EventHandler& eh) {
deadrec_setup();
eh.add_hook("NewFrame", event_frame);
eh.add_hook("1", event_1);
eh.add_hook("lerp_done", event_lerp);
}
int main(int argc, char* argv[]) {

View File

@ -46,6 +46,7 @@
#include <guiRollover.h>
#include <guiButton.h>
#include <guiFrame.h>
#include <guiSign.h>
//From framework
extern PT(GeomNode) geomnode;
@ -303,6 +304,7 @@ static void test6(GuiManager* mgr, Node* font) {
f1->manage(mgr, event_handler);
}
/*
GuiManager* g_mgr;
PT(GuiButton) b1;
PT(GuiButton) b4;
@ -405,6 +407,70 @@ static void test7(GuiManager* mgr, Node* font) {
f1->recompute();
f1->manage(mgr, event_handler);
}
*/
GuiManager* g_mgr;
PT(GuiSign) s1;
PT(GuiSign) s4;
PT(GuiSign) s5;
PT(GuiFrame) f1;
static bool frame_state = true;
static void test8(GuiManager* mgr, Node* font) {
f1 = new GuiFrame("canids");
GuiLabel* l1 = GuiLabel::make_simple_text_label("dingo", font);
l1->set_foreground_color(0., 0., 0., 1.);
l1->set_background_color(1., 1., 1., 1.);
s1 = new GuiSign("dingo", l1);
s1->set_scale(0.1);
f1->add_item(s1);
GuiLabel* l2 = GuiLabel::make_simple_text_label("jackel", font);
l2->set_foreground_color(0., 0., 0., 1.);
l2->set_background_color(1., 1., 1., 1.);
GuiSign* s2 = new GuiSign("jackel", l2);
s2->set_scale(0.1);
f1->add_item(s2);
GuiLabel* l3 = GuiLabel::make_simple_text_label("hyena", font);
l3->set_foreground_color(0., 0., 0., 1.);
l3->set_background_color(1., 1., 1., 1.);
GuiSign* s3 = new GuiSign("jackel", l3);
s3->set_scale(0.1);
f1->add_item(s3);
GuiLabel* l4 = GuiLabel::make_simple_text_label("wolf", font);
l4->set_foreground_color(0., 0., 0., 1.);
l4->set_background_color(1., 1., 1., 1.);
s4 = new GuiSign("wolf", l4);
s4->set_scale(0.1);
f1->add_item(s4);
GuiLabel* l5 = GuiLabel::make_simple_text_label("fox", font);
l5->set_foreground_color(0., 0., 0., 1.);
l5->set_background_color(1., 1., 1., 1.);
s5 = new GuiSign("fox", l5);
s5->set_scale(0.1);
f1->pack_item(s2, GuiFrame::UNDER, s1);
f1->pack_item(s2, GuiFrame::LEFT, s1);
f1->pack_item(s3, GuiFrame::UNDER, s1);
f1->pack_item(s3, GuiFrame::RIGHT, s1);
f1->pack_item(s4, GuiFrame::UNDER, s1);
f1->pack_item(s4, GuiFrame::ALIGN_LEFT, s1);
float w, w1, w2;
w1 = l1->get_width();
w2 = l2->get_width();
w = (w1>w2)?w1:w2;
w2 = l3->get_width();
w = (w>w2)?w:w2;
w2 = l4->get_width();
w = (w>w2)?w:w2;
w2 = l5->get_width();
w = (w>w2)?w:w2;
l1->set_width(w);
l2->set_width(w);
l3->set_width(w);
l4->set_width(w);
l5->set_width(w);
f1->recompute();
f1->manage(mgr, event_handler);
}
static void setup_gui(void) {
GuiManager* mgr = GuiManager::get_ptr(main_win, mak);
@ -422,7 +488,10 @@ static void setup_gui(void) {
// test 6
// test6(mgr, font);
// test 7
test7(mgr, font);
// test7(mgr, font);
// g_mgr = mgr;
// test 8
test8(mgr, font);
g_mgr = mgr;
}
@ -434,6 +503,7 @@ static void event_2(CPT_Event) {
}
}
/*
// for test 7
static void event_3(CPT_Event) {
if (frame_state) {
@ -452,6 +522,26 @@ static void event_3(CPT_Event) {
f1->recompute();
frame_state = !frame_state;
}
*/
// for test 8
static void event_3(CPT_Event) {
if (frame_state) {
f1->remove_item(s4);
f1->add_item(s5);
f1->pack_item(s5, GuiFrame::UNDER, s1);
f1->pack_item(s5, GuiFrame::ALIGN_LEFT, s1);
s5->manage(g_mgr, event_handler);
} else {
f1->remove_item(s5);
f1->add_item(s4);
f1->pack_item(s4, GuiFrame::UNDER, s1);
f1->pack_item(s4, GuiFrame::ALIGN_LEFT, s1);
s4->manage(g_mgr, event_handler);
}
f1->recompute();
frame_state = !frame_state;
}
void gui_keys(EventHandler&) {
new RenderRelation( lights, dlight );