missing navmesh demo and small fixes

This commit is contained in:
Juan Linietsky 2014-11-19 11:33:15 -03:00
parent d5cb758d36
commit e709468bb1
10 changed files with 155 additions and 9 deletions

View File

@ -0,0 +1,9 @@
[application]
name="Navmesh Demo"
main_scene="res://navmesh.scn"
icon="res://icon.png"
[rasterizer]
shadow_filter=3

110
demos/3d/navmesh/navmesh.gd Normal file
View File

@ -0,0 +1,110 @@
extends Navigation
# member variables here, example:
# var a=2
# var b="textvar"
const SPEED=4.0
var camrot=0.0
var begin=Vector3()
var end=Vector3()
var m = FixedMaterial.new()
var path=[]
func _process(delta):
if (path.size()>1):
var to_walk = delta*SPEED
var to_watch = Vector3(0,1,0)
while(to_walk>0 and path.size()>=2):
var pfrom = path[path.size()-1]
var pto = path[path.size()-2]
to_watch = (pto - pfrom).normalized()
var d = pfrom.distance_to(pto)
if (d<=to_walk):
path.remove(path.size()-1)
to_walk-=d
else:
path[path.size()-1] = pfrom.linear_interpolate(pto,to_walk/d)
to_walk=0
var atpos = path[path.size()-1]
var atdir = to_watch
atdir.y=0
var t = Transform()
t.origin=atpos
t=t.looking_at(atpos+atdir,Vector3(0,1,0))
get_node("robot_base").set_transform(t)
if (path.size()<2):
path=[]
set_process(false)
else:
set_process(false)
var draw_path=false
func _update_path():
var p = get_simple_path(begin,end,true)
path=Array(p) # Vector3array to complex to use, convert to regular array
path.invert()
set_process(true)
if (draw_path):
var im = get_node("draw")
im.set_material_override(m)
im.clear()
im.begin(Mesh.PRIMITIVE_POINTS,null)
im.add_vertex(begin)
im.add_vertex(end)
im.end()
im.begin(Mesh.PRIMITIVE_LINE_STRIP,null)
for x in p:
im.add_vertex(x)
im.end()
func _input(ev):
if (ev.type==InputEvent.MOUSE_BUTTON and ev.button_index==BUTTON_LEFT and ev.pressed):
var from = get_node("cambase/Camera").project_position(ev.pos)
var to = from+get_node("cambase/Camera").project_ray_normal(ev.pos)*100
var p = get_closest_point_to_segment(from,to)
begin=get_closest_point(get_node("robot_base").get_translation())
end=p
_update_path()
if (ev.type==InputEvent.MOUSE_MOTION):
if (ev.button_mask&BUTTON_MASK_MIDDLE):
camrot+=ev.relative_x*0.005
get_node("cambase").set_rotation(Vector3(0,camrot,0))
print("camrot ", camrot)
func _ready():
# Initalization here
set_process_input(true)
m.set_line_width(3)
m.set_point_size(3)
m.set_fixed_flag(FixedMaterial.FLAG_USE_POINT_SIZE,true)
m.set_flag(Material.FLAG_UNSHADED,true)
#begin = get_closest_point(get_node("start").get_translation())
#end = get_closest_point(get_node("end").get_translation())
#call_deferred("_update_path")
pass

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 260 B

View File

@ -67,10 +67,13 @@ if env["platform"] == "iphone":
env_theora = env.Clone()
env_theora.Append(CPPFLAGS=["-D_YUV_C", "-D__THEORA", "-D_LIB"])
env_theora.Append(CPPFLAGS=["-D_YUV_C", "-D_LIB", "-D__THEORA"])
if env["platform"] == "iphone":
env_theora.Append(CPPFLAGS=["-D__AVFOUNDATION"])
else:
pass
#env_theora.Append(CPPFLAGS=["-D__FFMPEG"])
if env["platform"] == "android":
env_theora.Append(CPPFLAGS=["-D_ANDROID"])

View File

@ -271,6 +271,8 @@ void TheoraVideoClip_AVFoundation::load(TheoraDataSource* source)
AVAssetTrack *videoTrack = [tracks objectAtIndex:0];
NSArray* audioTracks = [asset tracksWithMediaType:AVMediaTypeAudio];
if (audio_track >= audioTracks.count)
audio_track = 0;
AVAssetTrack *audioTrack = audioTracks.count > 0 ? [audioTracks objectAtIndex:audio_track] : NULL;
printf("*********** using audio track %i\n", audio_track);

View File

@ -122,6 +122,7 @@ class AudioStreamInput : public AudioStreamResampled {
int rb_power;
int total_wrote;
bool playing;
bool paused;
public:
@ -133,6 +134,7 @@ public:
AudioServer::get_singleton()->stream_set_active(stream_rid,true);
AudioServer::get_singleton()->stream_set_volume_scale(stream_rid,1);
playing = true;
paused = false;
};
virtual void stop() {
@ -146,8 +148,8 @@ public:
virtual bool is_playing() const { return true; };
virtual void set_paused(bool p_paused) {};
virtual bool is_paused(bool p_paused) const { return false; };
virtual void set_paused(bool p_paused) { paused = p_paused; };
virtual bool is_paused(bool p_paused) const { return paused; };
virtual void set_loop(bool p_enable) {};
virtual bool has_loop() const { return false; };
@ -209,6 +211,7 @@ public:
AudioStreamInput(int p_channels, int p_freq) {
playing = false;
paused = true;
channels = p_channels;
freq = p_freq;
total_wrote = 0;
@ -285,12 +288,12 @@ void VideoStreamTheoraplayer::stop() {
clip->stop();
clip->seek(0);
};
started = true;
};
void VideoStreamTheoraplayer::play() {
playing = true;
started = true;
if (clip)
playing = true;
};
bool VideoStreamTheoraplayer::is_playing() const {
@ -300,7 +303,13 @@ bool VideoStreamTheoraplayer::is_playing() const {
void VideoStreamTheoraplayer::set_paused(bool p_paused) {
playing = false;
paused = p_paused;
if (paused) {
clip->pause();
} else {
if (clip && playing && !started)
clip->play();
}
};
bool VideoStreamTheoraplayer::is_paused(bool p_paused) const {
@ -355,6 +364,9 @@ int VideoStreamTheoraplayer::get_pending_frame_count() const {
void VideoStreamTheoraplayer::pop_frame(Ref<ImageTexture> p_tex) {
if (!clip)
return;
TheoraVideoFrame* f = clip->getNextFrame();
if (!f) {
return;
@ -374,7 +386,7 @@ void VideoStreamTheoraplayer::pop_frame(Ref<ImageTexture> p_tex) {
{
DVector<uint8_t>::Write wr = data.write();
uint8_t* ptr = wr.ptr();
memcpy(ptr, f->getBuffer(), imgsize);
copymem(ptr, f->getBuffer(), imgsize);
}
/*
for (int i=0; i<h; i++) {
@ -416,6 +428,12 @@ void VideoStreamTheoraplayer::update(float p_time) {
if (!mgr)
return;
if (!clip)
return;
if (!playing || paused)
return;
//printf("video update!\n");
if (started) {
if (clip->getNumReadyFrames() < 2) {
@ -499,6 +517,7 @@ VideoStreamTheoraplayer::VideoStreamTheoraplayer() {
clip = NULL;
started = false;
playing = false;
paused = false;
loop = false;
audio_track=0;
};

View File

@ -17,6 +17,7 @@ class VideoStreamTheoraplayer : public VideoStream {
bool started;
bool playing;
bool loop;
bool paused;
int audio_track;

View File

@ -2464,6 +2464,8 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const {
"assert",
"yield",
"static",
"float",
"int",
0};

View File

@ -1494,7 +1494,7 @@ OS::Date OS_Windows::get_date() const {
OS::Time OS_Windows::get_time() const {
SYSTEMTIME systemtime;
GetSystemTime(&systemtime);
GetLocalTime(&systemtime);
Time time;
time.hour=systemtime.wHour;