mirror of
https://github.com/raysan5/raylib.git
synced 2026-10-11 04:01:54 -04:00
Compare commits
4 Commits
a043255aa7
...
9056ea3299
| Author | SHA1 | Date | |
|---|---|---|---|
| 9056ea3299 | |||
| 806d68a9bc | |||
| 3825bbf2d4 | |||
| c8b19b297b |
@ -131,7 +131,7 @@ int main(void)
|
|||||||
DrawText("Left/right to change wave type", 10, 30, 20, DARKGRAY);
|
DrawText("Left/right to change wave type", 10, 30, 20, DARKGRAY);
|
||||||
|
|
||||||
// Draw the last 10 ms of uploaded audio
|
// Draw the last 10 ms of uploaded audio
|
||||||
for (int i = 0; i < screenWidth; i++)
|
for (int i = 0; i < screenWidth - 1; i++)
|
||||||
{
|
{
|
||||||
Vector2 startPos = {(float)i, 250 - 50*buffer[SAMPLE_RATE - SAMPLE_RATE/100 + i*SAMPLE_RATE/100/screenWidth] };
|
Vector2 startPos = {(float)i, 250 - 50*buffer[SAMPLE_RATE - SAMPLE_RATE/100 + i*SAMPLE_RATE/100/screenWidth] };
|
||||||
Vector2 endPos = { (float)(i + 1), 250 - 50*buffer[SAMPLE_RATE - SAMPLE_RATE/100 + (i + 1)*SAMPLE_RATE/100/screenWidth] };
|
Vector2 endPos = { (float)(i + 1), 250 - 50*buffer[SAMPLE_RATE - SAMPLE_RATE/100 + (i + 1)*SAMPLE_RATE/100/screenWidth] };
|
||||||
|
|||||||
@ -50,7 +50,7 @@ int main(void)
|
|||||||
// NOTE: The gesture log uses an array (as an inverted circular queue) to store the performed gestures
|
// NOTE: The gesture log uses an array (as an inverted circular queue) to store the performed gestures
|
||||||
char gestureLog[GESTURE_LOG_SIZE][12] = { "" };
|
char gestureLog[GESTURE_LOG_SIZE][12] = { "" };
|
||||||
// NOTE: The index for the inverted circular queue (moving from last to first direction, then looping around)
|
// NOTE: The index for the inverted circular queue (moving from last to first direction, then looping around)
|
||||||
int gestureLogIndex = GESTURE_LOG_SIZE;
|
int gestureLogIndex = 0;
|
||||||
int previousGesture = 0;
|
int previousGesture = 0;
|
||||||
|
|
||||||
// Log mode values:
|
// Log mode values:
|
||||||
|
|||||||
@ -988,7 +988,7 @@ Sound LoadSoundAlias(Sound source)
|
|||||||
{
|
{
|
||||||
Sound sound = { 0 };
|
Sound sound = { 0 };
|
||||||
|
|
||||||
if (source.stream.buffer->data != NULL)
|
if ((source.stream.buffer != NULL) && (source.stream.buffer->data != NULL))
|
||||||
{
|
{
|
||||||
AudioBuffer *audioBuffer = LoadAudioBuffer(AUDIO_DEVICE_FORMAT, AUDIO_DEVICE_CHANNELS, AUDIO.System.device.sampleRate, 0, AUDIO_BUFFER_USAGE_STATIC);
|
AudioBuffer *audioBuffer = LoadAudioBuffer(AUDIO_DEVICE_FORMAT, AUDIO_DEVICE_CHANNELS, AUDIO.System.device.sampleRate, 0, AUDIO_BUFFER_USAGE_STATIC);
|
||||||
|
|
||||||
|
|||||||
@ -4174,31 +4174,45 @@ RayCollision GetRayCollisionSphere(Ray ray, Vector3 center, float radius)
|
|||||||
|
|
||||||
Vector3 raySpherePos = Vector3Subtract(center, ray.position);
|
Vector3 raySpherePos = Vector3Subtract(center, ray.position);
|
||||||
float vector = Vector3DotProduct(raySpherePos, ray.direction);
|
float vector = Vector3DotProduct(raySpherePos, ray.direction);
|
||||||
float distance = Vector3Length(raySpherePos);
|
float distanceToCenter = Vector3Length(raySpherePos);
|
||||||
float d = radius*radius - (distance*distance - vector*vector);
|
float d = radius*radius - (distanceToCenter*distanceToCenter - vector*vector);
|
||||||
|
|
||||||
collision.hit = d >= 0.0f;
|
// Check if the ray's line intersects with the sphere
|
||||||
|
if (d >= 0.0f)
|
||||||
// Check if ray origin is inside the sphere to calculate the correct collision point
|
|
||||||
if (distance < radius)
|
|
||||||
{
|
{
|
||||||
collision.distance = vector + sqrtf(d);
|
Vector3 point = { 0 };
|
||||||
|
Vector3 normal = { 0 };
|
||||||
|
float hitDistance = 0.0f;
|
||||||
|
|
||||||
// Calculate collision point
|
// Check if ray origin is inside the sphere to calculate the correct collision point
|
||||||
collision.point = Vector3Add(ray.position, Vector3Scale(ray.direction, collision.distance));
|
if (distanceToCenter < radius)
|
||||||
|
{
|
||||||
|
hitDistance = vector + sqrtf(d);
|
||||||
|
|
||||||
// Calculate collision normal (pointing outwards)
|
// Calculate collision point
|
||||||
collision.normal = Vector3Negate(Vector3Normalize(Vector3Subtract(collision.point, center)));
|
point = Vector3Add(ray.position, Vector3Scale(ray.direction, hitDistance));
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
collision.distance = vector - sqrtf(d);
|
|
||||||
|
|
||||||
// Calculate collision point
|
// Calculate collision normal (pointing outwards)
|
||||||
collision.point = Vector3Add(ray.position, Vector3Scale(ray.direction, collision.distance));
|
normal = Vector3Negate(Vector3Normalize(Vector3Subtract(point, center)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hitDistance = vector - sqrtf(d);
|
||||||
|
|
||||||
// Calculate collision normal (pointing inwards)
|
// Calculate collision point
|
||||||
collision.normal = Vector3Normalize(Vector3Subtract(collision.point, center));
|
point = Vector3Add(ray.position, Vector3Scale(ray.direction, hitDistance));
|
||||||
|
|
||||||
|
// Calculate collision normal (pointing inwards)
|
||||||
|
normal = Vector3Normalize(Vector3Subtract(point, center));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hitDistance >= 0.0f)
|
||||||
|
{
|
||||||
|
collision.hit = true;
|
||||||
|
collision.point = point;
|
||||||
|
collision.normal = normal;
|
||||||
|
collision.distance = hitDistance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return collision;
|
return collision;
|
||||||
|
|||||||
Reference in New Issue
Block a user