http://cgi.tutsplus.com/tutorials/creating-a-low-poly-ninja-game-character-using-blender-part-1--cg-16132
http://cgi.tutsplus.com/tutorials/creating-a-low-poly-ninja-game-character-using-blender-part-2--cg-16133
jeudi 15 octobre 2015
Blender créer un personnage
mercredi 23 septembre 2015
Unity ThirdPersonController.js to ThirdPersonController.cs
1: using UnityEngine;
2: using System.Collections;
3: public class ThirdPersonController : MonoBehaviour {
4: public AnimationClip idleAnimation;
5: public AnimationClip walkAnimation;
6: public AnimationClip runAnimation;
7: public AnimationClip jumpPoseAnimation;
8: public float walkMaxAnimationSpeed = 0.75f;
9: public float trotMaxAnimationSpeed= 1.0f;
10: public float runMaxAnimationSpeed = 1.0f;
11: public float jumpAnimationSpeed = 1.15f;
12: public float landAnimationSpeed = 1.0f;
13: private Animation _animation;
14: // The speed when walking
15: public float walkSpeed = 2.0f;
16: // after trotAfterSeconds of walking we trot with trotSpeed
17: public float trotSpeed = 4.0f;
18: // when pressing "Fire3" button (cmd) we start running
19: public float runSpeed = 6.0f;
20: public float inAirControlAcceleration = 3.0f;
21: // How high do we jump when pressing jump and letting go immediately
22: public float jumpHeight = 0.5f;
23: // The gravity for the character
24: public float gravity = 20.0f;
25: // The gravity in controlled descent mode
26: public float speedSmoothing = 10.0f;
27: public float rotateSpeed = 500.0f;
28: public float trotAfterSeconds = 3.0f;
29: public bool canJump = true;
30: private float jumpRepeatTime = 0.05f;
31: private float jumpTimeout = 0.15f;
32: private float groundedTimeout = 0.25f;
33: // The camera doesnt start following the target immediately but waits for a split second to avoid too much waving around.
34: private float lockCameraTimer = 0.0f;
35: // The current move direction in x-z
36: private Vector3 moveDirection = Vector3.zero;
37: // The current vertical speed
38: private float verticalSpeed = 0.0f;
39: // The current x-z move speed
40: private float moveSpeed = 0.0f;
41: // The last collision flags returned from controller.Move
42: private CollisionFlags collisionFlags;
43: // Are we jumping? (Initiated with jump button and not grounded yet)
44: private bool jumping = false;
45: private bool jumpingReachedApex = false;
46: // Are we moving backwards (This locks the camera to not do a 180 degree spin)
47: private bool movingBack = false;
48: // Is the user pressing any keys?
49: private bool isMoving = false;
50: // When did the user start walking (Used for going into trot after a while)
51: private float walkTimeStart = 0.0f;
52: // Last time the jump button was clicked down
53: private float lastJumpButtonTime = -10.0f;
54: // Last time we performed a jump
55: private float lastJumpTime = -1.0f;
56: // the height we jumped from (Used to determine for how long to apply extra jump power after jumping.)
57: private float lastJumpStartHeight = 0.0f;
58: private Vector3 inAirVelocity = Vector3.zero;
59: private float lastGroundedTime = 0.0f;
60: private bool isControllable = true;
61: enum CharacterState {
62: Idle = 0,
63: Walking = 1,
64: Trotting = 2,
65: Running = 3,
66: Jumping = 4,
67: }
68: private CharacterState _characterState;
69: // Use this for initialization
70: void Start () {
71: }
72: void Awake () {
73: moveDirection = transform.TransformDirection(Vector3.forward);
74: _animation = GetComponent <Animation> ();
75: if(!_animation)
76: Debug.Log("The character you would like to control doesn't have animations. Moving her might look weird.");
77: /*
78: public var idleAnimation : AnimationClip;
79: public var walkAnimation : AnimationClip;
80: public var runAnimation : AnimationClip;
81: public var jumpPoseAnimation : AnimationClip;
82: */
83: if(!idleAnimation) {
84: _animation = null;
85: Debug.Log("No idle animation found. Turning off animations.");
86: }
87: if(!walkAnimation) {
88: _animation = null;
89: Debug.Log("No walk animation found. Turning off animations.");
90: }
91: if(!runAnimation) {
92: _animation = null;
93: Debug.Log("No run animation found. Turning off animations.");
94: }
95: if(!jumpPoseAnimation && canJump) {
96: _animation = null;
97: Debug.Log("No jump animation found and the character has canJump enabled. Turning off animations.");
98: }
99: }
100: void UpdateSmoothedMovementDirection ()
101: {
102: Transform cameraTransform = Camera.main.transform;
103: bool grounded = IsGrounded();
104: // Forward vector relative to the camera along the x-z plane
105: Vector3 forward = cameraTransform.TransformDirection(Vector3.forward);
106: forward.y = 0;
107: forward = forward.normalized;
108: // Right vector relative to the camera
109: // Always orthogonal to the forward vector
110: Vector3 right = new Vector3(forward.z, 0, -forward.x);
111: float v = Input.GetAxisRaw("Vertical");
112: float h = Input.GetAxisRaw("Horizontal");
113: // Are we moving backwards or looking backwards
114: if (v < -0.2f)
115: movingBack = true;
116: else
117: movingBack = false;
118: bool wasMoving = isMoving;
119: isMoving = Mathf.Abs (h) > 0.1f || Mathf.Abs (v) > 0.1f;
120: // Target direction relative to the camera
121: Vector3 targetDirection = h * right + v * forward;
122: // Grounded controls
123: if (grounded)
124: {
125: // Lock camera for short period when transitioning moving & standing still
126: lockCameraTimer += Time.deltaTime;
127: if (isMoving != wasMoving)
128: lockCameraTimer = 0.0f;
129: // We store speed and direction seperately,
130: // so that when the character stands still we still have a valid forward direction
131: // moveDirection is always normalized, and we only update it if there is user input.
132: if (targetDirection != Vector3.zero)
133: {
134: // If we are really slow, just snap to the target direction
135: if (moveSpeed < walkSpeed * 0.9f && grounded)
136: {
137: moveDirection = targetDirection.normalized;
138: }
139: // Otherwise smoothly turn towards it
140: else
141: {
142: moveDirection = Vector3.RotateTowards(moveDirection, targetDirection, rotateSpeed * Mathf.Deg2Rad * Time.deltaTime, 1000);
143: moveDirection = moveDirection.normalized;
144: }
145: }
146: // Smooth the speed based on the current target direction
147: float curSmooth = speedSmoothing * Time.deltaTime;
148: // Choose target speed
149: //* We want to support analog input but make sure you cant walk faster diagonally than just forward or sideways
150: float targetSpeed = Mathf.Min(targetDirection.magnitude, 1.0f);
151: _characterState = CharacterState.Idle;
152: // Pick speed modifier
153: if (Input.GetKey (KeyCode.LeftShift) || Input.GetKey (KeyCode.RightShift))
154: {
155: targetSpeed *= runSpeed;
156: _characterState = CharacterState.Running;
157: }
158: else if (Time.time - trotAfterSeconds > walkTimeStart)
159: {
160: targetSpeed *= trotSpeed;
161: _characterState = CharacterState.Trotting;
162: }
163: else
164: {
165: targetSpeed *= walkSpeed;
166: _characterState = CharacterState.Walking;
167: }
168: moveSpeed = Mathf.Lerp(moveSpeed, targetSpeed, curSmooth);
169: // Reset walk time start when we slow down
170: if (moveSpeed < walkSpeed * 0.3f)
171: walkTimeStart = Time.time;
172: }
173: // In air controls
174: else
175: {
176: // Lock camera while in air
177: if (jumping)
178: lockCameraTimer = 0.0f;
179: if (isMoving)
180: inAirVelocity += targetDirection.normalized * Time.deltaTime * inAirControlAcceleration;
181: }
182: }
183: void ApplyJumping ()
184: {
185: // Prevent jumping too fast after each other
186: if (lastJumpTime + jumpRepeatTime > Time.time)
187: return;
188: if (IsGrounded()) {
189: // Jump
190: // - Only when pressing the button down
191: // - With a timeout so you can press the button slightly before landing
192: if (canJump && Time.time < lastJumpButtonTime + jumpTimeout) {
193: verticalSpeed = CalculateJumpVerticalSpeed (jumpHeight);
194: SendMessage("DidJump", SendMessageOptions.DontRequireReceiver);
195: }
196: }
197: }
198: void ApplyGravity ()
199: {
200: if (isControllable) // don't move player at all if not controllable.
201: {
202: // Apply gravity
203: bool jumpButton = Input.GetButton("Jump");
204: // When we reach the apex of the jump we send out a message
205: if (jumping && !jumpingReachedApex && verticalSpeed <= 0.0f)
206: {
207: jumpingReachedApex = true;
208: SendMessage("DidJumpReachApex", SendMessageOptions.DontRequireReceiver);
209: }
210: if (IsGrounded ())
211: verticalSpeed = 0.0f;
212: else
213: verticalSpeed -= gravity * Time.deltaTime;
214: }
215: }
216: float CalculateJumpVerticalSpeed (float targetJumpHeight)
217: {
218: // From the jump height and gravity we deduce the upwards speed
219: // for the character to reach at the apex.
220: return Mathf.Sqrt(2 * targetJumpHeight * gravity);
221: }
222: void DidJump ()
223: {
224: jumping = true;
225: jumpingReachedApex = false;
226: lastJumpTime = Time.time;
227: lastJumpStartHeight = transform.position.y;
228: lastJumpButtonTime = -10;
229: _characterState = CharacterState.Jumping;
230: }
231: void OnControllerColliderHit (ControllerColliderHit hit)
232: {
233: // Debug.DrawRay(hit.point, hit.normal);
234: if (hit.moveDirection.y > 0.01f)
235: return;
236: }
237: float GetSpeed () {
238: return moveSpeed;
239: }
240: public bool IsJumping () {
241: return jumping;
242: }
243: bool IsGrounded () {
244: return (collisionFlags & CollisionFlags.CollidedBelow) != 0;
245: }
246: Vector3 GetDirection () {
247: return moveDirection;
248: }
249: public bool IsMovingBackwards () {
250: return movingBack;
251: }
252: public float GetLockCameraTimer ()
253: {
254: return lockCameraTimer;
255: }
256: bool IsMoving ()
257: {
258: return Mathf.Abs(Input.GetAxisRaw("Vertical")) + Mathf.Abs(Input.GetAxisRaw("Horizontal")) > 0.5f;
259: }
260: bool HasJumpReachedApex ()
261: {
262: return jumpingReachedApex;
263: }
264: bool IsGroundedWithTimeout ()
265: {
266: return lastGroundedTime + groundedTimeout > Time.time;
267: }
268: void Reset ()
269: {
270: gameObject.tag = "Player";
271: }
272: // Update is called once per frame
273: void Update () {
274: if (!isControllable)
275: {
276: // kill all inputs if not controllable.
277: Input.ResetInputAxes();
278: }
279: if (Input.GetButtonDown ("Jump"))
280: {
281: lastJumpButtonTime = Time.time;
282: }
283: UpdateSmoothedMovementDirection();
284: // Apply gravity
285: // - extra power jump modifies gravity
286: // - controlledDescent mode modifies gravity
287: ApplyGravity ();
288: // Apply jumping logic
289: ApplyJumping ();
290: // Calculate actual motion
291: Vector3 movement = moveDirection * moveSpeed + new Vector3 (0, verticalSpeed, 0) + inAirVelocity;
292: movement *= Time.deltaTime;
293: // Move the controller
294: CharacterController controller = GetComponent <CharacterController> ();
295: collisionFlags = controller.Move(movement);
296: // ANIMATION sector
297: if(_animation) {
298: if(_characterState == CharacterState.Jumping)
299: {
300: if(!jumpingReachedApex) {
301: _animation[jumpPoseAnimation.name].speed = jumpAnimationSpeed;
302: _animation[jumpPoseAnimation.name].wrapMode = WrapMode.ClampForever;
303: _animation.CrossFade(jumpPoseAnimation.name);
304: } else {
305: _animation[jumpPoseAnimation.name].speed = -landAnimationSpeed;
306: _animation[jumpPoseAnimation.name].wrapMode = WrapMode.ClampForever;
307: _animation.CrossFade(jumpPoseAnimation.name);
308: }
309: }
310: else
311: {
312: if(controller.velocity.sqrMagnitude < 0.1) {
313: _animation.CrossFade(idleAnimation.name);
314: }
315: else
316: {
317: if(_characterState == CharacterState.Running) {
318: _animation[runAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0f, runMaxAnimationSpeed);
319: _animation.CrossFade(runAnimation.name);
320: }
321: else if(_characterState == CharacterState.Trotting) {
322: _animation[walkAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0f, trotMaxAnimationSpeed);
323: _animation.CrossFade(walkAnimation.name);
324: }
325: else if(_characterState == CharacterState.Walking) {
326: _animation[walkAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0f, walkMaxAnimationSpeed);
327: _animation.CrossFade(walkAnimation.name);
328: }
329: }
330: }
331: }
332: // ANIMATION sector
333: // Set rotation to the move direction
334: if (IsGrounded())
335: {
336: transform.rotation = Quaternion.LookRotation(moveDirection);
337: }
338: else
339: {
340: var xzMove = movement;
341: xzMove.y = 0;
342: if (xzMove.sqrMagnitude > 0.001f)
343: {
344: transform.rotation = Quaternion.LookRotation(xzMove);
345: }
346: }
347: // We are in jump mode but just became grounded
348: if (IsGrounded())
349: {
350: lastGroundedTime = Time.time;
351: inAirVelocity = Vector3.zero;
352: if (jumping)
353: {
354: jumping = false;
355: SendMessage("DidLand", SendMessageOptions.DontRequireReceiver);
356: }
357: }
358: }
359: }
Unity ThirdPersonCamera.js to ThirdPersonCamera.cs
1: using UnityEngine;
2: using System.Collections;
3: public class ThirdPersonCamera : MonoBehaviour {
4: Transform cameraTransform;
5: private Transform _target;
6: // The distance in the x-z plane to the target
7: public float distance = 7.0f;
8: // the height we want the camera to be above the target
9: public float height = 3.0f;
10: public float angularSmoothLag = 0.3f;
11: public float angularMaxSpeed = 15.0f;
12: public float heightSmoothLag = 0.3f;
13: public float snapSmoothLag = 0.2f;
14: public float snapMaxSpeed = 720.0f;
15: public float clampHeadPositionScreenSpace = 0.75f;
16: public float lockCameraTimeout = 0.2f;
17: private Vector3 headOffset = Vector3.zero;
18: private Vector3 centerOffset = Vector3.zero;
19: private float heightVelocity = 0.0f;
20: private float angleVelocity = 0.0f;
21: private bool snap = false;
22: private ThirdPersonController controller;
23: private float targetHeight = 100000.0f;
24: void Awake ()
25: {
26: if(!cameraTransform && Camera.main)
27: cameraTransform = Camera.main.transform;
28: if(!cameraTransform) {
29: Debug.Log("Please assign a camera to the ThirdPersonCamera script.");
30: enabled = false;
31: }
32: _target = transform;
33: if (_target)
34: {
35: controller = _target.GetComponent <ThirdPersonController> ();
36: }
37: if (controller)
38: {
39: Collider characterController = _target.GetComponent <Collider> ();
40: centerOffset = characterController.bounds.center - _target.position;
41: headOffset = centerOffset;
42: headOffset.y = characterController.bounds.max.y - _target.position.y;
43: }
44: else
45: Debug.Log("Please assign a target to the camera that has a ThirdPersonController script attached.");
46: Cut(_target, centerOffset);
47: }
48: float AngleDistance (float a, float b)
49: {
50: a = Mathf.Repeat(a, 360);
51: b = Mathf.Repeat(b, 360);
52: return Mathf.Abs(b - a);
53: }
54: void DebugDrawStuff ()
55: {
56: Debug.DrawLine(_target.position, _target.position + headOffset);
57: }
58: void Apply (Transform dummyTarget , Vector3 dummyCenter)
59: {
60: // Early out if we don't have a target
61: if (!controller)
62: return;
63: Vector3 targetCenter = _target.position + centerOffset;
64: Vector3 targetHead = _target.position + headOffset;
65: // DebugDrawStuff();
66: // Calculate the current & target rotation angles
67: float originalTargetAngle = _target.eulerAngles.y;
68: float currentAngle = cameraTransform.eulerAngles.y;
69: // Adjust real target angle when camera is locked
70: float targetAngle = originalTargetAngle;
71: // When pressing Fire2 (alt) the camera will snap to the target direction real quick.
72: // It will stop snapping when it reaches the target
73: if (Input.GetButton("Fire2"))
74: snap = true;
75: if (snap)
76: {
77: // We are close to the target, so we can stop snapping now!
78: if (AngleDistance (currentAngle, originalTargetAngle) < 3.0)
79: snap = false;
80: currentAngle = Mathf.SmoothDampAngle(currentAngle, targetAngle, ref angleVelocity, snapSmoothLag, snapMaxSpeed);
81: }
82: // Normal camera motion
83: else
84: {
85: if (controller.GetLockCameraTimer () < lockCameraTimeout)
86: {
87: targetAngle = currentAngle;
88: }
89: // Lock the camera when moving backwards!
90: // * It is really confusing to do 180 degree spins when turning around.
91: if (AngleDistance (currentAngle, targetAngle) > 160 && controller.IsMovingBackwards ())
92: targetAngle += 180;
93: currentAngle = Mathf.SmoothDampAngle(currentAngle, targetAngle, ref angleVelocity, angularSmoothLag, angularMaxSpeed);
94: }
95: // When jumping don't move camera upwards but only down!
96: if (controller.IsJumping ())
97: {
98: // We'd be moving the camera upwards, do that only if it's really high
99: float newTargetHeight = targetCenter.y + height;
100: if (newTargetHeight < targetHeight || newTargetHeight - targetHeight > 5)
101: targetHeight = targetCenter.y + height;
102: }
103: // When walking always update the target height
104: else
105: {
106: targetHeight = targetCenter.y + height;
107: }
108: // Damp the height
109: float currentHeight = cameraTransform.position.y;
110: currentHeight = Mathf.SmoothDamp (currentHeight, targetHeight, ref heightVelocity, heightSmoothLag);
111: // Convert the angle into a rotation, by which we then reposition the camera
112: Quaternion currentRotation = Quaternion.Euler (0, currentAngle, 0);
113: // Set the position of the camera on the x-z plane to:
114: // distance meters behind the target
115: cameraTransform.position = targetCenter;
116: cameraTransform.position += currentRotation * Vector3.back * distance;
117: // Set the height of the camera
118: cameraTransform.position = new Vector3 (cameraTransform.position.x,currentHeight,cameraTransform.position.z);
119: // Always look at the target
120: SetUpRotation(targetCenter, targetHead);
121: }
122: void Cut (Transform dummyTarget, Vector3 dummyCenter)
123: {
124: float oldHeightSmooth = heightSmoothLag;
125: float oldSnapMaxSpeed = snapMaxSpeed;
126: float oldSnapSmooth = snapSmoothLag;
127: snapMaxSpeed = 10000;
128: snapSmoothLag = 0.001f;
129: heightSmoothLag = 0.001f;
130: snap = true;
131: Apply (transform, Vector3.zero);
132: heightSmoothLag = oldHeightSmooth;
133: snapMaxSpeed = oldSnapMaxSpeed;
134: snapSmoothLag = oldSnapSmooth;
135: }
136: void SetUpRotation (Vector3 centerPos, Vector3 headPos)
137: {
138: // Now it's getting hairy. The devil is in the details here, the big issue is jumping of course.
139: // * When jumping up and down we don't want to center the guy in screen space.
140: // This is important to give a feel for how high you jump and avoiding large camera movements.
141: //
142: // * At the same time we dont want him to ever go out of screen and we want all rotations to be totally smooth.
143: //
144: // So here is what we will do:
145: //
146: // 1. We first find the rotation around the y axis. Thus he is always centered on the y-axis
147: // 2. When grounded we make him be centered
148: // 3. When jumping we keep the camera rotation but rotate the camera to get him back into view if his head is above some threshold
149: // 4. When landing we smoothly interpolate towards centering him on screen
150: Vector3 cameraPos = cameraTransform.position;
151: Vector3 offsetToCenter = centerPos - cameraPos;
152: // Generate base rotation only around y-axis
153: Quaternion yRotation = Quaternion.LookRotation(new Vector3(offsetToCenter.x, 0, offsetToCenter.z));
154: Vector3 relativeOffset = Vector3.forward * distance + Vector3.down * height;
155: cameraTransform.rotation = yRotation * Quaternion.LookRotation(relativeOffset);
156: // Calculate the projected center position and top position in world space
157: Ray centerRay = cameraTransform.GetComponent <Camera>().ViewportPointToRay(new Vector3(0.5f, 0.5f, 1));
158: Ray topRay = cameraTransform.GetComponent <Camera>().ViewportPointToRay(new Vector3(0.5f, clampHeadPositionScreenSpace, 1));
159: Vector3 centerRayPos = centerRay.GetPoint(distance);
160: Vector3 topRayPos = topRay.GetPoint(distance);
161: float centerToTopAngle = Vector3.Angle(centerRay.direction, topRay.direction);
162: float heightToAngle = centerToTopAngle / (centerRayPos.y - topRayPos.y);
163: float extraLookAngle = heightToAngle * (centerRayPos.y - centerPos.y);
164: if (extraLookAngle < centerToTopAngle)
165: {
166: extraLookAngle = 0;
167: }
168: else
169: {
170: extraLookAngle = extraLookAngle - centerToTopAngle;
171: cameraTransform.rotation *= Quaternion.Euler(-extraLookAngle, 0, 0);
172: }
173: }
174: Vector3 GetCenterOffset ()
175: {
176: return centerOffset;
177: }
178: // Use this for initialization
179: void Start () {
180: }
181: // Update is called once per frame
182: void Update () {
183: }
184: void LateUpdate () {
185: Apply (transform, Vector3.zero);
186: }
187: }
Format code for blog
http://danielthat.blogspot.ca/2013/03/how-to-display-code-in-blogger-posts.html
http://codeformatter.blogspot.in/2009/06/about-code-formatter.html
http://codeformatter.blogspot.in/2009/06/about-code-formatter.html
mercredi 2 septembre 2015
Unity 3D création d'un arc avec Line Renderer/ Unity 3D create Arc with Line Renderer
J'ai téléchargé le projet fait par l'usager UVRadiation sur le forum;
http://forum.unity3d.com/threads/projection-trajectory-arc.12588/
Le code était en Javascript, je l'ai donc converti en C# et fait la modification pour que l'arc soit créé à partir de 3 point (début, milieu et fin). Le mouvement de la souris modifie la position de l'objet fin ce qui agrandit et diminue l'arc.
J'ai aussi pris les fonctions du script Bezier que j'ai inclus directement dans le script ArcBehavior.cs
Eng/
I downloaded the project done by UVRadiation user forum ;
http://forum.unity3d.com/threads/projection-trajectory-arc.12588/
The code was in Javascript, so I converted to C # and made the change to the arc is created from three points (start, middle and end) . The movement of the mouse changes the position of the end object which enlarges and reduces the arc.
I also took the functions of Bezier script I included directly in the script ArcBehavior.cs
http://forum.unity3d.com/threads/projection-trajectory-arc.12588/
Le code était en Javascript, je l'ai donc converti en C# et fait la modification pour que l'arc soit créé à partir de 3 point (début, milieu et fin). Le mouvement de la souris modifie la position de l'objet fin ce qui agrandit et diminue l'arc.
J'ai aussi pris les fonctions du script Bezier que j'ai inclus directement dans le script ArcBehavior.cs
Eng/
I downloaded the project done by UVRadiation user forum ;
http://forum.unity3d.com/threads/projection-trajectory-arc.12588/
The code was in Javascript, so I converted to C # and made the change to the arc is created from three points (start, middle and end) . The movement of the mouse changes the position of the end object which enlarges and reduces the arc.
I also took the functions of Bezier script I included directly in the script ArcBehavior.cs
1: using UnityEngine;
2: using System.Collections;
3: public class ArcBehaviourC1: MonoBehaviour {
4: public Transform start;
5: public Transform middle;
6: public Transform end;
7: public float maxHeight = 200;
8: public float maxWidth = 200 ;
9: public int sections = 10;
10: int floorMask;
11: Ray shootRay;
12: LineRenderer GrenadeLine;
13: float camRayLength = 50f;
14: bool raycastok;
15: // Use this for initialization
16: void Start () {
17: GrenadeLine = GetComponent <LineRenderer> ();
18: floorMask = LayerMask.GetMask ("Floor");
19: GrenadeLine.SetVertexCount(sections);
20: }
21: // Update is called once per frame
22: void Update () {
23: Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
24: RaycastHit floorHit;
25: shootRay.origin = transform.position;
26: shootRay.direction = transform.forward;
27: raycastok = Physics.Raycast (camRay, out floorHit, camRayLength, floorMask);
28: Vector3 objectToMouse = floorHit.point - transform.position;
29: objectToMouse.y = 0f;
30: if (Mathf.Abs(objectToMouse.z) < 20 && Mathf.Abs(objectToMouse.x) < 20 )
31: {
32: if (raycastok)
33: {
34: GrenadeLine.enabled = true;
35: end.transform.position = floorHit.point;
36: Debug.DrawLine (start.position, middle.position, Color.red);
37: Debug.DrawLine (middle.position, end.position, Color.red);
38: Debug.DrawLine (start.position, end.position, Color.red);
39: Plot (start.position, middle.position, end.position);
40: }
41: else
42: {
43: GrenadeLine.enabled = false;
44: }
45: }
46: else
47: {
48: GrenadeLine.enabled = false;
49: }
50: }
51: Vector3 GetQuadraticCoordinates(float t , Vector3 p0, Vector3 c0, Vector3 p1)
52: {
53: Vector3 Result;
54: Result = Mathf.Pow(1-t,2)*p0 + 2*t*(1-t)*c0 + Mathf.Pow(t,2)*p1 ;
55: return Result;
56: }
57: void Plot(Vector3 p0 , Vector3 c0,Vector3 p1 )
58: {
59: float t;
60: for (int i = 0 ; i < sections ; i++ )
61: {
62: t = (float)i/(sections-1);
63: GrenadeLine.SetPosition (i ,GetQuadraticCoordinates(t , p0 , c0 , p1 ));
64: }
65: }
66: }
vendredi 17 juillet 2015
Unity 3D RTS Tutoriel
http://stormtek.geek.nz/rts_tutorial/part6.php
lundi 29 juin 2015
Programme de transfert Photo / Vidéo Mutli Caméra (Mise à jour)
http://informatique-prog-ef.blogspot.com/2015/06/programme-de-transfert-photo-video_29.html
J'ai modifié le programme pour permettre de sélectionner les dates à transférer. Il y a aussi une nouvelle section qui permet de visualiser les "Thumbnail" des photos/vidéos qui sont présents dans les dates sélectionnées. Pour pouvoir créer les "Thumbnail" des vidéos, j'utilise FFmpeg qui était déjà utilisé pour la conversion.
Voir la page: https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video
J'ai modifié le programme pour permettre de sélectionner les dates à transférer. Il y a aussi une nouvelle section qui permet de visualiser les "Thumbnail" des photos/vidéos qui sont présents dans les dates sélectionnées. Pour pouvoir créer les "Thumbnail" des vidéos, j'utilise FFmpeg qui était déjà utilisé pour la conversion.
Voir la page: https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video
mardi 23 juin 2015
Visual Studio SQLite
https://nickcharlton.net/posts/sqlite-with-csharp.html
http://swinbrain.ict.swin.edu.au/wiki/Create_a_SQLite_Database
http://swinbrain.ict.swin.edu.au/wiki/Create_a_SQLite_Database
Programme de transfert Photo / Vidéo Mutli Caméra
Je possède une caméra Sony
HDRXR260V et le logiciel de transfert qui vient avec celle-ci est très
lent pour transférer les vidéos de la caméra, car il convertit les vidéo
avant de les transférer et le tout ce fait par USB. Je trouvais ceci
très inefficace, l'autre façon de fonctionner était d'aller manuellement
chercher les vidéos par l'explorateur Windows mais encore là j'obtenais
un problème dû au fait que je devais créer l'arborescence manuellement
(classer par date). J'en suis venu à la conclusion de créer mon
programme de transfert de média et par le fait même transférer les
photos/vidéo de n'importe quel marque de caméra
J'ai programmé le tout avec Visual Studio 2012 Express en C#. L'interface est très simple et très de base.
Vu
que le tout est développé avec la version Express de Visual Studio,
selon la licence, je ne peux pas publier le code source (Selon ce que
j'ai lu... je peux p-ê me tromper).
J'ai programmé le tout avec Visual Studio 2012 Express en C#. L'interface est très simple et très de base.
On
peut choisir le device que l'on veut et les options qui ont été
pré-configurés. Lorsqu'on choisit l'appareil, le périphérique USB
associé à l'appareil est détecté et la lettre du lecteur s'affiche dans
l'indicateur et on peut ensuite débuter le transfert. Le programme va
identifié les fichiers à transférer sous le dossier source, créer une
arborescence par date(AAAA-MM-JJ) dans le dossier de destination, toutes
les photos/Vidéo qui ont été prises la même date se retrouvent dans le
même dossier de destination. Il y a donc un classement qui se fait en
même temps. J'ai inclus un programme crc32.exe qui permet de vérifier
que les checksum du fichier source et de destination sont semblables.
Une option de 2ième dossier de backup est disponible. Dans le cas de
vidéo, il est possible de convertir ceux-ci avec ffmpeg avec une ligne
de commande configurable et les vidéos convertis sont enregistrés dans
un dossier de destination.
La
conclusion est que ce petit programme me permet de sauver énormément de
temps. Certaines fonctions ne sont pas encore codé: "Transférer
seulement les récentes" et "Tranférer et Supprimer". Cependant, pour ce
qui est de la première, il y a une validation qui est fait avant de
copier le fichier à savoir si celui-ci existe déjà dans le dossier de
destination, si c'est le cas le fichier n'est pas recopié mais le
checksum est quand même validé.
Guide programmation WPF
http://www.wpftutorial.net/WPFIntroduction.html
http://www.codeproject.com/Articles/23772/WPF-A-Beginner-s-Guide-Part-of-n
http://www.codeproject.com/Articles/23772/WPF-A-Beginner-s-Guide-Part-of-n
Unity Site différent type de Camera
http://code.tutsplus.com/tutorials/unity3d-third-person-cameras--mobile-11230
Reconaissance Facial
OPENCVdotNET
https://code.google.com/p/opencvdotnet/
http://friism.com/facedectection-in-c-with-less-than-50-loc
https://code.google.com/p/opencvdotnet/
http://friism.com/facedectection-in-c-with-less-than-50-loc
SQLite Password
http://stackoverflow.com/questions/1381264/password-protect-a-sqlite-db-is-it-possible
SQLiteConnection conn = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
conn.SetPassword("password");
conn.open();
then next time you can access it likeconn = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;Password=password;");
conn.Open();
This wont allow any GUI editor to view Your data. Later if you wish to change the password, use
conn.ChangePassword("new_password");
To reset or remove password, use conn.ChangePassword(String.Empty);
HTTP GET avec Visual C#
http://stackoverflow.com/questions/943852/how-to-send-an-https-get-request-in-c-sharp
visual c# int à une chaîne de caractère avec une longueur fixe.
http://stackoverflow.com/questions/6399771/string-format-in-net-convert-integer-to-fixed-width-string
Input gamepad
http://www.codeproject.com/Articles/185522/Using-the-Raw-Input-API-to-Process-Joystick-Input
Visual C# Joystick Input
http://msdn.microsoft.com/en-us/library/windows/desktop/bb153251%28v=vs.85%29.aspx
SlimDx
http://slimdx.org/
Visual C# Joystick Input
http://msdn.microsoft.com/en-us/library/windows/desktop/bb153251%28v=vs.85%29.aspx
SlimDx
http://slimdx.org/
ActiveX Dev
http://www.codeproject.com/Articles/24089/Create-ActiveX-in-NET-Step-by-Step
http://www.codeproject.com/Articles/1256/Exposing-Windows-Forms-Controls-as-ActiveX-control
http://www.codeproject.com/Articles/14533/A-Complete-ActiveX-Web-Control-Tutorial
http://stackoverflow.com/questions/3360160/how-do-i-create-an-activex-com-in-c
http://www.mrrives.com/Technology/?p=767
http://www.digitallycreated.net/Blog/38/using-makecert-to-create-certificates-for-development
http://msdn.microsoft.com/en-us/library/aa231196%28v=vs.60%29.aspx
http://surfthenetsafely.com/ieseczone3.htm
http://msdn.microsoft.com/en-us/library/aewdt4xt%28v=vs.90%29.aspx
http://blogs.msdn.com/b/winsdk/archive/2009/11/13/steps-to-sign-a-file-using-signtool-exe.aspx
http://www.codeproject.com/Articles/1256/Exposing-Windows-Forms-Controls-as-ActiveX-control
http://www.codeproject.com/Articles/14533/A-Complete-ActiveX-Web-Control-Tutorial
http://stackoverflow.com/questions/3360160/how-do-i-create-an-activex-com-in-c
http://www.mrrives.com/Technology/?p=767
http://www.digitallycreated.net/Blog/38/using-makecert-to-create-certificates-for-development
http://msdn.microsoft.com/en-us/library/aa231196%28v=vs.60%29.aspx
http://surfthenetsafely.com/ieseczone3.htm
http://msdn.microsoft.com/en-us/library/aewdt4xt%28v=vs.90%29.aspx
http://blogs.msdn.com/b/winsdk/archive/2009/11/13/steps-to-sign-a-file-using-signtool-exe.aspx
C++ Liste des fenêtres ouvertes dans la session
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <tlhelp32.h>
#include <vector>
#include <string>
#include <ShellAPI.h>
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
...
EnumWindows(EnumWindowsProc, NULL);
....
std::string progtitle("Notepad.exe");
GetClassNameA(hwnd3,class_name, sizeof(class_name));
GetWindowTextA(hwnd3,title,sizeof(title));
std::string wintitle(title);
//std::string classname(class_name);
if(wintitle.find(progtitle) != std::string::npos)
{
bTitleFound = TRUE;
wintitleglb = wintitle;
//MessageBoxA(0, classname.c_str(), "MessageBox caption", MB_OK);
HWND iHandle = FindWindowA("TabThumbnailWindow", wintitle.c_str());
if(iHandle)
{
SendMessage(iHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
}
else
{
iHandle = FindWindowA("IEFrame", wintitle.c_str());
if(iHandle)
{
SendMessage(iHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
}
}
}
return TRUE;
}
#include <stdlib.h>
#include <stdio.h>
#include <tlhelp32.h>
#include <vector>
#include <string>
#include <ShellAPI.h>
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam);
...
EnumWindows(EnumWindowsProc, NULL);
....
std::string progtitle("Notepad.exe");
GetClassNameA(hwnd3,class_name, sizeof(class_name));
GetWindowTextA(hwnd3,title,sizeof(title));
std::string wintitle(title);
//std::string classname(class_name);
if(wintitle.find(progtitle) != std::string::npos)
{
bTitleFound = TRUE;
wintitleglb = wintitle;
//MessageBoxA(0, classname.c_str(), "MessageBox caption", MB_OK);
HWND iHandle = FindWindowA("TabThumbnailWindow", wintitle.c_str());
if(iHandle)
{
SendMessage(iHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
}
else
{
iHandle = FindWindowA("IEFrame", wintitle.c_str());
if(iHandle)
{
SendMessage(iHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
}
}
}
return TRUE;
}
C++ Démarre une application à partir d'un Service
Le service démarre avec l'usager System Local donc pour démarrer une
application au nom de l'usager il faut démarrer celle-ci avec
CreateProcessAsUser. Il faut aller chercher le token de l'usager dans
la session console active.
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <tlhelp32.h>
#include <vector>
#include <string>
#include <ShellAPI.h>
#include <userenv.h>
#include <winnt.h>
#include <WtsApi32.h>
#include <process.h>
HANDLE currentToken = 0;
HANDLE primaryToken = 0;
int dwSessionId = 0;
HANDLE hUserToken = 0;
HANDLE hTokenDup = 0;
PWTS_SESSION_INFO pSessionInfo = 0;
DWORD dwCount = 0;
//Get User Token
WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo, &dwCount);
int dataSize = sizeof(WTS_SESSION_INFO);
for (DWORD i = 0; i < dwCount; ++i)
{
WTS_SESSION_INFO si = pSessionInfo[i];
if (WTSActive == si.State)
{
dwSessionId = si.SessionId;
break;
}
}
WTSFreeMemory(pSessionInfo);
BOOL bRet = WTSQueryUserToken(dwSessionId, ¤tToken);
int errorcode = GetLastError();
if(bRet == false)
{
bLoggedUser = false;
}
else
{
bLoggedUser = true;
}
bRet = DuplicateTokenEx(currentToken, TOKEN_ASSIGN_PRIMARY | TOKEN_ALL_ACCESS, 0, SecurityImpersonation, TokenPrimary, &primaryToken);
errorcode = GetLastError();
if (bRet == false)
{
//return 0;
}
if (primaryToken == 0)
{
}
STARTUPINFO StartupInfo = {0};
PROCESS_INFORMATION processInfo;
StartupInfo.cb = sizeof(STARTUPINFO);
STARTUPINFO si = { sizeof(STARTUPINFO) };
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
PROCESS_INFORMATION pi;
LPVOID pEnvironment = NULL;
bRet = CreateEnvironmentBlock(&pEnvironment, primaryToken, TRUE);
if (!bRet) {
//hr = GetLastError();
//return hr;
}
.....
CreateProcessAsUser(primaryToken,L"c:\\application.exe",NULL, NULL, NULL, FALSE, CREATE_UNICODE_ENVIRONMENT , pEnvironment, NULL, &si, &pi);
DestroyEnvironmentBlock(pEnvironment);
CloseHandle(primaryToken);
CloseHandle(currentToken);
CloseHandle( pi.hThread );
CloseHandle( pi.hProcess );
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <tlhelp32.h>
#include <vector>
#include <string>
#include <ShellAPI.h>
#include <userenv.h>
#include <winnt.h>
#include <WtsApi32.h>
#include <process.h>
HANDLE currentToken = 0;
HANDLE primaryToken = 0;
int dwSessionId = 0;
HANDLE hUserToken = 0;
HANDLE hTokenDup = 0;
PWTS_SESSION_INFO pSessionInfo = 0;
DWORD dwCount = 0;
//Get User Token
WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pSessionInfo, &dwCount);
int dataSize = sizeof(WTS_SESSION_INFO);
for (DWORD i = 0; i < dwCount; ++i)
{
WTS_SESSION_INFO si = pSessionInfo[i];
if (WTSActive == si.State)
{
dwSessionId = si.SessionId;
break;
}
}
WTSFreeMemory(pSessionInfo);
BOOL bRet = WTSQueryUserToken(dwSessionId, ¤tToken);
int errorcode = GetLastError();
if(bRet == false)
{
bLoggedUser = false;
}
else
{
bLoggedUser = true;
}
bRet = DuplicateTokenEx(currentToken, TOKEN_ASSIGN_PRIMARY | TOKEN_ALL_ACCESS, 0, SecurityImpersonation, TokenPrimary, &primaryToken);
errorcode = GetLastError();
if (bRet == false)
{
//return 0;
}
if (primaryToken == 0)
{
}
STARTUPINFO StartupInfo = {0};
PROCESS_INFORMATION processInfo;
StartupInfo.cb = sizeof(STARTUPINFO);
STARTUPINFO si = { sizeof(STARTUPINFO) };
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
PROCESS_INFORMATION pi;
LPVOID pEnvironment = NULL;
bRet = CreateEnvironmentBlock(&pEnvironment, primaryToken, TRUE);
if (!bRet) {
//hr = GetLastError();
//return hr;
}
.....
CreateProcessAsUser(primaryToken,L"c:\\application.exe",NULL, NULL, NULL, FALSE, CREATE_UNICODE_ENVIRONMENT , pEnvironment, NULL, &si, &pi);
DestroyEnvironmentBlock(pEnvironment);
CloseHandle(primaryToken);
CloseHandle(currentToken);
CloseHandle( pi.hThread );
CloseHandle( pi.hProcess );
C++ Vérifier si on Process est déjà démarré
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <tlhelp32.h>
#include <vector>
#include <string>
#include <ShellAPI.h>
#include <userenv.h>
#include <winnt.h>
#include <WtsApi32.h>
#include <process.h>
DWORD aProcesses[1024], cbNeeded, cProcesses;
HANDLE hProcess;
bool bProcRunning = false;WCHAR filename[260];
wcscpy(filename, L"Application.exe");
bool bLoggedUser;
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
PROCESSENTRY32 pEntry;
pEntry.dwSize = sizeof (pEntry);
BOOL hRes = Process32First(hSnapShot, &pEntry);
while (hRes)
{
if (wcscmp(pEntry.szExeFile, filename)==0)
{
bProcRunning=true;
if( bLoggedUser == false)
{
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0,(DWORD) pEntry.th32ProcessID);
if (hProcess != NULL)
{
TerminateProcess(hProcess, 9);
CloseHandle(hProcess);
}
}
}
hRes = Process32Next(hSnapShot, &pEntry);
}
CloseHandle(hSnapShot);
#include <stdlib.h>
#include <stdio.h>
#include <tlhelp32.h>
#include <vector>
#include <string>
#include <ShellAPI.h>
#include <userenv.h>
#include <winnt.h>
#include <WtsApi32.h>
#include <process.h>
DWORD aProcesses[1024], cbNeeded, cProcesses;
HANDLE hProcess;
bool bProcRunning = false;WCHAR filename[260];
wcscpy(filename, L"Application.exe");
bool bLoggedUser;
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
PROCESSENTRY32 pEntry;
pEntry.dwSize = sizeof (pEntry);
BOOL hRes = Process32First(hSnapShot, &pEntry);
while (hRes)
{
if (wcscmp(pEntry.szExeFile, filename)==0)
{
bProcRunning=true;
if( bLoggedUser == false)
{
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0,(DWORD) pEntry.th32ProcessID);
if (hProcess != NULL)
{
TerminateProcess(hProcess, 9);
CloseHandle(hProcess);
}
}
}
hRes = Process32Next(hSnapShot, &pEntry);
}
CloseHandle(hSnapShot);
Visual C# Effacer tout les éléments d'une liste
listBox_SelectStation.Items.Clear();
Visual C# Enlever des éléments de la liste
ArrayList SelectedItems = new ArrayList(listBox_SelectStation.SelectedItems);
foreach (var selectitem in SelectedItems)
{
listBox_SelectStation.Items.Remove(selectitem);
}
foreach (var selectitem in SelectedItems)
{
listBox_SelectStation.Items.Remove(selectitem);
}
Visual C# Énumérer fichier dans un dossier et remplir une liste avec ceci
foreach (var filepath in Directory.EnumerateFiles(path))
{
comboBox_StationFile.Items.Add(filepath.Replace("path to remove",""));
}
{
comboBox_StationFile.Items.Add(filepath.Replace("path to remove",""));
}
Visual C# vérification de l'existence d'un fichier ou répertoire
Fichier:
if(File.Exists(string_Path+ "config.ini"))
Répertoire
if(Directory.Exists(string_Path))
if(File.Exists(string_Path+ "config.ini"))
Répertoire
if(Directory.Exists(string_Path))
Visual C# lire un fichier
using (StreamReader sr = File.OpenText(textFile))
{
while ((compare = sr.ReadLine()) != null)
{
code;
}
}
{
while ((compare = sr.ReadLine()) != null)
{
code;
}
}
Visual C# écrire une ligne dans un fichier
using (StreamWriter sw = File.CreateText(string_command))
{
sw.WriteLine(string_line);
}
{
sw.WriteLine(string_line);
}
Visual C# lancement d'un ligne de commande avec fenêtre cachée.
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = string_command;
p.Start();
p.WaitForExit(); // Attend la fin de l'exécution avant de continuer dans le code
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = string_command;
p.Start();
p.WaitForExit(); // Attend la fin de l'exécution avant de continuer dans le code
NetBeans Java exécuter un programme.exe ou une ligne de commande
Pour exécuter une ligne de commande, voici comment faire:
File destDir = jFileChooser_Dest.getCurrentDirectory();
String del_cmd = "cmd /c rmdir /S /Q " + destDir;
String create_cmd= "cmd /c mkdir " + destDir;
try{
Process rt = Runtime.getRuntime().exec(del_cmd);
StreamGobbler errorGobbler = new
StreamGobbler(rt.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(rt.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
rt.waitFor();
//Process pr = rt.exec();
}catch (IOException ex){
//jTextField_Statut.setText(ex.toString());
Logger.getLogger(MedFilm_MainView.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(MedFilm_MainView.class.getName()).log(Level.SEVERE, null, ex);
}
try{
Process rt = Runtime.getRuntime().exec(create_cmd);
StreamGobbler errorGobbler = new
StreamGobbler(rt.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(rt.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
rt.waitFor();
//Process pr = rt.exec();
}catch (IOException ex){
//jTextField_Statut.setText(ex.toString());
Logger.getLogger(MedFilm_MainView.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(MedFilm_MainView.class.getName()).log(Level.SEVERE, null, ex);
}
jFileChooser_Dest.rescanCurrentDirectory();
}
File destDir = jFileChooser_Dest.getCurrentDirectory();
String del_cmd = "cmd /c rmdir /S /Q " + destDir;
String create_cmd= "cmd /c mkdir " + destDir;
try{
Process rt = Runtime.getRuntime().exec(del_cmd);
StreamGobbler errorGobbler = new
StreamGobbler(rt.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(rt.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
rt.waitFor();
//Process pr = rt.exec();
}catch (IOException ex){
//jTextField_Statut.setText(ex.toString());
Logger.getLogger(MedFilm_MainView.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(MedFilm_MainView.class.getName()).log(Level.SEVERE, null, ex);
}
try{
Process rt = Runtime.getRuntime().exec(create_cmd);
StreamGobbler errorGobbler = new
StreamGobbler(rt.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(rt.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
rt.waitFor();
//Process pr = rt.exec();
}catch (IOException ex){
//jTextField_Statut.setText(ex.toString());
Logger.getLogger(MedFilm_MainView.class.getName()).log(Level.SEVERE, null, ex);
} catch (InterruptedException ex) {
Logger.getLogger(MedFilm_MainView.class.getName()).log(Level.SEVERE, null, ex);
}
jFileChooser_Dest.rescanCurrentDirectory();
}
NetBeans Java mise à jour d'un TextArea
J'ai fait un petit programme en Java avec NetBeans pour créer un GUI
pour les usagers. Dans l'interface j'ai placé un TextArea pour donner
le statut des étapes que le programme faisait. En modifiant dans le
contenu du TextArea dans le code, je me suis rendu compte que celui-ci
ne se mettait pas à jour jusqu'à temps que le code de l'event d'un
Bouton n'était pas complété. Étant un petit programme, je ne voulais
pas trop passer de temps à coder celui-ci, donc j'ai pu régler la
situation de cette façon:
jTextArea_Statut.append("Copie des fichiers terminée.\n");
jTextArea_Statut.update(jTextArea_Statut.getGraphics());
jTextArea_Statut.append("Conversion des fichiers en cours.\n");
jTextArea_Statut.update(jTextArea_Statut.getGraphics());
jTextArea_Statut.append("Copie des fichiers terminée.\n");
jTextArea_Statut.update(jTextArea_Statut.getGraphics());
jTextArea_Statut.append("Conversion des fichiers en cours.\n");
jTextArea_Statut.update(jTextArea_Statut.getGraphics());
Ogre3D tutoriel pour mouvement personnage
http://codefreax.org/tutorials/view/id/3
S'abonner à :
Messages (Atom)