Exemple #1
0
    def start_mouse_grab(self):
        soya.cursor_set_visible(0)
        soya.set_grab_input(1)
        soya.set_mouse_pos(camera.width / 2, camera.height / 2)
        soya.clear_events()
        Rx, ry = soya.get_mouse_rel_pos()

        self.grab_cursor = 1
	def begin_round(self):
		soya.Camera.begin_round(self)
		events = soya.MAIN_LOOP.events
		
		for evenement in soya.coalesce_motion_event(events) :
			# mouvement de la souris
			if  evenement[0] == soya.sdlconst.MOUSEMOTION  and (evenement[1] != self.get_screen_width()/2 and evenement[2] != self.get_screen_height()/2):
				left = (evenement[1] - self.get_screen_width()/2) * (self.mouse_sensivity-1) + evenement[1]
				top = (evenement[2] - self.get_screen_height()/2) * (self.mouse_sensivity-1) + evenement[2]
				self.look_at(self.coord2d_to_3d( left, top ))
				soya.set_mouse_pos(self.get_screen_width()/2,self.get_screen_height()/2)
		
		for event in events:
			if event[0] == soya.sdlconst.KEYDOWN:
				if   event[1] == soya.sdlconst.K_UP:     self.speed.z = -1.0
				elif event[1] == soya.sdlconst.K_DOWN:   self.speed.z =  1.0
				elif event[1] == soya.sdlconst.K_LEFT:   self.speed.x = -1.0
				elif event[1] == soya.sdlconst.K_RIGHT:  self.speed.x =  1.0
				elif event[1] == soya.sdlconst.K_SPACE:  self.speed.y =  1.0
				elif event[1] == soya.sdlconst.K_LCTRL:  self.speed.y =  -1.0
				elif event[1] == soya.sdlconst.K_q:      soya.MAIN_LOOP.stop()
				elif event[1] == soya.sdlconst.K_ESCAPE: soya.MAIN_LOOP.stop()
				elif event[1] == soya.sdlconst.K_RETURN:
					self.set_xyz(0,0,70),
					self.look_at(Point(self.parent,0,0,0))
			elif event[0] == soya.sdlconst.KEYUP:
				if   event[1] == soya.sdlconst.K_UP:     self.speed.z = 0.0
				elif event[1] == soya.sdlconst.K_DOWN:   self.speed.z = 0.0
				elif event[1] == soya.sdlconst.K_LEFT:   self.speed.x = 0.0
				elif event[1] == soya.sdlconst.K_RIGHT:  self.speed.x = 0.0
				elif event[1] == soya.sdlconst.K_SPACE:  self.speed.y = 0.0
				elif event[1] == soya.sdlconst.K_LCTRL:  self.speed.y = 0.0
			elif event[0] == soya.sdlconst.MOUSEBUTTONDOWN:
				self.laser_on = True
				self.laser.visible = True
				if event[1] == soya.sdlconst.BUTTON_RIGHT:
					self.laser_power=100000
					self.single_blast = True
					self.laser.color=(0,0.4,1,0.9)
			elif event[0] == soya.sdlconst.MOUSEBUTTONUP:
				self.laser_on = False
				self.laser.visible = False
				
		if self.laser_on:
			if self.laser_on:
				self.laser.move(self.laser_pos)
				self.laser.look_at(self.laser_vector)
			result = self.parent.raypick(self.laser_pos, self.laser_vector)
			if result:
				impact,normal = result
				#apply force
				target = impact.parent
				target.add_force(self.laser_vector*self.laser_power,impact)
				
				l = sqrt(self.laser_power/1000.)
				nl = int(sqrt(l))
				#create particle
				# first corresponding to the dust of the planet
				s = soya.Smoke(self.parent,nb_particles=12*nl)
				s.move(impact)
				s.removable = True
				s.set_colors(target.dust_color+(0.5,),target.dust_color+(0,))
				s.set_sizes((0.3, 0.3), (0.7, 0.7))
				s.life = 1
				#second the lazer beam
				s = soya.Smoke(self.parent,nb_particles=12*nl)
				s.move(impact)
				s.removable = True
				s.life = 0.4*l
				s.speed = 1
				s.set_colors((0.121569,0.431373,0.792157,0.8),(0.121569,0.431373,0.792157,0.5+l/20.))
				s.set_sizes((0.2, 0.2), (0, 0))
import sys, os
from random import choice, gauss as normalvariate, randint, random, expovariate
from math import sqrt, pi
import soya
import soya.widget
import soya.sphere
import soya.laser
from soya import Vector, Point

if '-f' in sys.argv:
	soya.init("ode-collision-7-hit_func-3-contacts",width=1280,height=854,fullscreen=True)
else:
	soya.init("ode-collision-7-hit_func-3-contacts",width=1024,height=768)
soya.cursor_set_visible(False)
soya.set_mouse_pos(1280/2,854/2)

soya.path.append(os.path.join(os.path.dirname(sys.argv[0]), "data"))
scene = soya.World()

class Nova(soya.Smoke):
	def __init__(self,parent,nb_particles=12):
		soya.Smoke.__init__(self,parent,nb_particles=nb_particles)
		#self.set_colors((1.0, 1.0, 1.0, 1.0), (1.0, 0.0, 0.0,0.5),(1.0,1.0,0.,0.5),(0.5,0.5,0.5,0.5),(0.,0.,0.,0.5))
		#self.set_sizes ((0.19, 0.19), (0.35, 0.35))
		#self.auto_generate_particle=1
	def added_into(self,parent):
		#print 'former:',self.parent
		if self.parent is not None:
			self.parent.parent.remove(self.parent)
		soya.Smoke.added_into(self,parent)